Search in sources :

Example 1 with AttributeProvider

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();
}
Also used : Node(org.commonmark.node.Node) HtmlNodeRendererFactory(org.commonmark.renderer.html.HtmlNodeRendererFactory) Parser(org.commonmark.parser.Parser) HeadingAnchorExtension(org.commonmark.ext.heading.anchor.HeadingAnchorExtension) Extension(org.commonmark.Extension) AutolinkExtension(org.commonmark.ext.autolink.AutolinkExtension) TablesExtension(org.commonmark.ext.gfm.tables.TablesExtension) AttributeProviderFactory(org.commonmark.renderer.html.AttributeProviderFactory) AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) HtmlNodeRendererContext(org.commonmark.renderer.html.HtmlNodeRendererContext) AttributeProvider(org.commonmark.renderer.html.AttributeProvider)

Aggregations

Extension (org.commonmark.Extension)1 AutolinkExtension (org.commonmark.ext.autolink.AutolinkExtension)1 TablesExtension (org.commonmark.ext.gfm.tables.TablesExtension)1 HeadingAnchorExtension (org.commonmark.ext.heading.anchor.HeadingAnchorExtension)1 Node (org.commonmark.node.Node)1 Parser (org.commonmark.parser.Parser)1 AttributeProvider (org.commonmark.renderer.html.AttributeProvider)1 AttributeProviderContext (org.commonmark.renderer.html.AttributeProviderContext)1 AttributeProviderFactory (org.commonmark.renderer.html.AttributeProviderFactory)1 HtmlNodeRendererContext (org.commonmark.renderer.html.HtmlNodeRendererContext)1 HtmlNodeRendererFactory (org.commonmark.renderer.html.HtmlNodeRendererFactory)1 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)1