本文整理汇总了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;
}