-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Inconsistent anchor-id linkage #664
Comments
Auto-generated header IDs is a much discussed topic for marked, so any change to the current default behavior is going to upset some people. renderer = new marked.Renderer;
renderer.heading = function(text, level, raw) {
return '<h'
+ level
+ ' id="'
+ this.options.headerPrefix
+ raw.replace(/[^\w]+/g, '-')
+ '">'
+ text
+ '</h'
+ level
+ '>\n';
};
html = marked(src, { renderer: renderer }); |
Thank you. Your code snippet is helpful. However, the problem is not as much about the the exact IDs generated, as it is about consistency between the ID and the internal a href anchors When the document authors specify explicit header IDs, they inevitably use them in the anchor tags (for example, to generate TOC). So, creating custom renderers with custom IDs as you have suggested will break the document. For example, consider this line I sampled from one of the document TOCs:
Unless the header The solution is not to customize the header generation, but to use explicit IDs (if supplied by the author) as is, without customizing them further. If the author supplied explicit IDs, there must be a good reason why he did so. For all that we know, the author might even share that link somewhere outside externally and we should be able to resolve it correctly. Using our own transformations on the headers, will break such documents. |
You speak about explicit IDs for headers, but
|
While trying to render markdown docs from github getting inconsistent anchor / link combinations (due to the header ids being forced to lowercase ). For an example, below is one such doc:
The generated header ids are all forced lower case, while the generated
a href
links are retained "as-is".Forcing the lowercase only for header ids, while leaving the
<a href
"as-is" is causing un-navigatable docs to be rendered.The text was updated successfully, but these errors were encountered: