Element Strip
Internal utility element_strip() used by mixin_paragraph, Reference.
Functions:
| Name | Description |
|---|---|
strip_elements |
Remove the tags of specified sub-elements within a given element, |
strip_tags |
Recursively remove a selection of tags from an element, preserving |
_strip_tags
_strip_tags(
element: Element,
strip: Iterable[str],
protect: Iterable[str],
protected: bool,
) -> tuple[Element | list[Element | str], bool]
Internal recursive helper for strip_tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element
|
The current element to process. |
required |
strip
|
Iterable[str]
|
Tags to be stripped. |
required |
protect
|
Iterable[str]
|
Tags to be protected. |
required |
protected
|
bool
|
A flag indicating if the current element is under a protected parent. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Element | list[Element | str], bool]
|
tuple[Element | list[Element | str], bool]: A tuple containing the processed element or list of elements, and a boolean indicating if any modification occurred. |
Source code in odfdo/element_strip.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
strip_elements
strip_elements(
element: Element,
sub_elements: Element | Iterable[Element],
) -> Element | list[Element | str]
Remove the tags of specified sub-elements within a given element, preserving their inner children and text content.
Warning: This function modifies the sub_elements in place and does not
create clones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element
|
The parent element from which tags will be stripped. |
required |
sub_elements
|
Element | Iterable[Element]
|
An element or a list of elements whose tags should be stripped. |
required |
Returns:
| Type | Description |
|---|---|
Element | list[Element | str]
|
Element | list[Element | str]: The modified element. If the top-level element itself is stripped, it may return a list of its children and text content. |
Source code in odfdo/element_strip.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
strip_tags
strip_tags(
element: Element,
strip: Iterable[str] | None = None,
protect: Iterable[str] | None = None,
default: str | None = "text:p",
) -> Element | list[Element | str]
Recursively remove a selection of tags from an element, preserving their inner content (children and text).
This function is analogous to lxml.etree.strip_tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
Element
|
The element to strip tags from. |
required |
strip
|
Iterable[str] | None
|
A list of qualified ODF tag names
(e.g., “text:span”) to remove. If |
None
|
protect
|
Iterable[str] | None
|
A list of qualified ODF tag names that should not be stripped. The protection applies to the element itself but not its descendants. |
None
|
default
|
str | None
|
If the top-level |
'text:p'
|
Returns:
| Type | Description |
|---|---|
Element | list[Element | str]
|
Element | list[Element | str]: The modified element. If the top-level
|
Source code in odfdo/element_strip.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |