Skip to content

Commit 14d5df1

Browse files
authored
docs: Generate permanent links to numbered headings (#1083)
make_id from docutils removes leading digits from IDs, which makes it impossible to have permanent links to numbered headings. We prefix IDs which start with a digit with "id-" before passing it to make_id to make permanent links work.
1 parent e09bb92 commit 14d5df1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/src/conf.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525
import re
2626

2727

28+
# make_id from docutils removes leading digits from IDs, which makes it impossible to have permanent links to numbered
29+
# headings. We prefix IDs which start with a digit with "id-" before passing it to make_id to make permanent links work.
30+
#
31+
# See https://docutils.sourceforge.io/docs/ref/rst/directives.html#identifier-normalization
32+
def setup(app):
33+
import docutils.nodes
34+
make_id_orig = docutils.nodes.make_id
35+
36+
def make_id(string):
37+
prefixed_string = "id-" + string if string and string[0].isdigit() else string
38+
return make_id_orig(prefixed_string)
39+
40+
docutils.nodes.make_id = make_id
41+
42+
2843
# -- Project information -----------------------------------------------------
2944

3045
project = "Splice"

0 commit comments

Comments
 (0)