@@ -65,23 +65,14 @@ def footnote_def(state: StateBlock, startLine: int, endLine: int, silent: bool):
65
65
return True
66
66
pos += 1
67
67
68
- if "footnotes" not in state .env :
69
- state .env ["footnotes" ] = {}
70
- if "refs" not in state .env ["footnotes" ]:
71
- # TODO here (as is expected) previously defined footnotes are ignored
72
- # we should though add a record of these (plus line numbers) to the env
73
- # so that renderers may report warnings for these ignored footnotes
74
- # rather than 'failing silently'
75
- state .env ["footnotes" ]["refs" ] = {}
76
68
label = state .src [start + 2 : pos - 2 ]
77
- state .env [ "footnotes" ][ "refs" ] [":" + label ] = - 1
69
+ state .env . setdefault ( "footnotes" , {}). setdefault ( "refs" , {}) [":" + label ] = - 1
78
70
79
- token = Token ("footnote_reference_open" , "" , 1 )
80
- # TODO add record of line numbers to footnote definitions
81
- token .meta = {"label" : label }
82
- token .level = state .level
71
+ open_token = Token ("footnote_reference_open" , "" , 1 )
72
+ open_token .meta = {"label" : label }
73
+ open_token .level = state .level
83
74
state .level += 1
84
- state .tokens .append (token )
75
+ state .tokens .append (open_token )
85
76
86
77
oldBMark = state .bMarks [startLine ]
87
78
oldTShift = state .tShift [startLine ]
@@ -127,6 +118,8 @@ def footnote_def(state: StateBlock, startLine: int, endLine: int, silent: bool):
127
118
state .sCount [startLine ] = oldSCount
128
119
state .bMarks [startLine ] = oldBMark
129
120
121
+ open_token .map = [startLine , state .line ]
122
+
130
123
token = Token ("footnote_reference_close" , "" , - 1 )
131
124
state .level -= 1
132
125
token .level = state .level
@@ -159,11 +152,8 @@ def footnote_inline(state: StateInline, silent: bool):
159
152
# so all that's left to do is to call tokenizer.
160
153
#
161
154
if not silent :
162
- if "footnotes" not in state .env :
163
- state .env ["footnotes" ] = {}
164
- if "list" not in state .env ["footnotes" ]:
165
- state .env ["footnotes" ]["list" ] = {}
166
- footnoteId = len (state .env ["footnotes" ]["list" ])
155
+ refs = state .env .setdefault ("footnotes" , {}).setdefault ("list" , {})
156
+ footnoteId = len (refs )
167
157
168
158
tokens = []
169
159
state .md .inline .parse (
@@ -173,10 +163,7 @@ def footnote_inline(state: StateInline, silent: bool):
173
163
token = state .push ("footnote_ref" , "" , 0 )
174
164
token .meta = {"id" : footnoteId }
175
165
176
- state .env ["footnotes" ]["list" ][footnoteId ] = {
177
- "content" : state .src [labelStart :labelEnd ],
178
- "tokens" : tokens ,
179
- }
166
+ refs [footnoteId ] = {"content" : state .src [labelStart :labelEnd ], "tokens" : tokens }
180
167
181
168
state .pos = labelEnd + 1
182
169
state .posMax = maximum
0 commit comments