Skip to content

Commit

Permalink
Merge pull request #415 from ColonelThirtyTwo/fix-rich-text-paragraph
Browse files Browse the repository at this point in the history
Fix exception when converting rich text with paragraph alignments
  • Loading branch information
chrismaddalena authored Apr 10, 2024
2 parents aac9fb8 + 840227e commit 28c7d12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ghostwriter/modules/reportwriter/html_to_docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def tag_p(self, el, *, par=None, **kwargs):
# Top level <p>
par = self.doc.add_paragraph(style=self.p_style)

par_classes = set(el.attrs.get("class", "").split())
par_classes = set(el.attrs.get("class", []))
if "left" in par_classes:
par.alignment = WD_ALIGN_PARAGRAPH.LEFT
if "center" in par_classes:
Expand Down
2 changes: 1 addition & 1 deletion ghostwriter/modules/reportwriter/html_to_pptx.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def tag_p(self, el, **kwargs):
self.text_tracking.new_block()
par = self.shape.text_frame.add_paragraph()

par_classes = set(el.attrs.get("class", "").split())
par_classes = set(el.attrs.get("class", []))
if "left" in par_classes:
par.alignment = PP_ALIGN.LEFT
if "center" in par_classes:
Expand Down
13 changes: 13 additions & 0 deletions ghostwriter/reporting/tests/test_rich_text_docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,16 @@ class RichTextToDocxTests(TestCase):
</w:tbl>
""",
)

test_paragraph_class = mk_test_docx(
"test_paragraph_class",
"""
<p class="left">Paragraph with a class</p>
""",
"""
<w:p>
<w:pPr><w:jc w:val="left"/></w:pPr>
<w:r><w:t>Paragraph with a class</w:t></w:r>
</w:p>
"""
)

0 comments on commit 28c7d12

Please sign in to comment.