Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate HTML identifier from section title #996

Open
toindev opened this issue Aug 20, 2018 · 10 comments
Open

Generate HTML identifier from section title #996

toindev opened this issue Aug 20, 2018 · 10 comments

Comments

@toindev
Copy link

toindev commented Aug 20, 2018

Expected behaviour

I can link to a specific section in a exported HTML document using an identifier generated from its title.

eg. <h4 id="my-section">My section</h4> in generated html, in order to be able to use my_note.html#my-section to access "My section"

Actual behaviour

The identifier for sections exist, but are numerically incremented, and do not reflect the title of the section.

example: <h4 id="toc_6">My section</h4>

Possible implementation

This is how it's done in the insert-toc script, in order to work well with GitHub flavored Markdown:

    function extractLink(title) {
        var lowercase = title.toLowerCase()
        var spaceReplaced = lowercase.replace(/ /g, "-")
        var invalidCharsRemoved = spaceReplaced.replace(/[^A-Za-zÀ-ÿ-_]/g, "")
        return invalidCharsRemoved;
    }
@pbek
Copy link
Owner

pbek commented Aug 20, 2018

You can change the generated html with http://docs.qownnotes.org/en/develop/scripting/README.html#notetomarkdownhtmlhook. To set anchors as you like...
Does this answer your question?

@toindev
Copy link
Author

toindev commented Aug 20, 2018

It could, but it would not be very practical, since I would have to run regexp after regexp. I think it could be better suited for a patch to the HTML generator. Could you direct me to the code, unless it is from an
external library ?

@pbek
Copy link
Owner

pbek commented Aug 21, 2018

It's a 3rd party library: https://github.com/pbek/QOwnNotes/tree/develop/src/libraries/hoedown
But you can also play with markdown-it (see: the script repository).

@toindev
Copy link
Author

toindev commented Aug 21, 2018

Ha, nice! markdown-it even has a plugin for header anchors already. I'll have a look at integrating it and close this issue, thank you.

@pbek
Copy link
Owner

pbek commented Aug 21, 2018

great!

@pbek pbek added Help wanted Type: Feature adds functionality and removed Type: Support labels Aug 26, 2018
@thomascwells
Copy link

@toindev - Did you figure out how to use this for TOC-style links within a given note? I tried using markdown-it, but still didn't get quite what I was looking for.

@thomascwells
Copy link

Oh, I see now (#1567) that the markdown engine(?) has been changed to https://github.com/mity/md4c .

Maybe this issue is now moot.

@pbek
Copy link
Owner

pbek commented Jun 28, 2022

Maybe this issue is now moot.

So can you link to sections? 🤔

@thomascwells
Copy link

I actually couldn't quite figure out how to link to sections directly. I was expecting something like this to work:

# My Title

[Skip to conclusion](#conclusion)
[Skip to footnotes](#footnotes)

## Section 1

## Conclusion

### Footnotes

But I could only get it to work with the link formatted something like:
[Skip to conclusion](my_file_name.md#conclusion)

I thought switching to MD4C would fix it, but alas, I couldn't make it work. I tired with the markdown-it script as well.

For now, I'm going to use VSCodium, so this isn't a pressing issue for me. (I'm often coding, so I will usually have VSCode open already anyway, and at least on my system (Fedora) the RAM footprint was about the same).

But I'm happy to continue engaging/working on this Issue if there's anything I can do. I appreciate all the work you've put into QOwnNotes and love to see tools like this continue to be successful - especially ones that integrate so well into the self-hosted ecosystem!

@pbek
Copy link
Owner

pbek commented Jun 29, 2022

[Skip to conclusion](my_file_name.md#conclusion)

yes, this is the way 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants