# Feature request: automatically generated ids for headers

**URL:** <https://talk.commonmark.org/t/feature-request-automatically-generated-ids-for-headers/115>\
**Category:** Uncategorized\
**Created:** [September 3, 2014, 9:49pm UTC](https://talk.commonmark.org/t/feature-request-automatically-generated-ids-for-headers/115 "2014-09-03T21:49:39Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![jericson](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/jericson/32/36_2.png) [@jericson](https://talk.commonmark.org/u/jericson)\
**Post date:** [September 4, 2014, 5:59pm UTC](https://talk.commonmark.org/t/feature-request-automatically-generated-ids-for-headers/115/17 "2014-09-04T17:59:36Z")

</div>

I suggest adopting [Wikipedia’s section anchor scheme](http://en.wikipedia.org/wiki/Help:Section#Section_linking), which takes the text of the header and converts it to a valid [id](http://en.wikipedia.org/wiki/Fragment_identifier):

1. spaces =\> `_`
2. [certain punctuation](http://en.wikipedia.org/wiki/Template:Anchor#Limitations) is converted to [character entity references](http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references)
3. second and following duplicate headers are appended with `_2` to `_n` suffixes (N.B.: the first instance is unchanged.)
4. header depth is ignored

This would allow authors to refer to headers without imposing any extra syntax:

```
# A good place to start

...

Please begin at [the beginning](#A_good_place_to_start).

```

Downsides:

- The requirement for unique ids (point #3) means that the converter will need to keep track of duplicate header names. Further, if there are multiple Markdown documents on a single page, the page will need to be validated to be sure that no documents duplicate the same ids. These are concerns with _any_ system that allows URL fragments in Markdown, however. (This leads me to believe that link anchors should be an extension and not part of the core standard.)

- Edits to the header text will break links (both internal and external). This could be solved by adding manual anchors and creating redirects (which is what Wikipedia does). If authors are able to specific anchors manually, they could future-proof their own documents at the cost of giving up the convenience of automation. (Again, this seems more appropriate for an extension that _also_ adds manual anchors.)

On the plus side:

- Authors can predict what ids will be generated. And perhaps more importantly, so can their authoring tools. (Though, again, #3 complicates matters.)

- Editors can reorganize a document without breaking it _as long as they don’t change the text of the header_. (Oh, they _also_ need to be careful not to rearrange the order of duplicate headers. _Sigh_.)

- People familiar with Wikipedia section links will feel at home.

- There is a pleasing parallelism between the syntax of [ATX headers](http://jgm.github.io/stmd/spec.html#atx-headers) and the links to them.

---

_[View the full topic](https://talk.commonmark.org/t/feature-request-automatically-generated-ids-for-headers/115)._
