markdig icon indicating copy to clipboard operation
markdig copied to clipboard

WikiLinks support?

Open alex-netkachov opened this issue 1 year ago • 13 comments

Hi! I'm looking for the WikiLinks support (links within two square brackets, e.g. https://python-markdown.github.io/extensions/wikilinks/). Does this library support it, via plugin maybe?

If it is not supported, I do not mind to implement it. Could you maybe guide me a bit on what would be the right approach?

Kind regards, Alex

alex-netkachov avatar Jun 08 '23 02:06 alex-netkachov

Hi! I'm looking for the WikiLinks support (links within two square brackets, e.g. https://python-markdown.github.io/extensions/wikilinks/). Does this library support it, via plugin maybe?

Not that I'm aware of.

If it is not supported, I do not mind to implement it. Could you maybe guide me a bit on what would be the right approach?

I would start with an existing similar parser like the LinkInlineParser but Wikilinks should be simpler in the end (no image support, no special link rules as in regular links).

xoofx avatar Jul 08 '23 16:07 xoofx

This feature would be great for parsing Obsidian notes. No pressure, just wondering, any development or plans?

nightroman avatar Sep 13 '23 03:09 nightroman

As the topic starter, I feel that I need to inform you that I will not proceed with it further because I no longer use wikilinks. The name clashes in the large knowledge base have become too much of a nuisance.

alex-netkachov avatar Sep 14 '23 00:09 alex-netkachov

I would also love this feature... very useful for Dendron workspaces.

@alex-netkachov FYI, Dendron solves the namespacing issue using hierarchical dot notation, e.g. [[languages.c-sharp]] is distinct from [[tags.c-sharp]]

djradon avatar Oct 09 '23 17:10 djradon

Describe the basic specification for this.

Take a phrase in your document, e.g. cheese on toast

You add double square brackets around it, e.g. [[cheese on toast]]

It becomes an in the rendered document, with the href set to cheese_on_toast ?

What are the rules to slugify the phrases? How do you deal with punctuation?

Just trying to flesh it out. I'm using markdig for a wiki right now, but I'm forcing the users just to make full links because I've not got it smart enough to do it wiki-style yet.

QINGCHARLES avatar Oct 17 '23 21:10 QINGCHARLES

Hi @QINGCHARLES. I believe spaces in links are not supported, so it would look like [[cheese-on-toast]] which would set the href to "cheese-on-toast.md".

FWIW, I use the "VS Slug" plugin, which in turn uses https://github.com/sindresorhus/slugify - but I would say slugification shouldn't be necessary for this use case... Just expect the phrase to correspond directly to a filename without the ".md" extension.

djradon avatar Oct 18 '23 13:10 djradon

@djradon That's a format I've not seen before for "Wiki" style links. The original wikis used a strange CamelCaseFormat like that to create links, which clearly isn't very readable for normal humans. The link at the top of this thread, which I finally remembered to check out, uses basically the same format as WikiMedia, which is close to ideal as it allows spaces and punctuation in links and then does its best to slugify them in a way where they end up looking often identical to the original text.

The one I decided on for my wiki allows spaces in the text, but uses a hyphen instead of an underline in the link, and lower-cases everything, just because that's my personal preference for links.

I'm hard-pressed to see the use case for the one in your post -- is there a specific reason you don't want spaces in the link text? Obviously it makes converting it to a filename even easier, but filenames actually are less restricted than URL slugs as they can more easily have spaces in them.

QINGCHARLES avatar Oct 19 '23 15:10 QINGCHARLES

(p.s. I wish there was a way to hack into the InlineLink function to modify its functionality without having to write a whole new one from scratch)

QINGCHARLES avatar Oct 19 '23 15:10 QINGCHARLES

@QINGCHARLES My use case is for Dendron, which only allows dashes in filenames, and the wikilink corresponds directly to the filename (without the .md extension), see https://wiki.dendron.so/notes/90mrtp10ucyyvt60qekuj4y/. But supporting spaces would be fine, doesn't affect my use case.

djradon avatar Oct 22 '23 12:10 djradon

I wrote a simple extension for an Obsidian-based static site generator I'm working on, and thought I'd share it here. It'll probably need tweaking for other use cases, but hopefully someone finds it useful.

Temetra avatar Nov 14 '23 14:11 Temetra

It'll probably need tweaking for other use cases, but hopefully someone finds it useful.

Thanks! Unfortunately, Dendron wikilinks have reversed the page name and the alt text order, so [[UI Components|ui-components]] instead of what I now realize is the standard way of putting the actual page/note title first.

djradon avatar Nov 14 '23 16:11 djradon

Ah, that's a shame. I think the easiest way to fix that would be to swap the assignments in WikilinkParser.cs, lines 97-98.

Temetra avatar Nov 14 '23 16:11 Temetra

Yes, it would be easy to modify your code @Temetra. I checked it out, very nice, thank you. We need more example extensions like this to learn from.

QINGCHARLES avatar Nov 14 '23 18:11 QINGCHARLES