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

Method __processPlaceholders

markdown/treeprocessors.py:172–251  ·  view source on GitHub ↗

Process string with placeholders and generate `ElementTree` tree. Arguments: data: String with placeholders instead of `ElementTree` elements. parent: Element, which contains processing inline data. isText: Boolean variable, True - it's text, Fal

(
        self,
        data: str | None,
        parent: etree.Element,
        isText: bool = True
    )

Source from the content-addressed store, hash-verified

170 node.insert(pos, newChild[0])
171
172 def __processPlaceholders(
173 self,
174 data: str | None,
175 parent: etree.Element,
176 isText: bool = True
177 ) -> list[tuple[etree.Element, list[str]]]:
178 """
179 Process string with placeholders and generate `ElementTree` tree.
180
181 Arguments:
182 data: String with placeholders instead of `ElementTree` elements.
183 parent: Element, which contains processing inline data.
184 isText: Boolean variable, True - it's text, False - it's a tail.
185
186 Returns:
187 List with `ElementTree` elements with applied inline patterns.
188
189 """
190 def linkText(text: str | None) -> None:
191 if text:
192 if result:
193 if result[-1][0].tail:
194 result[-1][0].tail += text
195 else:
196 result[-1][0].tail = text
197 elif not isText:
198 if parent.tail:
199 parent.tail += text
200 else:
201 parent.tail = text
202 else:
203 if parent.text:
204 parent.text += text
205 else:
206 parent.text = text
207 result = []
208 strartIndex = 0
209 while data:
210 index = data.find(self.__placeholder_prefix, strartIndex)
211 if index != -1:
212 id, phEndIndex = self.__findPlaceholder(data, index)
213
214 if id in self.stashed_nodes:
215 node = self.stashed_nodes.get(id)
216
217 if index > 0:
218 text = data[strartIndex:index]
219 linkText(text)
220
221 if not isinstance(node, str): # it's Element
222 for child in [node] + list(node):
223 if child.tail:
224 if child.tail.strip():
225 self.__processElementText(
226 node, child, False
227 )
228 if child.text:
229 if child.text.strip():

Callers 2

__processElementTextMethod · 0.95
runMethod · 0.95

Calls 2

__findPlaceholderMethod · 0.95
__processElementTextMethod · 0.95

Tested by

no test coverage detected