jsepia / markdown-it-wikilinks

Renders Wikimedia-style wiki links in markdown-it. This is useful for making Markdown-based wikis.
MIT License
37 stars 23 forks source link

Add a class to invalid wikilinks #10

Open xplosionmind opened 2 years ago

xplosionmind commented 2 years ago

In order to style on a particular way [[wikilinks]] that do not have a matching page, it should be possible to add a class, so that they are rendered like <span class='invalid-wikilink'>[[Non-matching wikilink]]</span>

Ferk commented 1 year ago

It would be great if there was another optional post-processing transform that was called after the link is being produced.. so we can modify the link accordingly to add a different class/style or maybe change other properties from it (what if I want non-matching wiki-links to point to a different page?)

EDIT: Actually... after checking the code, I see that postProcessPageName already is straight up modifying the page URL.

Then the one thing I'm missing is a postProcessHtmlAttrs so I can modify the htmlAttrs variable before it gets serialized into the link. It would be fine for me to take care of detecting if the link is valid or not from my side (which is something that might be hard to really know depending on the setup), provided that at least the pageName is also included as a parameter of the postProcessHtmlAttrs method.