Closed
Description
This may well be an edge case, but I’m making an issue anyway.
In my markdown, I sometimes want to customize the output a tad by adding HTML, such as adding an icon in front of a heading; # <span class="font-icon font-icon-logo"></span>Heading text
.
This works just fine, but the anchor generation is too stupid in this case, as it will generate the following output; <h1 id="span-class-font-icon-font-icon-logo-span-heading-text">Heading text</h1>
. Hardly what I want and certainly not what I expect.
I made a renderer to get around the problem, but would prefer if Marked was smart enough to handle it all by itself. And without jQuery as a dependency, obviously.
renderer.heading = function(text, level)
{
var stripped = $('<div />').html(text).text();
var escaped = stripped.toLowerCase().replace(/[^\w]+/g, '-');
return '<h' + level + ' id="' + escaped + '">' + text + '</h' + level + '>';
};