vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.21k stars 260 forks source link

Feature/create d2 diagrams extension #589

Open Anakin100100 opened 10 months ago

Anakin100100 commented 10 months ago

Work in progress

Anakin100100 commented 10 months ago

@vsch I'm working on adding the support for d2 diagrams and am able to parse the ast correctly (D2Node should be 0 to 23, I'm going to fix it later)

Document[0, 23]
  D2Block[0, 23]
    D2Node[20, 23]

and this should render <p>rendering d2 node</p> but the render method of the D2NodeRenderer is not called even though the D2Node rendering is associated with the render method of the renderer.

public class D2NodeRenderer implements NodeRenderer {
    public D2NodeRenderer(DataHolder options) {

    }

    @Override
    public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() {
        HashSet<NodeRenderingHandler<?>> set = new HashSet<>();
        set.add(new NodeRenderingHandler<>(D2Node.class, this::render));
        return set;
    }

    private void render(D2Node node, NodeRendererContext context, HtmlWriter html) {
        html.tag("p");
        html.text("rendering d2 node");
        html.tag("/p");
    }

    public static class Factory implements NodeRendererFactory {
        @NotNull
        @Override
        public NodeRenderer apply(@NotNull DataHolder options) {
            return new D2NodeRenderer(options);
        }
    }
}

I'm a bit at a loss here because the method is not called and I don't see any relevant differences between the examples and other extensions and this one. Do you see what could be a cause of this issue?