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

Method run

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected