Skip to content

Anchor generation and headers with HTML #685

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

Closed
Haraldson opened this issue Nov 17, 2015 · 1 comment
Closed

Anchor generation and headers with HTML #685

Haraldson opened this issue Nov 17, 2015 · 1 comment
Labels
L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue proposal

Comments

@Haraldson
Copy link

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 + '>';
};
@joshbruce joshbruce added L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue proposal labels Dec 23, 2017
@joshbruce
Copy link
Member

#981

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue proposal
Projects
None yet
Development

No branches or pull requests

2 participants