MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / run

Method run

markdown/extensions/admonition.py:141–177  ·  view source on GitHub ↗
(self, parent: etree.Element, blocks: list[str])

Source from the content-addressed store, hash-verified

139 return self.parse_content(parent, block)[0] is not None
140
141 def run(self, parent: etree.Element, blocks: list[str]) -> None:
142 block = blocks.pop(0)
143 m = self.RE.search(block)
144
145 if m:
146 if m.start() > 0:
147 self.parser.parseBlocks(parent, [block[:m.start()]])
148 block = block[m.end():] # removes the first line
149 block, theRest = self.detab(block)
150 else:
151 sibling, block, theRest = self.parse_content(parent, block)
152
153 if m:
154 klass, title = self.get_class_and_title(m)
155 div = etree.SubElement(parent, 'div')
156 div.set('class', '{} {}'.format(self.CLASSNAME, klass))
157 if title:
158 p = etree.SubElement(div, 'p')
159 p.text = title
160 p.set('class', self.CLASSNAME_TITLE)
161 else:
162 # Sibling is a list item, but we need to wrap it's content should be wrapped in <p>
163 if sibling.tag in ('li', 'dd') and sibling.text:
164 text = sibling.text
165 sibling.text = ''
166 p = etree.SubElement(sibling, 'p')
167 p.text = text
168
169 div = sibling
170
171 self.parser.parseChunk(div, block)
172
173 if theRest:
174 # This block contained unindented line(s) after the first indented
175 # line. Insert these lines as the first block of the master blocks
176 # list for future processing.
177 blocks.insert(0, theRest)
178
179 def get_class_and_title(self, match: re.Match[str]) -> tuple[str, str | None]:
180 klass, title = match.group(1).lower(), match.group(2)

Callers

nothing calls this directly

Calls 7

parse_contentMethod · 0.95
get_class_and_titleMethod · 0.95
searchMethod · 0.80
parseBlocksMethod · 0.80
setMethod · 0.80
parseChunkMethod · 0.80
detabMethod · 0.45

Tested by

no test coverage detected