flexmark-java
flexmark-java copied to clipboard
WikiLinkNodeFormatter duplicates pageRef for links w/o text but with anchor
When formatting a WikiLink or WikiImage the link is modified:
[[my Page#anchor]]
turns into
[[my Pagemy Page#anchor]]
WikiLinks with explicit text or without anchor are fine.
To Reproduce
- [x]
Parser - [ ]
HtmlRenderer - [x]
Formatter - [ ]
FlexmarkHtmlParser - [ ]
DocxRenderer - [ ]
PdfConverterExtension - [x]
ext-wikilink
String md = "[[my Page#anchor]]";
Parser.Builder parser = new Parser.Builder();
Parser.addExtensions(parser, WikiLinkExtension.create())
.set(WikiLinkExtension.ALLOW_ANCHORS, true);
Document doc = parser.build().parse(md);
String newmd = new Formatter.Builder(parser).build().render(doc);
Assert.assertEquals(md, newmd);
References:
-
WikiNodeuses thepageRefas the node's text during parsing -
WikiLinkNodeFormatteronly checks for missing text for simple formatting -
but it also falls back to the
pageRefif no text is present -
and for
WikiLinkNodeRendererthere is the same fallback but as comment
Either point 1+4 or 2 need to change. I would prefer a null text, when there is in fact no explicit text input (thus removing point 1 from WikiNode).