Closed S-W-Williams closed 6 years ago
You must generate ids from the third argument passed to the heading
generator, which contains the textual (unescaped) content of the heading, like this:
renderer.heading = function(heading, level, raw) {
return '<h' + level + ' id='
+ raw.toLowerCase().replace(/(\s|,)+/g, '-').replace(/("|'|`|’)/g, "").replace(/\(|\)/g, "") + '>'
+ heading + '</h' + level + '>';
};
marked("# Dijkstra's Shortest Path Algorithm", {renderer: renderer})
This prints
<h1 id=dijkstras-shortest-path-algorithm>Dijkstra's Shortest Path Algorithm</h1>
@joshbruce we can close this
@Feder1co5oave: You're giving folks a lot of great information. Starting to wonder if updating docs would be of value to consumers of Marked. Closing.
I'm currently trying to make the parsed heading ids match GitHub's markdown anchor conversion rules.
My regular expressions work when tested, but the moment I include it in the render apostrophes stop working.
By apostrophe I mean unicode character 39, not 8217.
For example the string "Dijkstra's Shortest Path Algorithm" becomes "dijkstra's-shortest-path-algorithm" in the parsed html, but running
properly returns "dijkstras-shortest-path-algorithm".
Am I doing something wrong here? Is this intended or a bug?