dullage / flatnotes

A self-hosted, database-less note taking web app that utilises a flat folder of markdown files for storage.
MIT License
1.5k stars 87 forks source link

Bug: Link to headings not working #202

Closed pbogre closed 4 months ago

pbogre commented 4 months ago

Headings still have their id attribute applied correctly via the customHTMLRenderer from baseOptions.js, however linking to these headings is not as simple after the recent update introducing support for running flatnotes in a subpath.

Before, I was able to link to a heading in the same document with this code:

[Link to Heading](#heading-name)

However after the update this redirects me to http://example.com:8080/#heading-name, instead of the old funtional http://example.com:8080/note/ExampleNote/#heading-name. If I used instead something like:

[Link to Heading](/note/ExampleNote#heading-name)

Then it would work correctly, but it's quite ugly and requires a lot of repetition. I also tried using WikiLinks like so:

[[ExampleNote#heading-name]]

But this redirects me to http://example.com:8080/note/ExampleNote%23heading-name.

A fix could be to change the behavior of links when they start with a # character, so for instance [Link to Heading](#heading-name) always prepends the note's path to the redirecting URL. Otherwise it could be convenient to stop converting characters into URL-compatible characters when using WikiLinks, like in the example above where # becomes %23. This could be seen as an extension of WikiLinks, allowing you to not only link to another note but also a specific section of that note.

I'm not sure how these changes would fare with an application running on a subpath.

dullage commented 4 months ago

Ah. I made sure to cover all relative paths in the application but hadn't considered that there might be relative paths in the content!

I'll take a look to see if I can intercept the rendering of hyperlinks and use Vue Router to set the href value to an absolute path (which would take path prefixes into account).

dullage commented 4 months ago

@pbogre - The develop branch now has a resolution for this. [Link to Heading](#heading-name) should now resolve as expected. I've pushed a build to Docker Hub, so please give the :develop tag a go if you can.

pbogre commented 4 months ago

Thanks for looking into this! I'll check out the develop branch as soon as I can.

pbogre commented 4 months ago

Just tested it, can confirm it's working! Thanks again.