21
21
class DefIdNode (nodes .Element ):
22
22
def __init__ (self , kind , text ):
23
23
text , id = parse_target_from_text (text )
24
- super ().__init__ (def_kind = kind , def_text = text , def_id = id_from_text (id ))
24
+ super ().__init__ (def_kind = kind , def_text = text , def_id = id_from_text (kind , id ))
25
25
26
26
def astext (self ):
27
27
return self ["def_text" ]
@@ -35,7 +35,7 @@ def __init__(self, kind, source_doc, text):
35
35
ref_kind = kind ,
36
36
ref_source_doc = source_doc ,
37
37
ref_text = text ,
38
- ref_target = id_from_text (target ),
38
+ ref_target = id_from_text (kind , target ),
39
39
)
40
40
41
41
def astext (self ):
@@ -211,8 +211,17 @@ def get_object_types():
211
211
return result
212
212
213
213
214
- def id_from_text (text ):
215
- return "" .join (c if c .isalnum () else "_" for c in text .lower ())
214
+ def id_from_text (kind , text ):
215
+ # We lowercase the text so that capitalization does not matter for
216
+ # references and definitions, which is sometimes the case for when they are
217
+ # used as the start of a sentence.
218
+ # Notably though, this breaks for paragraph ids which are unique randomized
219
+ # strings where capitalization matters for hyperlinking, so we don't do so
220
+ # for those
221
+ return "" .join (
222
+ c if c .isalnum () else "_"
223
+ for c in (text if kind == "paragraph" else text .lower ())
224
+ )
216
225
217
226
218
227
def setup (app ):
0 commit comments