`a:p` custom element class
| 394 | |
| 395 | |
| 396 | class CT_TextParagraph(BaseOxmlElement): |
| 397 | """`a:p` custom element class""" |
| 398 | |
| 399 | get_or_add_endParaRPr: Callable[[], CT_TextCharacterProperties] |
| 400 | get_or_add_pPr: Callable[[], CT_TextParagraphProperties] |
| 401 | r_lst: list[CT_RegularTextRun] |
| 402 | _add_br: Callable[[], CT_TextLineBreak] |
| 403 | _add_r: Callable[[], CT_RegularTextRun] |
| 404 | |
| 405 | pPr: CT_TextParagraphProperties | None = ZeroOrOne( # pyright: ignore[reportAssignmentType] |
| 406 | "a:pPr", successors=("a:r", "a:br", "a:fld", "a:endParaRPr") |
| 407 | ) |
| 408 | r = ZeroOrMore("a:r", successors=("a:endParaRPr",)) |
| 409 | br = ZeroOrMore("a:br", successors=("a:endParaRPr",)) |
| 410 | endParaRPr: CT_TextCharacterProperties | None = ZeroOrOne( |
| 411 | "a:endParaRPr", successors=() |
| 412 | ) # pyright: ignore[reportAssignmentType] |
| 413 | |
| 414 | def add_br(self) -> CT_TextLineBreak: |
| 415 | """Return a newly appended `a:br` element.""" |
| 416 | return self._add_br() |
| 417 | |
| 418 | def add_r(self, text: str | None = None) -> CT_RegularTextRun: |
| 419 | """Return a newly appended `a:r` element.""" |
| 420 | r = self._add_r() |
| 421 | if text: |
| 422 | r.text = text |
| 423 | return r |
| 424 | |
| 425 | def append_text(self, text: str): |
| 426 | """Append `a:r` and `a:br` elements to `p` based on `text`. |
| 427 | |
| 428 | Any `\n` or `\v` (vertical-tab) characters in `text` delimit `a:r` (run) elements and |
| 429 | themselves are translated to `a:br` (line-break) elements. The vertical-tab character |
| 430 | appears in clipboard text from PowerPoint at "soft" line-breaks (new-line, but not new |
| 431 | paragraph). |
| 432 | """ |
| 433 | for idx, r_str in enumerate(re.split("\n|\v", text)): |
| 434 | # ---breaks are only added _between_ items, not at start--- |
| 435 | if idx > 0: |
| 436 | self.add_br() |
| 437 | # ---runs that would be empty are not added--- |
| 438 | if r_str: |
| 439 | self.add_r(r_str) |
| 440 | |
| 441 | @property |
| 442 | def content_children(self) -> tuple[CT_RegularTextRun | CT_TextLineBreak | CT_TextField, ...]: |
| 443 | """Sequence containing text-container child elements of this `a:p` element. |
| 444 | |
| 445 | These include `a:r`, `a:br`, and `a:fld`. |
| 446 | """ |
| 447 | return tuple( |
| 448 | e for e in self if isinstance(e, (CT_RegularTextRun, CT_TextLineBreak, CT_TextField)) |
| 449 | ) |
| 450 | |
| 451 | @property |
| 452 | def text(self) -> str: # pyright: ignore[reportIncompatibleMethodOverride] |
| 453 | """str text contained in this paragraph.""" |
nothing calls this directly
no test coverage detected
searching dependent graphs…