MCPcopy Index your code
hub / github.com/Python-Markdown/markdown / remove_fnrefs

Function remove_fnrefs

markdown/extensions/toc.py:151–171  ·  view source on GitHub ↗

Remove footnote references from a copy of the element, if any are present.

(root: etree.Element)

Source from the content-addressed store, hash-verified

149
150
151def remove_fnrefs(root: etree.Element) -> etree.Element:
152 """ Remove footnote references from a copy of the element, if any are present. """
153 # Remove footnote references, which look like this: `<sup id="fnref:1">...</sup>`.
154 # If there are no `sup` elements, then nothing to do.
155 if next(root.iter('sup'), None) is None:
156 return root
157 root = deepcopy(root)
158 # Find parent elements that contain `sup` elements.
159 for parent in root.findall('.//sup/..'):
160 carry_text = ""
161 for child in reversed(parent): # Reversed for the ability to mutate during iteration.
162 # Remove matching footnote references but carry any `tail` text to preceding elements.
163 if child.tag == 'sup' and child.get('id', '').startswith('fnref'):
164 carry_text = f'{child.tail or ""}{carry_text}'
165 parent.remove(child)
166 elif carry_text:
167 child.tail = f'{child.tail or ""}{carry_text}'
168 carry_text = ""
169 if carry_text:
170 parent.text = f'{parent.text or ""}{carry_text}'
171 return root
172
173
174def nest_toc_tokens(toc_list):

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…