You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The link and wikilink node values have inconsistent children node shapes when a title is present. For normal links, when there is no title, the node has no children. For wikilinks, when there is no title, the node has one children that contains the link itself. This makes it hard for parsers to distinguish between a wikilink with title and one without.
To reproduce run this code:
use comrak::{nodes::NodeValue, parse_document,Arena,Options};fnmain(){let arena = Arena::new();letmut options = Options::default();
options.extension.wikilinks_title_before_pipe = true;let root = parse_document(&arena,"[](link1)\n[title](link2)\n[[link3]]\n[[title|link4]]",&options,);for node in root.descendants(){let data = node.data.borrow();match data.value{NodeValue::Link(_) | NodeValue::WikiLink(_) => println!("{node:#?}"),
_ => (),};}}
Notice the output below. I would have expected that link1 and link3 should have the same shape (no children), but they don't.
This is a bit of a philosophical matter, since CommonMark specifies that a link without a title should be empty, and therefore it must have no contents. The closest thing we have to a spec for wikilinks, on the other hand, specifies that a wikilink without an explicit title should contain the link as its title.
Whether that happens at the rendering stage or the parsing stage is indeed up to us; I sympathise with wanting to preserve the information.
The link and wikilink node values have inconsistent children node shapes when a title is present. For normal links, when there is no title, the node has no children. For wikilinks, when there is no title, the node has one children that contains the link itself. This makes it hard for parsers to distinguish between a wikilink with title and one without.
To reproduce run this code:
Notice the output below. I would have expected that link1 and link3 should have the same shape (no children), but they don't.
I can probably create a PR to fix this myself, but this will be a breaking change so I would like someone to give it the green light before I do so.
The text was updated successfully, but these errors were encountered: