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

Class AbbrBlockprocessor

markdown/extensions/abbr.py:131–168  ·  view source on GitHub ↗

Parse text for abbreviation references.

Source from the content-addressed store, hash-verified

129
130
131class AbbrBlockprocessor(BlockProcessor):
132 """ Parse text for abbreviation references. """
133
134 RE = re.compile(r'^[*]\[(?P<abbr>[^\\]*?)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$', re.MULTILINE)
135
136 def __init__(self, parser: BlockParser, abbrs: dict):
137 self.abbrs: dict = abbrs
138 super().__init__(parser)
139
140 def test(self, parent: etree.Element, block: str) -> bool:
141 return True
142
143 def run(self, parent: etree.Element, blocks: list[str]) -> bool:
144 """
145 Find and remove all abbreviation references from the text.
146 Each reference is added to the abbreviation collection.
147
148 """
149 block = blocks.pop(0)
150 m = self.RE.search(block)
151 if m:
152 abbr = m.group('abbr').strip()
153 title = m.group('title').strip()
154 if title and abbr:
155 if title == "''" or title == '""':
156 self.abbrs.pop(abbr)
157 else:
158 self.abbrs[abbr] = title
159 if block[m.end():].strip():
160 # Add any content after match back to blocks as separate block
161 blocks.insert(0, block[m.end():].lstrip('\n'))
162 if block[:m.start()].strip():
163 # Add any content before match back to blocks as separate block
164 blocks.insert(0, block[:m.start()].rstrip('\n'))
165 return True
166 # No match. Restore block.
167 blocks.insert(0, block)
168 return False
169
170
171AbbrPreprocessor = deprecated("This class has been renamed to `AbbrBlockprocessor`.")(AbbrBlockprocessor)

Callers 1

extendMarkdownMethod · 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…