Skip to content
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

Why "id" attribute is being generated on heading elements? #54

Closed
smohadjer opened this issue Feb 15, 2015 · 16 comments
Closed

Why "id" attribute is being generated on heading elements? #54

smohadjer opened this issue Feb 15, 2015 · 16 comments

Comments

@smohadjer
Copy link

I see that this line of markdown:

This is a test of GFM for javascript

once converted to HTML becomes this:

<h1 id="this-is-a-test-of-gfm-for-javascript">This is a test of GFM for javascript</h1>

Which option is responsible for auto-generating id in heading elements and how can this be turned off?

@treasonx
Copy link
Owner

@treasonx
Copy link
Owner

I did a little more digging. I was always under the assumption this was standard markdown behavior. Grunt markdown uses https://github.com/chjj/marked It might be part of the GFM option. You can pass options to marked using the markdownOptions of in your grunt file

@smohadjer
Copy link
Author

I don't see any option for disabling auto generation of id attributes on headings, do you?

@treasonx
Copy link
Owner

No I don't you might not be able to disabled it.

https://github.com/chjj/marked/blob/master/lib/marked.js#L788

Thats where they are adding the ID. I don't seen any obvious way of disabling that behavior.

@smohadjer
Copy link
Author

I don't think this is part of standard markdown. John Gruber's markdown samples and his Dingus app do not generate such id on headings when converting markdown to html, nor does Github.

http://daringfireball.net/projects/markdown/dingus

@treasonx
Copy link
Owner

Yea not sure where this came from. Marked is doing it and since i am using marked there is little I can do about it.

Looks like there is some discussion on this thread markedjs/marked#515

@smohadjer
Copy link
Author

Others have also complained about this:
markedjs/marked#420

Marked's development seems to be stalled with 180 open issues.

@smohadjer
Copy link
Author

Have you looked into this? https://github.com/evilstreak/markdown-js

@treasonx
Copy link
Owner

Does it support GFM? GFM is really important for a lot of the common uses of grunt markdown.

@smohadjer
Copy link
Author

Not yet, but he is working on it. You can voice your support for it here:
evilstreak/markdown-js#41

@treasonx
Copy link
Owner

If you really want to remove the ids you could do it in postCompile. I think thats all I can do for right now since marked doesn't expose a setting.

@smohadjer
Copy link
Author

I think I can live with it. Thanks for your help.

@dnutels
Copy link

dnutels commented Feb 18, 2015

Wouldn't you be able to override marked's Renderer and override it's heading handler?

@treasonx
Copy link
Owner

@dnutels yes I could but right now I don't extend marked at all. If I start to extend marked the plugin will become coupled to marked. I like to keep the coupling loose so if I find a better markdown parser I should be able to swap it easily.

@dnutels
Copy link

dnutels commented Feb 19, 2015

  1. at some point one has to give up :) and admit that marked is the de-facto standard
  2. you can abstract that setting - since any "better" markdown plugin should have the ability to alter the way headings are generated (otherwise you'd be trading down, IMO):
{
    ...
    markdown: {
        heading: function() {...}
    }
}

@sulhome
Copy link

sulhome commented Nov 29, 2015

it looks like id is being added to headings only. Use a renderer to override this as follow:

var marked = require('marked');
var renderer = new marked.Renderer();
renderer.heading = function (text, level) { 
  return `<h${level}>${text}</h${level}>`;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants