本文整理匯總了Java中org.commonmark.renderer.html.AttributeProviderContext類的典型用法代碼示例。如果您正苦於以下問題:Java AttributeProviderContext類的具體用法?Java AttributeProviderContext怎麽用?Java AttributeProviderContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AttributeProviderContext類屬於org.commonmark.renderer.html包,在下文中一共展示了AttributeProviderContext類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extend
import org.commonmark.renderer.html.AttributeProviderContext; //導入依賴的package包/類
@Override
public void extend(HtmlRenderer.Builder rendererBuilder) {
rendererBuilder.attributeProviderFactory(new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext context) {
return HeadingIdAttributeProvider.create(defaultId, idPrefix, idSuffix);
}
});
}
示例2: attributeProviderIsApplied
import org.commonmark.renderer.html.AttributeProviderContext; //導入依賴的package包/類
@Test
public void attributeProviderIsApplied() {
AttributeProviderFactory factory = new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext context) {
return new AttributeProvider() {
@Override
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
if (node instanceof TableBlock) {
attributes.put("test", "block");
} else if (node instanceof TableHead) {
attributes.put("test", "head");
} else if (node instanceof TableBody) {
attributes.put("test", "body");
} else if (node instanceof TableRow) {
attributes.put("test", "row");
} else if (node instanceof TableCell) {
attributes.put("test", "cell");
}
}
};
}
};
HtmlRenderer renderer = HtmlRenderer.builder()
.attributeProviderFactory(factory)
.extensions(EXTENSIONS)
.build();
String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2"));
assertThat(rendered, is("<table test=\"block\">\n" +
"<thead test=\"head\">\n" +
"<tr test=\"row\"><th test=\"cell\">Abc</th><th test=\"cell\">Def</th></tr>\n" +
"</thead>\n" +
"<tbody test=\"body\">\n" +
"<tr test=\"row\"><td test=\"cell\">1</td><td test=\"cell\">2</td></tr>\n" +
"</tbody>\n" +
"</table>\n"));
}
示例3: process
import org.commonmark.renderer.html.AttributeProviderContext; //導入依賴的package包/類
public MarkdownProcessorResult process(String markdownContent, List<Visitor> visitors) {
List<Extension> extensions = Arrays.asList(TablesExtension.create(), YamlFrontMatterExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdownContent);
YamlFrontMatterVisitor yamlVisitor = new YamlFrontMatterVisitor();
document.accept(yamlVisitor);
Set<String> linkTargets = new HashSet<>();
// Modify listing headings
for (Visitor visitor : visitors) {
document.accept(visitor); // new NavigationLinkInjector(siblingPages, subCategories));
}
// Fix links to *.md to go to *.html instead
document.accept(new AbstractVisitor() {
@Override
public void visit(Link link) {
URI uri = URI.create(link.getDestination());
linkTargets.add(link.getDestination());
link.setDestination(MarkdownUtils.renameFilenameForMarkdownPage(link.getDestination()));
visitChildren(link);
}
});
MarkdownTocGenerator tocGenerator = new MarkdownTocGenerator();
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).attributeProviderFactory(new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext context) {
return tocGenerator;
}
}).build();
String renderedContent = renderer.render(document);
MarkdownProcessorResult result = new MarkdownProcessorResult(renderedContent, tocGenerator.getToc(), yamlVisitor.getData());
result.getLinkTargets().addAll(linkTargets);
return result;
}
示例4: create
import org.commonmark.renderer.html.AttributeProviderContext; //導入依賴的package包/類
@Override
public AttributeProvider create(AttributeProviderContext context) {
return this;
}