Add flag to suppress id=xxxx in generated H1..6 tags

Hi, Hugo’s terrific, thanks to everybody who has participated in building it. There’s one thing I would like to do but haven’t found an option for: remove TOC tags if I decide to not use them. I was thinking that an option such as --disableRSS could be nice, does that sound like a good idea to you? It’s a detail, really, but Hugo is good at removing the bloat (I’m currently converting a WP site to it) that I find it a pity to see those extra tags in my code when I don’t need them.

Maxime

I’m not following. If you don’t include {{ .TableOfContents }} in your template, Hugo won’t generate the TOC. Are you referring to something different?

Yes, to the id="toc_0" tags generated in my header tags, actually.

Which layout are you using? And is this in the generated HTML or XML?

This comes in the HTML tags. I use layouts/_default/single.html and this happens on two separate Hugo websites.

Can you post the snippet that generates the tags? I’m not seeing that toc_0 in my HTML, so I must be doing something differently than you.

  • layouts/_default/single.html: {{ .Content }}
  • content/post.md: ## test title
  • HTML: <h2 id="toc_0">test title</h2>

Ok. You must be using version 0.12. With v0.13, the id is very different, that’s what confused me.

Content:

# test
## test
### test
## test
# test
## test

HTML:

<h1 id="test:4108045d631e1ffc0a8f9e461e342847">test</h1>

<h2 id="test-1:4108045d631e1ffc0a8f9e461e342847">test</h2>

<h3 id="test-2:4108045d631e1ffc0a8f9e461e342847">test</h3>

<h2 id="test-3:4108045d631e1ffc0a8f9e461e342847">test</h2>

<h1 id="test-4:4108045d631e1ffc0a8f9e461e342847">test</h1>

<h2 id="test-5:4108045d631e1ffc0a8f9e461e342847">test</h2>

Yes, I am using the latest stable. But what is your opinion on adding an option to remove those extra tags when unneeded? I feel like this feature wouldn’t be worth the trouble of writing it but perhaps somebody has a different opinion and would like to see this as well.

The id gets added to any heading in the content, so it’s not related to the .TableOfContents variable. That’s what the reference to TOC brought to mind. So, it could use a name that’s closer to the functionality.

I agree that it adds a little clutter to the HTML (especially with that new fingerprint), but I hadn’t even noticed it until after you pointed it out (even then, it took a couple of tries to actually see it). If it generated a different id each time I ran Hugo, then it would cause unnecessary (and unwanted) changes that would have to be pushed up. But if it’s the same, it doesn’t matter either way to me, especially since I’m not running any JQuery to manipulate the DOM based on id.

Sorry for the confusion, I thought of --disableTOC because of the way Hugo 0.12 names those ids (toc_0).

In 0.13 you can use plainIdAnchors

See

https://github.com/spf13/hugo/blob/master/docs/content/overview/configuration.md

1 Like

On a somewhat related note, I am not the biggest fan of IDs for header tags beiong generated with a hash, like this:

I would much rather have a predictable one like this,
for the purposes of easily creating links from elsewhere in the same page,
and also for comsemtiuc reasons:

<h1 id=“test”>test</h1>

I understand that the reason that hashes are added is to ensure that each one has a unique ID. However, I am wil;ling to manually ensure that all headings on a page are unique myself.

Is there currenlty an option to disable adding hashes?

Thanks

In v0.13, you can add a flag for BlackFriday (the Markdown engine) to your config.toml file:

[blackfriday]
  plainIdAnchors = true

Before:

<h1 id="h1:f066022a5cd7e2eba28340b66795b149">h1</h1>
<h2 id="h2:f066022a5cd7e2eba28340b66795b149">h2</h2>
<h3 id="h3:f066022a5cd7e2eba28340b66795b149">h3</h3>

After:

<h1 id="h1">h1</h1>
<h2 id="h2">h2</h2>
<h3 id="h3">h3</h3>
1 Like

Ah, thanks for that, I was not aware of this option! Pity that we need 0.13 for this though. I’m collaborating with others who jsut use the hugo binary, so they are stuckl with 0.12 for now.

See: http://discuss.gohugo.io/t/release-cycle/727/3?u=bguiz

@bgulz The v0.13 binaries are up on the web site - https://github.com/spf13/hugo/releases.

If anyone is struggling with this post v0.15 it’s because they have become case sensitive and now you need to use: plainIDAnchors

This is an odd feature to have by default. I can understand that for blog post headings you would want IDs, but for everything it’s quite strange.

It makes the generated HTML constantly change by default which messes with SVN history. If you use the plain option it means that all headings get default IDs that might clash with other things on the page. That seems error-prone to me.

Can it be configured to only apply to certain headings. For instance h1/h2. Then at least you can use lower level ones to avoid it.

1 Like

In 0.16 it is default off.

I use version 0.19. I have very long header texts. And each such text is rendered as Id. That is nonsensical.

the plainIDAnchors setting does not change this and by its description does not say that it would change this behavior.