Skip to content

Commit 5b213fa

Browse files
authored
📚 DOC: Update auto-generated header anchors section (#524)
1 parent e477a75 commit 5b213fa

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Full Changelog: [v0.16.1...v0.17.0](https://github.com/executablebooks/MyST-Pars
88

99
### ‼️ Markdown link resolution improvements
1010

11+
**WARNING: This is a breaking change for links that rely on auto-generated anchor links**. You should now [manually enable auto-generated anchor links](https://myst-parser.readthedocs.io/en/latest/syntax/optional.html?highlight=anchor#auto-generated-header-anchors) if you see errors like `WARNING reference target not found`.
12+
1113
Markdown links are of the format `[text](link)`.
1214
MyST-Parser looks to smartly resolve such links, by identifying if they are:
1315

@@ -30,6 +32,8 @@ See [Markdown Links and Referencing](docs/syntax/syntax.md#markdown-links-and-re
3032

3133
### ‼️ Dollarmath is now disabled by default
3234

35+
**WARNING: This is a breaking change for dollar math**. You should now manually enable dollar math (see below).
36+
3337
The default configuration is now `myst_enable_extensions=()`, instead of `myst_enable_extensions=("dollarmath",)`.
3438
If you are using math enclosed in `$` or `$$` in your documents, you should enable `dollarmath` explicitly.
3539

docs/syntax/optional.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,36 @@ Also see [](syntax/html-admonition).
489489

490490
## Auto-generated header anchors
491491

492-
A common, extended Markdown syntax is to use header bookmark links, locally; `[](#header-anchor)`, or cross-file `[](path/to/file.md#header-anchor)`.
493-
To achieve this, section headings must be assigned anchors, which can be achieved in `myst-parser`,
494-
by setting `myst_heading_anchors = 2` in your `conf.py`.
495-
This configures heading anchors to be assigned to both `h1` and `h2` level headings.
496-
The anchor "slugs" created aim to follow the [GitHub implementation](https://github.com/Flet/github-slugger); lower-case text, removing punctuation, replacing spaces with `-`, uniqueness *via* suffix enumeration `-1`.
497-
To change the slug function, set `myst_heading_slug_func` in your `conf.py` to a function that accepts a string and returns a string.
492+
The MyST Parser can automatically generate label "slugs" for header anchors so that you can reference them from markdown links.
493+
For example, you can use header bookmark links, locally; `[](#header-anchor)`, or cross-file `[](path/to/file.md#header-anchor)`.
494+
To achieve this, use the `myst_heading_anchors = DEPTH` configuration option, where `DEPTH` is the depth of header levels for which you wish to generate links.
495+
496+
For example, the following configuration in `conf.py` tells the `myst_parser` to generate labels for heading anchors for `h1`, `h2`, and `h3` level headings (corresponding to `#`, `##`, and `###` in markdown).
497+
498+
```python
499+
myst_heading_anchors = 3
500+
```
501+
502+
You can then insert markdown links directly to anchors that are generated from your header titles in your documentation.
503+
For example `[](#auto-generated-header-anchors)`: [](#auto-generated-header-anchors).
504+
505+
The paths to other files should be relative to the current file, for example
506+
`[**link text**](./syntax.md#the-myst-syntax-guide)`: [**link text**](./syntax.md#the-myst-syntax-guide).
507+
508+
509+
### Anchor slug structure
510+
511+
The anchor "slugs" created aim to follow the [GitHub implementation](https://github.com/Flet/github-slugger):
512+
513+
- lower-case text
514+
- remove punctuation
515+
- replace spaces with `-`
516+
- enforce uniqueness *via* suffix enumeration `-1`
517+
518+
To change the slug generation function, set `myst_heading_slug_func` in your `conf.py` to a function that accepts a string and returns a string.
519+
520+
### Inspect the links that will be created
521+
498522
You can inspect the links that will be created using the command-line tool:
499523

500524
```console
@@ -508,11 +532,6 @@ $ myst-anchors -l 2 docs/syntax/optional.md
508532
<h2 id="direct-latex-math"></h2>
509533
```
510534

511-
For example `[](#auto-generated-header-anchors)`: [](#auto-generated-header-anchors).
512-
513-
The paths to other files should be relative to the current file, for example
514-
`[**link text**](./syntax.md#the-myst-syntax-guide)`: [**link text**](./syntax.md#the-myst-syntax-guide).
515-
516535
(syntax/definition-lists)=
517536

518537
## Definition Lists

0 commit comments

Comments
 (0)