Skip to content

Handle missing run for leading br tag#53

Open
dashingdove wants to merge 1 commit intopqzx:masterfrom
dashingdove:allow-leading-br
Open

Handle missing run for leading br tag#53
dashingdove wants to merge 1 commit intopqzx:masterfrom
dashingdove:allow-leading-br

Conversation

@dashingdove
Copy link
Copy Markdown

@dashingdove dashingdove commented Feb 7, 2023

(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.

Copy link
Copy Markdown

@giurul giurul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

@dashingdove
Copy link
Copy Markdown
Author

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.

giurul added a commit to giurul/html2docx that referenced this pull request May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants