-
Notifications
You must be signed in to change notification settings - Fork 19
Add support for anchors on headings #26
Comments
No need for an extra |
Looking into this, a few questions come to mind: How do we want to sanitize the title so the identifier is both user-friendly and still valid according to the html spec? Do we want to keep sanitized characters at the start/end of the identifier? Do we want to keep repeating dashed in the identifier? Identifiers have to be unique, so how would we want to handle 2 same labeled H2s in different H1s?
Are we targeting HTML 4 or HTML4.1+? |
Good questions ;) Also, github.com adds a |
@kptdobe, @rofe: so GitHub only uses the This also is an opinionated way on how to handle anchors that I'm not sure I would like to impose on our customers. And I think this is also in line with @rofe's earlier comment. I can look into generating the same identifiers that GitHub would do, but I would just leave these as
=> We would propose the first by default, and the project team can decide what to do with it. |
Good idea to do it like GitHub. They actually use some powerful advanced regex in python that properly supports all unicode blocks for foreign languages[0], but we don't have an easy JS equivalent at the moment. I see 2 possible approaches here:
I'm preparing a gist with as many examples as I can think of as test cases in [3]. |
Adapting existing tests to use the new heading ids fix #26
why do you want to keep the unicode letters in the anchor name? also see https://mathiasbynens.be/notes/es6-unicode-regex i think that |
The issue was about making it work like the github anchors, so if that is the actual requirement, I don't see how to achieve that result without a regex that fully supports all accented letters, but more importantly all foreign scripts as well. You can check the gist linked above for some examples.
I tried that, as well as various combinations of ES2018 is supposed to get proper unicode support in regex according to https://github.com/tc39/proposal-regexp-unicode-property-escapes, but until then it seems we are quite limited. |
i think keeping the non ascii characters is overrated :-) |
I had an ascii-only version earlier on (1st commit actually)… I'm ok with any approach, really. Now if we stick to the HTML5 spec, we should probably support unicode identifiers at some point, especially when we start supporting proper localization. Can't really have Chinese markdowns with Chinese headings and expect to transliterate to ascii identifiers I guess. |
i agree. you still need to ensure that the anchors are unique. |
The algorithm should ensure they are, even have unit tests for it. |
Sorry to interrupt, but why not just use lodash's kebabCase? https://lodash.com/docs/4.17.11#kebabCase EDIT: It does have proper unicode support… |
@koraa That is an excellent suggestion, didn't think about it. I tried playing with it on the gist I referenced and it actually performs really well for our needs. Here is a comparative table of the various approaches.
While lodash's |
Leverage lodash's kebabCase instead of XRegExp dependecy fix #26
I also notice that the |
I would be interested in meeting the person that uses such a heading, so I say we leave it in case anyone wants to report that bug ;) |
@koraa True… I initially thought I could provide a few examples from a mathematician's or physicist's point of view that would write some mathematical formula as heading title (E=mc², ∇² = φ, etc.) but even these actually work with kebabcase (all greek and maths symbols are supported)… so the only edge case I can think of that remains is just a gibberish sequence of special characters which you probably don't need to target anyway with an anchor. |
Remove package-lock.json modifications fix #26
…r instead Replacing the lodash kebabcase and custom id collision escpaing with the github slugger module that achieves boths fix #26
Refactor the getTextContent method in the heading handler to a static method of the class fix #26
Adjust the generate id algorithm so it matches what GitHub uses and extract it to separate file for easier testing fix #26
Adapting existing tests to use the new heading ids fix #26
Adapting existing tests to use the new heading ids fix #26
Leverage lodash's kebabCase instead of XRegExp dependecy fix #26
Remove package-lock.json modifications fix #26
…r instead Replacing the lodash kebabcase and custom id collision escpaing with the github slugger module that achieves boths fix #26
Refactor the getTextContent method in the heading handler to a static method of the class fix #26
# [1.5.0](v1.4.0...v1.5.0) (2019-04-16) ### Features * **html pipe:** add support for anchors on headings ([f52f768](f52f768)), closes [#26](#26)
🎉 This issue has been resolved in version 1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes the ID attributes so that the new output from pipeline-1.5 works see adobe/helix-pipeline#26
Properly support complex headers that include child elements (strong, em, code, etc.) when automatically generating the heading identifiers fix #26
# [1.5.0](v1.4.0...v1.5.0) (2019-04-16) ### Features * **html pipe:** add support for anchors on headings ([f52f768](f52f768)), closes [#26](#26)
Properly support complex headers that include child elements (strong, em, code, etc.) when automatically generating the heading identifiers fix #26
🎉 This issue has been resolved in version 1.5.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [2.2.0](v2.1.1...v2.2.0) (2019-05-29) ### Bug Fixes * **html pipe:** Fix merge conflict ([6abb218](6abb218)), closes [#253](#253) * **html pipe:** Sanitize generated markdown to avoid XSS attacks ([e2d7963](e2d7963)), closes [#253](#253) * **html pipe:** Sanitize generated markdown to avoid XSS attacks ([8c55d0d](8c55d0d)), closes [#253](#253) ### Features * **html pipe:** add support for anchors on headings ([65430d4](65430d4)), closes [#26](#26) * **html pipe:** Allow custom elements and attributes in markdown ([247a6b9](247a6b9)), closes [#253](#253)
🎉 This issue has been resolved in version 2.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Anchors are nicely managed on github.com: when rendering the markdown, github adds an anchor before each heading and shows an icon that gives the link to have a direct access to the corresponding heading.
While working on our Helix documentation, I realised this would be a really useful feature, especially to handle the navigation: you can have a long md file but create a nav that give direct access to a "section" of content below in the page. Without the anchors, I had to split the long md file into various small md files to give direct access.
The pipeline could automatically generate an anchor (
<a>
tag with an id) for each "section" and "heading". Showing or not an icon would be delegated to the project and could be done with CSS.This issue was moved by trieloff from adobe/project-helix#154.
The text was updated successfully, but these errors were encountered: