I know wiki links can be converted to DT markdown inks (in Tools->Item Links). Is it possible to convert wiki links to relative html links? For example:
[[Big Document]] becomes [Big Document](Big%20Document.md)
I have searched the forums but can’t find an easy way to do this. The name may have more than one word - Another%20Big%20Document.md
I have some indexed markdown files that are used in another app so don’t want to link back to something in DT but in the folder used by the app.
A script can do that. And there might be other ways, too.
(() => {
const app = Application("DEVONthink");
const records = app.selectedRecords();
records.forEach(r => {
r.plainText = r.plainText().replaceAll(/\[\[(.*)\]\]/g,(match, link) => {
const escapedLink = link.replaceAll(' ', '%20');
return `[${link}](${escapedLink}.md)`;
});
})
})()
That’s javascript, and it changes the currently selected records without checking if they are Markdown.
The cool thing (in my mind) is that it uses a “replacer” function in the outer replaceAll call. This function escapes spaces in the Wikilink before returning the relative HTML link.
Thanks. I will give this a try. 
It worked fine. Thanks.
I made my own small adjustments using regex 101 as I had a few documents with [[A]], [[B]] in them which got a bit muddled.
Yeah, sorry about that. When I cobbled the Regexes together, I didn’t think about more than one link in a paragraph. The outer Regex is greedy and shouldn’t be. Instead of .*, I should have used .*?.
1 Like
That is shorter than my solution! I have also learnt a little bit more about regex and stopping it being greedy. Thanks.
Just for completeness sake: The non-greedy quantors were introduced quite late in the game. Before them, you’d have to do something like
\[\[[^\]]*\]\]
which probably made too many people dizzy. Basically
- two opening brackets
- followed by anything but a closing bracket, any number of times
- followed by two closing brackets
Not too hard to write, but nauseating to read. So, Larry Wall added the non-greedy ? to Perl’s RegExes. If I remember correctly.
1 Like