Make wiki-links work in VSCode's Markdown preview
Thank you for the excellent extension! I like Markdown Notes so much that I recommended it to my colleagues, but I also want to see this improved a bit.
Summary
This PR addresses #6 and makes wiki-links work in Markdown preview.
What's changed
- Supply href with paths relative to the workspace root
- Set data-href as well as href for A-tags
The first change was necessary because
- VSCode's Uri.path starts with "/" and represents a full path in the file system, but
- href starting with "/" is interpreted as a path relative to the document root, which in this case is the workspace root.
Therefore, to get the desired behavior, we need to fill href with a path relative to the document or the workspace folder.
Regarding the second change, it seems necessary for links in the preview window to work as expected.
Implementation details
Regarding the second change, I chose to copy, paste and modify the code from markdown-it-wikilinks, which is a markdown-it plugin that renders wiki-links. A cleaner approach would be to use a version of markdown-it-wikilinks that sets the data-href attribute (e.g. @shdwcat/markdown-it-wikilinks, see also https://github.com/thomaskoppelaar/markdown-it-wikilinks/pull/1). I made this choice because I just wanted to have it work as quickly as possible without worrying about any side effects caused by changing dependent packages.
Limitations
A rendered wiki-link would be incorrect if "vscodeMarkdownNotes.workspaceFilenameConvention": "relativePaths" or the wiki-link itself is a relative path.
Also, is it possible to add tests for any of this stuff?
How much more work would it be to take the "cleaner approach" re "cleaner approach would be to use a version of markdown-it-wikilinks that sets the data-href attribute" ?
Also, is it possible to add tests for any of this stuff?
I'd be happy to, but because I am not familiar with testing a markdown-it plugin, it will take some time before it's done.
How much more work would it be to take the "cleaner approach"
Probably the hardest part is to make sure that the version of markdown-it-wikilinks like @shdwcat/markdown-it-wikilinks does not break any of the current features. Once that's done, then adopting it is as easy as rolling back all the changes in this PR and switching from @thomaskoppelaar/markdown-it-wikilinks to e.g. @shdwcat/markdown-it-wikilinks.
The current PR, instead, makes a minimal change to the code in @thomaskoppelaar/markdown-it-wikilinks to avoid side effects.
I see. OK, well, I leave it to you to decide which approach to take, but either way it would be good to add tests to this. And maybe put a few screenshots / a screencast in the PR to demonstrate what this looks like / how it works. Thanks.