html2docx icon indicating copy to clipboard operation
html2docx copied to clipboard

Handle missing run for leading br tag

Open dashingdove opened this issue 2 years ago • 1 comments

(Issue #37) When the HTML to parse begins with a <br> tag, an error is thrown because self.run is not defined. This is a simple fix to handle the error.

dashingdove avatar Feb 07 '23 06:02 dashingdove

Can you use this to recreate a real line break?

try:
    self.run.add_break()
except AttributeError: #If <br> is the first element parsed, self.run will not be defined
    self.paragraph = self.doc.add_paragraph()
    self.run = self.paragraph.add_run()
    self.run.add_break()

Yes, you could add a line break in that way. However, adding the paragraph itself creates a new line and so you would end up with the appearance of two new lines, I believe.

dashingdove avatar May 16 '23 11:05 dashingdove