use of org.commonmark.renderer.html.AttributeProvider in project zserio by ndsev.
the class DocMarkdownToHtmlConverter method convert.
static String convert(DocResourceManager docResourceManager, AstLocation location, String markdown) {
final List<Extension> extensions = Arrays.asList(AutolinkExtension.create(), HeadingAnchorExtension.create(), TablesExtension.create());
final Parser parser = Parser.builder().extensions(extensions).build();
final Node document = parser.parse(markdown);
final HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).nodeRendererFactory(new HtmlNodeRendererFactory() {
@Override
public NodeRenderer create(HtmlNodeRendererContext context) {
return new ResourcesRenderer(context, docResourceManager, location);
}
}).attributeProviderFactory(new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext arg0) {
return new AnchorAttributeProvider();
}
}).attributeProviderFactory(new AttributeProviderFactory() {
@Override
public AttributeProvider create(AttributeProviderContext arg0) {
return new ImageAttributeProvider();
}
}).build();
final String html = renderer.render(document);
// strip white-spaces around generated HTML added by renderer
return html.trim();
}
Aggregations