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.

Headings are missing anchors / ids

See original GitHub issue
# h1

parse =>

<h1>h1</h1>

not

<h1 id="h1">h1</h1>

image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

56reactions
Ratstail91commented, Dec 11, 2018

This should be a core feature. I shouldn’t have to go out of my way to implement something that is a core markdown feature.

39reactions
rexxarscommented, Mar 28, 2017

It’s hard to know how to address these headers, so I’ve decided to leave it out of the core. You can achieve the same functionality by using a Header renderer:

function flatten(text, child) {
  return typeof child === 'string'
    ? text + child
    : React.Children.toArray(child.props.children).reduce(flatten, text)
}

function HeadingRenderer(props) {
  var children = React.Children.toArray(props.children)
  var text = children.reduce(flatten, '')
  var slug = text.toLowerCase().replace(/\W/g, '-')
  return React.createElement('h' + props.level, {id: slug}, props.children)
}

<Markdown
  source="# Some heading!\n\nAnd a paragraph"
  renderers={{Heading: HeadingRenderer}}
/>

JSbin example here

Read more comments on GitHub >

github_iconTop Results From Across the Web

On Adding IDs to Headings - CSS-Tricks
It's technique is that it adds the ID on the anchor link itself, which is also totally fine. I guess that's another way...
Read more >
Headers don't have IDs? - Talkyard
Hi. It doesn't look like the markdown headers like the below have default IDs assigned to them, meaning I cannot create a contents...
Read more >
Punctuation is included in Markdown Heading Anchors ...
It refer to the doc point : Anchor IDs are assigned to all headings when rendered as HTML. The ID is the heading...
Read more >
Anchors not working with Sticker header - WordPress.org
I just set up an HTML Anchor on my page with a link. I also have set on the Customize / Twentig Options...
Read more >
Maintaining the heading anchor IDs across languages - HUGO
The format of auto-generated anchor IDs for headings with Unicode characters varies across static generators or their internal options/libraries ...
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 Hashnode Post

No results found