Proxy object wrapping a ` ` element.
| 21 | |
| 22 | |
| 23 | class Paragraph(StoryChild): |
| 24 | """Proxy object wrapping a `<w:p>` element.""" |
| 25 | |
| 26 | def __init__(self, p: CT_P, parent: t.ProvidesStoryPart): |
| 27 | super(Paragraph, self).__init__(parent) |
| 28 | self._p = self._element = p |
| 29 | |
| 30 | def add_run(self, text: str | None = None, style: str | CharacterStyle | None = None) -> Run: |
| 31 | """Append run containing `text` and having character-style `style`. |
| 32 | |
| 33 | `text` can contain tab (``\\t``) characters, which are converted to the |
| 34 | appropriate XML form for a tab. `text` can also include newline (``\\n``) or |
| 35 | carriage return (``\\r``) characters, each of which is converted to a line |
| 36 | break. When `text` is `None`, the new run is empty. |
| 37 | """ |
| 38 | r = self._p.add_r() |
| 39 | run = Run(r, self) |
| 40 | if text: |
| 41 | run.text = text |
| 42 | if style: |
| 43 | run.style = style |
| 44 | return run |
| 45 | |
| 46 | @property |
| 47 | def alignment(self) -> WD_PARAGRAPH_ALIGNMENT | None: |
| 48 | """A member of the :ref:`WdParagraphAlignment` enumeration specifying the |
| 49 | justification setting for this paragraph. |
| 50 | |
| 51 | A value of |None| indicates the paragraph has no directly-applied alignment |
| 52 | value and will inherit its alignment value from its style hierarchy. Assigning |
| 53 | |None| to this property removes any directly-applied alignment value. |
| 54 | """ |
| 55 | return self._p.alignment |
| 56 | |
| 57 | @alignment.setter |
| 58 | def alignment(self, value: WD_PARAGRAPH_ALIGNMENT): |
| 59 | self._p.alignment = value |
| 60 | |
| 61 | def clear(self): |
| 62 | """Return this same paragraph after removing all its content. |
| 63 | |
| 64 | Paragraph-level formatting, such as style, is preserved. |
| 65 | """ |
| 66 | self._p.clear_content() |
| 67 | return self |
| 68 | |
| 69 | @property |
| 70 | def contains_page_break(self) -> bool: |
| 71 | """`True` when one or more rendered page-breaks occur in this paragraph.""" |
| 72 | return bool(self._p.lastRenderedPageBreaks) |
| 73 | |
| 74 | @property |
| 75 | def hyperlinks(self) -> List[Hyperlink]: |
| 76 | """A |Hyperlink| instance for each hyperlink in this paragraph.""" |
| 77 | return [Hyperlink(hyperlink, self) for hyperlink in self._p.hyperlink_lst] |
| 78 | |
| 79 | def insert_paragraph_before( |
| 80 | self, text: str | None = None, style: str | ParagraphStyle | None = None |
no outgoing calls
searching dependent graphs…