question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should <h4> tags get direct linkified?

See original GitHub issue

I see that the heading-highlight implementation stops after <h3>. I remember when this utility was implemented but I can’t immediately think of a reason why we didn’t choose to highlight past <h3>.

I bring this up because sometimes when including links in a blog post (or sharing them), we might be referencing the same page in a single paragraph or even in the same sentence. So if I’m providing a link to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#field_declarations for example and then want to show the private field declarations the only direct link I have is ..#field_declarations which doesn’t take me directly to the desired subheading. This isn’t a problem, but more a question. I can foresee it looking a bit wonky with so many links, but I want to be able to replace this (which uses the same subheading direct link as the <h4> tags are linkified):

I am writing about Field declarations in JavaScript and also Private field declarations but want the private field declarations to directly link to that subheading within field declarations.

with this (where the private field declarations link will directly link to that subheading /Classes#private_field_declarations rather than having to scroll down a bit from field declarations and providing two of the same subheading links with /Classes#field_declarations:

I am writing about Field declarations in JavaScript and also Private field declarations and both links are unique linking to the specified subheading.

As a developer its pretty easy to open devtools and grab the id and replace the last component of the URL with the desired ID (to create your own direct link) but this isn’t always ideal.

What do you think about <h4> tags getting direct linkified? @peterbe

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
peterbecommented, Jul 30, 2021

What do you think about <h4> tags getting direct linkified?

It certainly would be nice! I’ve many times found that there’s a specific portion of the page I’d like to link to but the nearest h2/h3 is so far away/up that the anchor link doesn’t make much sense. I’d have to say “Go to the link Examples section and scroll down down to the section about polyfills”.

But we’d have to be a bit careful. Perhaps h4s aren’t as neatly used. It might be on the Tier 1 docs (i.e. popular en-US JS and CSS docs) but not on the long tail. Perhaps worth a shot and see how it feels and behaves. But we would need to browser a lot of samples to make sure it works OK.

For example, you can’t have HTML within a h2 or h3 because the whole heading becomes a link. So if you had:

<h4 id="google-example">Google <a href="google.com/example">example</a></h4>

it will become:

<h4 id="google-example"><a href="#google-example">Google <a href="google.com/example">example</a></a></h4>

Also, I don’t remember what does Yari do when there’s a <h3> that doesn’t have an ID? I think the kumascript rendering automatically generates on making <h3>Foo bar</h3> into <h3 id="foo-bar">Foo bar</h3>, first. But that’d need to be applied to all h4 too.

0reactions
ghostcommented, Sep 5, 2021

I see that the heading-highlight implementation stops after <h3>. I remember when this utility was implemented but I can’t immediately think of a reason why we didn’t choose to highlight past <h3>.

I bring this up because sometimes when including links in a blog post (or sharing them), we might be referencing the same page in a single paragraph or even in the same sentence. So if I’m providing a link to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#field_declarations for example and then want to show the private field declarations the only direct link I have is ..#field_declarations which doesn’t take me directly to the desired subheading. This isn’t a problem, but more a question. I can foresee it looking a bit wonky with so many links, but I want to be able to replace this (which uses the same subheading direct link as the <h4> tags are linkified):

I am writing about Field declarations in JavaScript and also Private field declarations but want the private field declarations to directly link to that subheading within field declarations.

with this (where the private field declarations link will directly link to that subheading /Classes#private_field_declarations rather than having to scroll down a bit from field declarations and providing two of the same subheading links with /Classes#field_declarations:

I am writing about Field declarations in JavaScript and also Private field declarations and both links are unique linking to the specified subheading.

As a developer its pretty easy to open devtools and grab the id and replace the last component of the URL with the desired ID (to create your own direct link) but this isn’t always ideal.

What do you think about <h4> tags getting direct linkified? @peterbe HJFDGTTJ4W3 2 aaw4ghjhjhjuwe432333336y978t44896+9a9+7+9a9a79a79a746464a-*-*a946a

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Explains How to Use Headings for SEO
Clearly, heading tags can indicate hierarchical levels of information, that several H3 headers are sub-topics of the previous H2.
Read more >
Header Tags: A Simple (But Complete) Guide To H1, H2 and ...
In this new guide, you'll learn exactly how to use H1 to H6 heading tags to optimize your page and drive higher search...
Read more >
HTML Heading Tags Best Practices - Medium
As the above quote from John Mueller states, HTML heading can affect your page rankings, both directly and indirectly. Direct: Google uses Headings...
Read more >
SEOptimer's Guide to Header Tags
Although header tags don't have a direct impact on SEO, abusing these tags will have a negative impact on search rankings. Search engines...
Read more >
How To Properly Optimize Headings to Improve SEO
If you can optimize your page's H1-H4 headers, readers will love your ... When writing content for your website, heading tags create a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found