Skip to content

Commit 52744da

Browse files
committed
feat: add /docs/header-ids.md
1 parent 599cb4c commit 52744da

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/header-ids.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Custom header IDs for markdown documents
2+
3+
Html ID attributes are used to create links to specific sections of a document. In markdown, **custom header IDs** should be assigned to all header lines (lines that begin with one-or-more hash marks, `#`).
4+
5+
## Markdown syntax
6+
7+
A custom heading ID should follow these rules:
8+
9+
- Placed at the end of a heading line, preceded by a space, followed by a line break
10+
- Wrapped in curly braces
11+
- Starts with a hash-mark
12+
- Uses kebab-case string
13+
- Unique for the current page
14+
15+
For example:
16+
17+
```markdown
18+
## My heading {#my-heading}
19+
20+
### A subheading {#a-subheading}
21+
22+
#### Or a longer title that can be shortened {#long-heading}
23+
```
24+
25+
Note that for short headers, simply lowercasing and using hyphens instead of spaces is sufficient. For longer headers, a shortened concise version of the header is encouraged. Must not repeat the same ID on the same page.
26+
27+
## How are these used?
28+
29+
When these headers are rendered, they come with a link icon attached to it that can be used to quickly link to that section of the document.
30+
31+
Extending the above example, if we wanted to link to the `A subheading` section of the above document (for example living at path `/docs`), you could use the link`/docs#a-subheading` to link directly to that section.
32+
33+
See a live example on ethereum.org: [https://ethereum.org/en/developers/docs/blocks/#block-anatomy](https://ethereum.org/en/developers/docs/blocks/#block-anatomy)
34+
35+
## When to use custom header IDs
36+
37+
### English content
38+
39+
These should be created for header on every new English markdown document.
40+
41+
### Translated content
42+
43+
English files are uploaded to Crowdin for translation. Header ID's should be _inherited_ from the English version, and remain unchanged during translation.
44+
45+
This is to ensure that the translated content can be linked to from other documents and external links, without breaking the path. This is similar to why path and filenames are not translated, but remain in English to simplify linking and referencing.
46+
47+
See a live example on ethereum.org: [https://ethereum.org/es/developers/docs/blocks/#block-anatomy](https://ethereum.org/en/developers/docs/blocks/#block-anatomy)
48+
49+
Notice the header ID is still in English (`#block-anatomy`), but links to the Spanish (`/es/`) version of the site, at the correct section.
50+
51+
## When are these not needed?
52+
53+
Markdown files in the repo `/docs` (such as this one) do not require custom header IDs, as they are not yet displayed on the website, and do not have translated versions.

0 commit comments

Comments
 (0)