MCPcopy
hub / github.com/mkdocs/mkdocs / _replace_elements_with_text

Function _replace_elements_with_text

mkdocs/utils/rendering.py:89–104  ·  view source on GitHub ↗

For each child element, if matched, replace it with the text returned from the predicate.

(
    parent: etree.Element, predicate: Callable[[etree.Element], str | None]
)

Source from the content-addressed store, hash-verified

87
88
89def _replace_elements_with_text(
90 parent: etree.Element, predicate: Callable[[etree.Element], str | None]
91) -> None:
92 """For each child element, if matched, replace it with the text returned from the predicate."""
93 carry_text = ""
94 for child in reversed(parent): # Reversed for the ability to mutate during iteration.
95 # Remove matching elements but carry any `tail` text to preceding elements.
96 new_text = predicate(child)
97 if new_text is not None:
98 carry_text = new_text + (child.tail or "") + carry_text
99 parent.remove(child)
100 elif carry_text:
101 child.tail = (child.tail or "") + carry_text
102 carry_text = ""
103 if carry_text:
104 parent.text = (parent.text or "") + carry_text

Callers 2

_remove_fnrefsFunction · 0.85
_extract_alt_textsFunction · 0.85

Calls 1

removeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…