Draft
Conversation
Author
|
If anyone else is experiencing the same issue, the following regex substitution can be used as a workaround: import re
from html2text import HTML2Text
data = "<table><tr><td></td><td>a</td></tr></table>"
result = HTML2Text().handle(data)
print(result)
# | a
# ---|---
result = re.sub(
r"^((\|\s+[^\|]+\s+)((\|\s+[^\|]+\s+|:?-+:?\|)(\|\s+[^\|]+\s+|:?-+:?\|))*:?-+:?\|:?-+:?\s*$)",
r"| \1",
result,
0,
re.MULTILINE,
)
print(result)
print(result)
# | | a
# ---|---It adds an empty cell at the start of the table if the number of header cells does not match the number of columns in the table. |
Owner
|
Can you please update the code with tests? |
If the first cell of a table is empty, no entry was created for in in the markdown table. This resulted in markdown tables which do parse properly.
dff8aa3 to
41f88f5
Compare
Owner
|
@joouha Thanks for adding the tests and the patch. You can run the tests locally by |
|
i encountered same issue, like: right expression need to be: |
html2text.config.PAD_TABLES = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello
This PR fixes an issue where an empty first cell in a table results in markdown tables which do parse properly.
For example:
results in the following output:
which is not a valid markdown table:
| b
---|---
c | d
With this fix, the output is:
which renders correctly: