html2docx
html2docx copied to clipboard
Handle missing run for leading br tag
(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.
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.