From 149ef79e897562bd1e5b2b99131bd6af642e625b Mon Sep 17 00:00:00 2001 From: dashingdove <76248251+dashingdove@users.noreply.github.com> Date: Tue, 7 Feb 2023 14:31:35 +0800 Subject: [PATCH] Handle missing run for leading br tag --- htmldocx/h2d.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htmldocx/h2d.py b/htmldocx/h2d.py index 6a0e113..a5225fe 100644 --- a/htmldocx/h2d.py +++ b/htmldocx/h2d.py @@ -419,7 +419,10 @@ def handle_starttag(self, tag, attrs): self.tags['list'].append(tag) return # don't apply styles for now elif tag == 'br': - self.run.add_break() + try: + self.run.add_break() + except AttributeError: #If
is the first element parsed, self.run will not be defined + self.doc.add_paragraph() return self.tags[tag] = current_attrs