|
5 | 5 | import itertools |
6 | 6 | import re |
7 | 7 |
|
8 | | -from docx.enum import text |
9 | 8 | from docx.text import paragraph as docx_paragraph |
10 | 9 | from docx.text import run as docx_run |
11 | 10 |
|
@@ -141,46 +140,31 @@ def insert_run(self, index: int, text: str, style: styles.RunStyle) -> docx_run. |
141 | 140 |
|
142 | 141 | def format( |
143 | 142 | self, |
144 | | - *, |
145 | | - bold: bool | None = None, |
146 | | - italics: bool | None = None, |
147 | | - font_size: int | None = None, |
148 | | - font_rgb: tuple[int, int, int] | None = None, |
149 | | - line_spacing: float | None = None, |
150 | | - space_before: float | None = None, |
151 | | - space_after: float | None = None, |
152 | | - alignment: text.WD_PARAGRAPH_ALIGNMENT | None = None, |
| 143 | + style: styles.ParagraphStyle, |
153 | 144 | ) -> None: |
154 | 145 | """Formats a paragraph in a Word document. |
155 | 146 |
|
156 | 147 | Args: |
157 | | - bold: Whether to bold the paragraph. |
158 | | - italics: Whether to italicize the paragraph. |
159 | | - font_size: The font size of the paragraph. |
160 | | - font_rgb: The font color of the paragraph. |
161 | | - line_spacing: The line spacing of the paragraph. |
162 | | - space_before: The spacing before the paragraph. |
163 | | - space_after: The spacing after the paragraph. |
164 | | - alignment: The alignment of the paragraph. |
| 148 | + style: The style to apply to the paragraph. |
165 | 149 | """ |
166 | | - if line_spacing is not None: |
167 | | - self.paragraph.paragraph_format.line_spacing = line_spacing |
| 150 | + if style.line_spacing is not None: |
| 151 | + self.paragraph.paragraph_format.line_spacing = style.line_spacing |
168 | 152 |
|
169 | | - if alignment is not None: |
170 | | - self.paragraph.alignment = alignment |
| 153 | + if style.alignment is not None: |
| 154 | + self.paragraph.alignment = style.alignment |
171 | 155 |
|
172 | | - if space_before is not None: |
173 | | - self.paragraph.paragraph_format.space_before = space_before |
| 156 | + if style.space_before is not None: |
| 157 | + self.paragraph.paragraph_format.space_before = style.space_before |
174 | 158 |
|
175 | | - if space_after is not None: |
176 | | - self.paragraph.paragraph_format.space_after = space_after |
| 159 | + if style.space_after is not None: |
| 160 | + self.paragraph.paragraph_format.space_after = style.space_after |
177 | 161 |
|
178 | 162 | for paragraph_run in self.paragraph.runs: |
179 | 163 | run.ExtendRun(paragraph_run).format( |
180 | 164 | styles.RunStyle( |
181 | | - bold=bold, |
182 | | - italic=italics, |
183 | | - font_size=font_size, |
184 | | - font_rgb=font_rgb, |
| 165 | + bold=style.bold, |
| 166 | + italic=style.italic, |
| 167 | + font_size=style.font_size, |
| 168 | + font_rgb=style.font_rgb, |
185 | 169 | ) |
186 | 170 | ) |
0 commit comments