0

I'm using Gulp + Gulpsmith + Metalsmith to create my website.

metalsmith_markdown is rendering my HTML as follows:

# This is an H1 to <h1 id="this-is-an-h1">This is an H1</h1>. Why is it rendering that 'id' tag?

Why might that be?

Here's the part that deals with the markdown rendering in my Gulpfile.js

.use(markdown({
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: true,
    smartLists: true,
    smartypants: true
}))
Preview
  • 35,317
  • 10
  • 92
  • 112
Martin Velchevski
  • 874
  • 11
  • 33
  • 1
    that's so that you can refer to the element, is it a problem? – Mike H-R Oct 16 '14 at 19:04
  • I absolutely don't want that ID there. I have dealt with all typographic elements in SCSS so I wouldn't have to target it specifically. Also imagine if markdown renders the contents of each tag as their ID... My HTML would look terrible. :/ – Martin Velchevski Oct 16 '14 at 19:09
  • hahaha, I'm pretty sure it's not the content of each tag, just major headings (it also means you can link to them with something like `link` or `[link](#this-is-an-h1)` in markdown). – Mike H-R Oct 16 '14 at 19:28
  • Dude! :D That's causing some serious OCD-induced panic attacks already... So that's normal behavior then? No way to 'flag' it off? – Martin Velchevski Oct 16 '14 at 19:29
  • 1
    it's certainly a common feature of many markdown processors. (E.g. pandoc does the same thing for all headings.) – Stephen Thomas Oct 16 '14 at 19:32
  • I still dont see the huge problem with the id's. – Beterraba Oct 16 '14 at 21:11
  • The problem is that inserting IDs on each heading without having the need for it seems pointless for me. It pollutes my HTML and on longer titles it feels even worse. It's non-semantic it serves no purpose (in my case at least). I want my rendered html to be as lightweight and clean as possible. – Martin Velchevski Oct 16 '14 at 21:18

1 Answers1

1

That's the behavior of metalsmith-markdown which uses marked as Markdown parser since the PR#181.

You can override some features of marked as stated in their Readme and in #420, but since all is handled by the metalsmith plugin, you can't really.

I would advice to create a PR in marked to add a custom option to deactivate completely the behavior near this

Preview
  • 35,317
  • 10
  • 92
  • 112
  • I forced a really 'caveman' solution by tweaking a few lines in `makred.js` within the metalsmith_markdown/node_modules/marked/lib folder, by commenting out some lines and tweaking the formatting of the rendered tag a little bit -> http://i.imgur.com/FVXDdNo.png It's now behaving the way I want it to but I really think there should be an option to remove that extraneous markup. – Martin Velchevski Oct 16 '14 at 19:44
  • Yep you can also do that, but that may be complicated if you want to update this dependency or re-install your project, you will have to re-made the change – Preview Oct 16 '14 at 19:45
  • You're absolutely right... I actually feel uneasy doing this. I might try and see if some of the markdown renderers for Gulp would do the trick. – Martin Velchevski Oct 16 '14 at 19:48