Fixing Obsidian Style Wiki Links

Posted:

My Obsidian style links worked for the most part - with two exceptions.

  1. If there was a "-" in my title, the links were borked.
  2. If I tried to use a link alias, the links were totally wrong because they were not properly converted to lower case.

To fix these two issues, I added a bit of logic in my customPagePathGenerator function to remove any "-" in the path and replace them with a single space.

I discovered markdown-it-wikilinks was not running links with piped aliases through my customPagePathGenerator. But, I learned I could add a custom post processor for the path. So, I added this little bit of logic:

const customPagePathPostProcessor = (path) => {  
    path = path.replace(/-/g,' ').toLowerCase();  
    path = path.replace(/\s\s+/g, ' ');  
    path = path.replace(/[/\s+]/g,'-').toLowerCase();  
    return(path);  
}

It:

  1. Replaces any "-" in the path with a space.
  2. Replaces multiple spaces with a single space. [^1]: otherwise, I would get multiple "-" in the final path.
  3. Convert spaces in the url back to "-" and change it all to lower case.