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

Method unique_ref

markdown/extensions/footnotes.py:124–143  ·  view source on GitHub ↗

Get a unique reference if there are duplicates.

(self, reference: str, found: bool = False)

Source from the content-addressed store, hash-verified

122 self.used_refs = set()
123
124 def unique_ref(self, reference: str, found: bool = False) -> str:
125 """ Get a unique reference if there are duplicates. """
126 if not found:
127 return reference
128
129 original_ref = reference
130 while reference in self.used_refs:
131 ref, rest = reference.split(self.get_separator(), 1)
132 m = RE_REF_ID.match(ref)
133 if m:
134 reference = '%s%d%s%s' % (m.group(1), int(m.group(2))+1, self.get_separator(), rest)
135 else:
136 reference = '%s%d%s%s' % (ref, 2, self.get_separator(), rest)
137
138 self.used_refs.add(reference)
139 if original_ref in self.found_refs:
140 self.found_refs[original_ref] += 1
141 else:
142 self.found_refs[original_ref] = 1
143 return reference
144
145 def findFootnotesPlaceholder(
146 self, root: etree.Element

Callers 1

makeFootnoteRefIdMethod · 0.95

Calls 1

get_separatorMethod · 0.95

Tested by

no test coverage detected