This recognizes text within double-brackets in my wiki notes and translates it to a link.
It is mostly working like a charm, except for capitalized wiki pages. The links go to the upper case URL. Here’s the live page where I’m testing it out: Berlin
The Go/RE2 RegEx does not support \L, in case you all have used it on RegEx 101.
I tried putting a lower function in my Goldmark render-links.html (i.e., | lower) but that precedes the replaceRe operation, as far as I can tell. I also tried setting disablePathToLower to false with no change in behavior (since that is the default) and then to true. I thought the latter would solve my problems - titlecase links going to titlecase pages - but somehow it has not.
If there’s one thing I might have done wrong, it could be that I need to do better in render-links.html. Continuing to look into it.
Any ideas? (Suggestions for my duct-taped RegEx code also welcome ;)) Worst case scenario, I guess all my note titles will have to be in lower case?
I suggest that you do not use a greedy match here. If you have several links on the same line, your RE will gobble them up all in one big match – which is probably not what you want. Instead, use a lazy match like \S*? or \[\[([^[]+\]\] (probably rather the first one because of legibility).
Also, your pattern \S*\s\S*\s etc. look a bit … like an anti-pattern. Especially since your attempt to replace blanks by dashes will not work with more than five words. I’d suggest a two-step approach:
find all the wiki links ignoring spaces in them with \[\[([^[]+\]\]
for each of them, replace the space(s) with dashes and possibly lower case the characters(not in .Content, just build a second list)
for each of the wiki links, replace it with its cleaned-up <a href=... version from the list you just buit.
That should make for easier to read (and maintain) code, and it will also for for 10 words in a wiki link…
Yes, that’s why I criticised the one line approach. With multiple lines and printf it would be easily doable. Put the regexpes into a slice, range through it and collect what comes out, then range over that and use lower for the first %s and get the second out as is. (print '<a href="%s">%s</a>' ($bla | lower) $bla)
By the way, I am not pretending to fully understand whats going on in those 5 regexpes, but I am pretty sure you can solve that with some form of {1,5} rule to match one to 5 of these groups (a group containing characters that are not whitespace ended by one whitespace or full stop).
Yes, and there’s no reason to set an arbitrary limit of 5 either. It’s something like \S+(?:\s+\S+)*. One has to make sure that the RE is not too greedy, too. So probably using a negated character class like [^[] would be better than \S
First of all, thank you so much everyone!!! Learning so much from this thread.
(Yes, I suppose I could add a few line breaks in there @davidsneighbour XD)
I used your suggestion @pamubay and I’m thrilled! Works like a charm. So grateful for your help. Hopefully this thread will be useful for others looking to hop on the wikilink (e.g., Obsidian, Roam, Logseq, etc.) train, because I could not find much about it when perusing the internet.