-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Header anchors [needs discussion] #28
Comments
add default perfix to make id unique? like
Use can set perfixId to empty string, got |
It's the most possible solution. Don't know how many expected things it will break. Also adds a second question - should we try to autofix links with anchors only (add prefix) or not. |
What an about an option for the prefix, which is on by default? So if anyone doesn't want their anchors autofixed, they can turn it off? |
I create a locally implementation for zeke/marky-markdown/pull/6 |
Yes. According to http://www.slideshare.net/x00mario/in-the-dom-no-one-will-hear-you-scream id/name without prefix will add unlimited vectors for attacs. No prefix by default would be mad, even with sanitizers. So, we have 2 more questions to answer:
|
How about follow the github way? github use |
If we add such perfix to links too, those will look ugly. I'd prefer something like |
Updated current status in the first post. If you know other people, interested in solution and having practice with this topic - invite them to join. Correct and convenient resolution is important. I don't have enougth usage stat, and don't wish to push all with my opinion. /cc @jonathanong |
@jonathanong old friend... /cc @dead-horse |
Make it a plugin and don't worry about it? Haha I'm okay with a custom prefix though |
IMHO it should be a plugin. And, it needs some options (how it will generate IDs). # First heading
## Nice, second heading
## Another "nested" heading
# Here we go again First variant:
Second is actually slugify with prefix option (default: no prefix):
Third one (I would go with this one by default):
Also, prefix option actually can affect both variants. So I imagine optiosn of a plugin like this: {
style: "slugify", // possible values: "slugify", "numerify"
prefix: "section-" // default: no prefix
} |
I think, that's unnecessary overcomplication. That will add more complexity than whole renderer function override. User can always do it, it (h|sh)e doesn't like default id generation method. |
Though i can add |
Looks like it will be better to add postfix instead of prefix. I think, it's better to rename option to
Possible transformation logic:
|
|
@fengmk2 could you explain? |
this problem can be fixed? |
Only with adding prefix / postfix to value |
http://talk.commonmark.org/t/feature-request-automatically-generated-ids-for-headers/115/39?u=vitaly
Seems we have to care about deduplication. |
Status of this issue is still unclear. No news on CommonMark forum. I tend to do nothing in flavour of 4.+ release, where renderer will allow easy attributes addition. Something like:
Good news is, that next milestone will start very soon. |
IDEA: |
This is how I wound up implementing the feature in one of my projects, but it doesn't support duplicate header contents yet: https://github.com/danielgtaylor/aglio/blob/olio-theme/src/main.coffee#L43-L49 I'd say there is definitely a real need for such a feature. |
@danielgtaylor in v4+ you can push new attr, without full renderer override. See updated doc As i said, i have no objection about this feature. Problem is in final conventions (including deduplication logic) and commonmark spec. Since that's not urgent (because easy to customize), i'd prefer to wait. |
I didn't read the entire thread but my 2 cents are: make something simple with ids. For a quick implementation on a website, I used dashified title + incremented value https://github.com/putaindecode/putaindecode.fr/blob/7c1e08ddf9f9d5d25dd0a877259d718ef57a3f69/scripts/marked.es#L77-L114 Result: http://putaindecode.fr/posts/entreprendre/auto-entrepreneuriat-retour-experiences/ |
@MoOx it's not a big problem to "code something", but if we talk about core feature or plugin in this org, it's important to care about security and all possible use cases. When you do custom solution for your project - you have less requirements, because you know exactly what happens in your environment. Custom modification is not a problem, because markdown-it was specially designed for that. |
There is a plugin for this now, which ads IDs and can add anchors (links) to either side of the heading text: https://github.com/valeriangalliat/markdown-it-anchor |
@danielgtaylor , I wonder, why ids, and not names (as in Also, nitpick: usage should start with |
You have two other plugin choices as well: |
FYI, I just published this plugin https://github.com/MoOx/markdown-it-toc-and-anchor |
This comment was marked as spam.
This comment was marked as spam.
The plugin seems to work fine, should this issue be closed ? |
No. This issue contains imporant security details, not yet resolved in CM spec. It's not about plugins. |
I was able to solve this issue with the above-provided plugin. Thanks. |
It's very popular request to add header ancors. Prior to do it, we need to discuss possible security problems and solutions.
Read first
Problems:
id
- collisionsname
- dom clobberingPossible solutions
Need to discuss better solutions, and what to do by default, because anchors are really needed
current status
options.anchorPrefix
- instance default.env.anchorPrefix
- every-time-render override-
or--
of no objections (short and easy to type)The text was updated successfully, but these errors were encountered: