wooorm / markdown-rs

CommonMark compliant markdown parser in Rust with ASTs and extensions
https://docs.rs/markdown/1.0.0-alpha.18/markdown/
MIT License
836 stars 41 forks source link

Add support for wiki links #62

Closed rambip closed 11 months ago

rambip commented 1 year ago

First, I'm thankfull for this fantastic work ! I'm trying to build a web app to render markdown coming from obsidian or similar software, but there is one feature I'm missing: wikilinks.

It would be nice if I could get [[article_name|click here]] blocks in the abstract syntax tree, because it is quite common now in some tools that use markdown.

One potential challenge is that there is no "right answer" to create an html equivalent to this type of link, it depends on the situation.

Would that make sense to add wiki-style links as an option for the abstract syntax tree if there is no way to compile it ? Maybe creating a html link to ./article would be the best default to convert [[article]] ?

Thank's

wooorm commented 1 year ago

One more challenge: there is no spec. “Wiki links” work different in different spaces. This is pretty important to me:

It is not a goal of this project to support lots of different extensions. It’s instead a goal to support very common and mostly standardized extensions. — https://github.com/wooorm/markdown-rs#extensions

As for precedence on things-in-the-ast-that-don’t-have-html-equivalents, MDX is already supported here, and directives are likely to be added at some point: https://github.com/wooorm/markdown-rs/issues/57.

rambip commented 1 year ago

Well, I think at least internal wikilinks are pretty standard: Either you use [[article_name|url or display]] or just [[article_name]] But I agree, other kinds of links like interwiki are a mess.

But your're right, there is no spec for that kind of syntax, except the wikipedia one that is not markdown-based.

I will need to find a workaround, maybe replacing the wikilinks by real markdown-style links beforhand

ChristianMurphy commented 11 months ago

As a not standardized feature, I don't think this will land in core markdown-rs, closing this as not planned.

That said, if parser plugins become a thing https://github.com/wooorm/markdown-rs/issues/32#issuecomment-1344648061, wikilinks could potentially be added as a community extension/plugin instead of a preprocessing step.

If you have interest in extending markdown-rs feel free to contribute to the plugin support efforts @rambip!