MCPcopy Create free account
hub / github.com/scanny/python-pptx / CT_RegularTextRun

Class CT_RegularTextRun

src/pptx/oxml/text.py:47–76  ·  view source on GitHub ↗

`a:r` custom element class

Source from the content-addressed store, hash-verified

45
46
47class CT_RegularTextRun(BaseOxmlElement):
48 """`a:r` custom element class"""
49
50 get_or_add_rPr: Callable[[], CT_TextCharacterProperties]
51
52 rPr: CT_TextCharacterProperties | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
53 "a:rPr", successors=("a:t",)
54 )
55 t: BaseOxmlElement = OneAndOnlyOne("a:t") # pyright: ignore[reportAssignmentType]
56
57 @property
58 def text(self) -> str:
59 """All text of (required) `a:t` child."""
60 text = self.t.text
61 # -- t.text is None when t element is empty, e.g. '<a:t/>' --
62 return text or ""
63
64 @text.setter
65 def text(self, value: str): # pyright: ignore[reportIncompatibleMethodOverride]
66 self.t.text = self._escape_ctrl_chars(value)
67
68 @staticmethod
69 def _escape_ctrl_chars(s: str) -> str:
70 """Return str after replacing each control character with a plain-text escape.
71
72 For example, a BEL character (x07) would appear as "_x0007_". Horizontal-tab
73 (x09) and line-feed (x0A) are not escaped. All other characters in the range
74 x00-x1F are escaped.
75 """
76 return re.sub(r"([\x00-\x08\x0B-\x1F])", lambda match: "_x%04X_" % ord(match.group(1)), s)
77
78
79class CT_TextBody(BaseOxmlElement):

Callers

nothing calls this directly

Calls 2

ZeroOrOneClass · 0.90
OneAndOnlyOneClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…