You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
IMHO it should be a plugin. And, it needs some options (how it will generate IDs).
I propose to support 3 variants of IDs generation. Assume we have markdown text:
# First heading## Nice, second heading## Another "nested" heading# Here we go again
First variant: slugify. For the markdown above it will generate IDs like this:
IMHO it should be a plugin. And, it needs some options (how it will generate IDs).
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.
IDEA: idTemplate (prefix) can be defined as user_custom_% or user_custom_%_%%. Then % will be replaced by content, and %% will be replaced by unique doc id (if needed). Such stupid microtemplating will not cost much, and remove restrictions on format.
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.
@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.
@danielgtaylor , I wonder, why ids, and not names (as in <a name="">)? I'm worried that ids could potentially collide with other ids on the page used by javascript.
Also, nitpick: usage should start with const md = require('markdown-it')(), so readme is missing ().
Activity
[-]Header anchors [needs disccussion][/-][+]Header anchors [needs discussion][/+]fengmk2 commentedon Jan 6, 2015
add default perfix to make id unique? like
prefixId="mdit-"# this is h1=>id="mdit-this-is-h1"Use can set perfixId to empty string, got
id="this-is-h1"puzrin commentedon Jan 6, 2015
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.
vyp commentedon Jan 6, 2015
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?
fengmk2 commentedon Jan 6, 2015
I create a locally implementation for zeke/marky-markdown/pull/6
puzrin commentedon Jan 6, 2015
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:
fengmk2 commentedon Jan 6, 2015
How about follow the github way? github use
user-content-perfixpuzrin commentedon Jan 6, 2015
If we add such perfix to links too, those will look ugly. I'd prefer something like
-or--.puzrin commentedon Jan 6, 2015
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
fengmk2 commentedon Jan 6, 2015
@jonathanong old friend...
/cc @dead-horse
jonathanong commentedon Jan 6, 2015
Make it a plugin and don't worry about it? Haha
I'm okay with a custom prefix though
ixti commentedon Jan 6, 2015
IMHO it should be a plugin. And, it needs some options (how it will generate IDs).
I propose to support 3 variants of IDs generation. Assume we have markdown text:
First variant:
slugify. For the markdown above it will generate IDs like this: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:
puzrin commentedon Jan 7, 2015
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.
puzrin commentedon Jan 7, 2015
Though i can add
Renderer.anchorify()for easy override.puzrin commentedon Jan 7, 2015
Looks like it will be better to add postfix instead of prefix. I think, it's better to rename option to
.anchorAdd(more neutral):null- no anchors (idea only, is it needed at all?)-- defaultPossible transformation logic:
/[\s\]\[\!\"\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\_\{\|\}\~\-]/gwith-.anchorAddto tailnameattribute (duplicatednameare allowed). Or still better to use id?5 remaining items
puzrin commentedon Feb 25, 2015
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.
puzrin commentedon Mar 5, 2015
IDEA:
idTemplate(prefix) can be defined asuser_custom_%oruser_custom_%_%%. Then%will be replaced by content, and%%will be replaced by unique doc id (if needed). Such stupid microtemplating will not cost much, and remove restrictions on format.danielgtaylor commentedon Mar 20, 2015
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.
puzrin commentedon Mar 20, 2015
@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.
MoOx commentedon May 29, 2015
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/
You will see a lot of title with the same name & counter right after it. Works great in the case (simple & stupid ^^)
puzrin commentedon May 29, 2015
@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.
danielgtaylor commentedon May 30, 2015
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
rlidwka commentedon May 30, 2015
@danielgtaylor , I wonder, why ids, and not names (as in
<a name="">)? I'm worried that ids could potentially collide with other ids on the page used by javascript.Also, nitpick: usage should start with
const md = require('markdown-it')(), so readme is missing().adam-p commentedon May 31, 2015
You have two other plugin choices as well:
https://github.com/leff/markdown-it-named-headers
https://github.com/adam-p/markdown-it-headinganchor
MoOx commentedon Jun 3, 2015
FYI, I just published this plugin https://github.com/MoOx/markdown-it-toc-and-anchor
ahmad380360 commentedon Apr 4, 2020
GrosSacASac commentedon Nov 20, 2020
The plugin seems to work fine, should this issue be closed ?
puzrin commentedon Nov 20, 2020
No. This issue contains imporant security details, not yet resolved in CM spec. It's not about plugins.
TimDaub commentedon Feb 23, 2021
I was able to solve this issue with the above-provided plugin. Thanks.