Fixed Obsidian Style Wiki Links
My Obsidian style links worked for the most part - with two exceptions.
- If there was a "-" in my title, the links were borked.
- 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:
- Replaces any "-" in the path with a space.
- Replaces multiple spaces with a single space. [^1]: otherwise, I would get multiple "-" in the final path.
- Convert spaces in the url back to "-" and change it all to lower case.