Skip to content

Commit

Permalink
Merge pull request #550 from Crozzers/trailing-table-whitespace
Browse files Browse the repository at this point in the history
Fix tables with trailing whitespace not being recognized (#549)
  • Loading branch information
nicholasserra committed Dec 10, 2023
2 parents 9178066 + 3b3e845 commit 37ed941
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Expand Up @@ -2,7 +2,7 @@

## python-markdown2 2.4.12 (not yet released)

(nothing yet)
- [pull #550] Fix tables with trailing whitespace not being recognized (#549)


## python-markdown2 2.4.11
Expand Down
8 changes: 4 additions & 4 deletions lib/markdown2.py
Expand Up @@ -1241,21 +1241,21 @@ def _do_tables(self, text):
(?:(?<=\n\n)|\A\n?) # leading blank line
^[ ]{0,%d} # allowed whitespace
(.*[|].*) \n # $1: header row (at least one pipe)
(.*[|].*)[ ]*\n # $1: header row (at least one pipe)
^[ ]{0,%d} # allowed whitespace
( # $2: underline row
# underline row with leading bar
(?: \|\ *:?-+:?\ * )+ \|? \s? \n
(?: \|\ *:?-+:?\ * )+ \|? \s?[ ]*\n
|
# or, underline row without leading bar
(?: \ *:?-+:?\ *\| )+ (?: \ *:?-+:?\ * )? \s? \n
(?: \ *:?-+:?\ *\| )+ (?: \ *:?-+:?\ * )? \s?[ ]*\n
)
( # $3: data rows
(?:
^[ ]{0,%d}(?!\ ) # ensure line begins with 0 to less_than_tab spaces
.*\|.* \n
.*\|.*[ ]*\n
)+
)
''' % (less_than_tab, less_than_tab, less_than_tab), re.M | re.X)
Expand Down
22 changes: 22 additions & 0 deletions test/tm-cases/trailing_table_whitespace.html
@@ -0,0 +1,22 @@
<table>
<thead>
<tr>
<th>Pros</th>
<th>Cons</th>
</tr>
</thead>
<tbody>
<tr>
<td>Unique and refreshing take on the genre</td>
<td>May not resonate with all viewers</td>
</tr>
<tr>
<td>Cult classic status</td>
<td>Over-the-top humor may polarize audiences</td>
</tr>
<tr>
<td>Influential in launching careers</td>
<td>Niche appeal among comedy aficionados</td>
</tr>
</tbody>
</table>
1 change: 1 addition & 0 deletions test/tm-cases/trailing_table_whitespace.opts
@@ -0,0 +1 @@
{"extras": ["tables"]}
5 changes: 5 additions & 0 deletions test/tm-cases/trailing_table_whitespace.text
@@ -0,0 +1,5 @@
| Pros | Cons |
|-----------------------------------------|------------------------------------------------|
| Unique and refreshing take on the genre | May not resonate with all viewers |
| Cult classic status | Over-the-top humor may polarize audiences |
| Influential in launching careers | Niche appeal among comedy aficionados |

0 comments on commit 37ed941

Please sign in to comment.