@@ -65,23 +65,14 @@ def footnote_def(state: StateBlock, startLine: int, endLine: int, silent: bool):
6565 return True
6666 pos += 1
6767
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" ] = {}
7668 label = state .src [start + 2 : pos - 2 ]
77- state .env [ "footnotes" ][ "refs" ] [":" + label ] = - 1
69+ state .env . setdefault ( "footnotes" , {}). setdefault ( "refs" , {}) [":" + label ] = - 1
7870
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
8374 state .level += 1
84- state .tokens .append (token )
75+ state .tokens .append (open_token )
8576
8677 oldBMark = state .bMarks [startLine ]
8778 oldTShift = state .tShift [startLine ]
@@ -127,6 +118,8 @@ def footnote_def(state: StateBlock, startLine: int, endLine: int, silent: bool):
127118 state .sCount [startLine ] = oldSCount
128119 state .bMarks [startLine ] = oldBMark
129120
121+ open_token .map = [startLine , state .line ]
122+
130123 token = Token ("footnote_reference_close" , "" , - 1 )
131124 state .level -= 1
132125 token .level = state .level
@@ -159,11 +152,8 @@ def footnote_inline(state: StateInline, silent: bool):
159152 # so all that's left to do is to call tokenizer.
160153 #
161154 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 )
167157
168158 tokens = []
169159 state .md .inline .parse (
@@ -173,10 +163,7 @@ def footnote_inline(state: StateInline, silent: bool):
173163 token = state .push ("footnote_ref" , "" , 0 )
174164 token .meta = {"id" : footnoteId }
175165
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 }
180167
181168 state .pos = labelEnd + 1
182169 state .posMax = maximum
0 commit comments