wincent / masochist

⛓ Website infrastructure for over-engineers
MIT License
78 stars 26 forks source link

Come up with reference link automation #145

Closed wincent closed 4 years ago

wincent commented 4 years ago

I am not super happy with the internal link situation in Markdown, as I was lamenting on Twitter.

Idea: set up an autocmd in Vim to update the reference links in a doc before saving: basically, scan through looking for links that are not already in the footer, and if they are missing, auto-create them. If they are in excess, delete them (or not; not sure how aggressive I want to be).

Basically given a doc:

This is an article about [Git merge conflicts].

On save, it would turn into:

This is an article about [Git merge conflicts].

[Git merge conflicts]: /wiki/Git_merge_conflicts

Gotcha: Reference links are supposedly case-insensitive, but I don't think we can really do anything about that. In Mediawiki the first letter is case-insensitive, so that you can use article liks naturally at the beginning or middle of sentences; eg:

[About this site] has more information.

You can find out more [about this site].

~But in Masochist, link targets are case-sensitive, so you really need to always use the right case; ie. these two links aren't the same resource:~

~Basically that means you'd always have to use the right case, unless you wanted to write things out in longer-hand form:~

Find out more [about this site][About this site].

(Not true all of that; I forgot but I implemented case-insensitivity of the first letter as a special case.)

I could also look at implementing [[Mediawiki style links]], like GitHub wikis do, and which I could achieve with markdown-it and a hack like markdown-it-wikilinks, but I do like the idea of staying as close to "vanilla" Markdown as possible.

wincent commented 4 years ago

Basically done.