diff --git a/html2docx/html2docx.py b/html2docx/html2docx.py index 0b83d1f..70ce413 100644 --- a/html2docx/html2docx.py +++ b/html2docx/html2docx.py @@ -99,7 +99,7 @@ def init_p(self, attrs: List[Tuple[str, Optional[str]]]) -> None: self.padding_left = Pt(style_decl["value"]) def finish_p(self) -> None: - if self.r is not None: + if not self.pre and self.r is not None: self.r.text = self.r.text.rstrip() self._reset() @@ -161,7 +161,10 @@ def add_text(self, data: str) -> None: for attrs in self.attrs: for font_attr, value in attrs: setattr(self.r.font, font_attr, value) - self.r.add_text(data) + if self.pre: + self.r.text = data + else: + self.r.add_text(data) def add_list_style(self, name: str) -> None: self.finish_p() diff --git a/tests/data/pre-nested-strong.html b/tests/data/pre-nested-strong.html new file mode 100644 index 0000000..35db1a3 --- /dev/null +++ b/tests/data/pre-nested-strong.html @@ -0,0 +1,2 @@ +
line1
+line2
\ No newline at end of file diff --git a/tests/data/pre-nested-strong.json b/tests/data/pre-nested-strong.json new file mode 100644 index 0000000..f5b3b5b --- /dev/null +++ b/tests/data/pre-nested-strong.json @@ -0,0 +1,14 @@ +[ + { + "text": "line1\nline2", + "runs": [ + { + "text": "line1\n" + }, + { + "text": "line2", + "bold": true + } + ] + } +]