Skip to content

Commit

Permalink
Render table with trailing whitespace (dart-lang/markdown#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Feb 17, 2022
1 parent 0e852ef commit 8f18b16
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkgs/markdown/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Breaking change: Change the type of `parseInline`'s parameter from `String?`
to `String`.
* Fix table-rendering bug when table rows have trailing whitespace.
[#368](https://github.com/dart-lang/markdown/issues/368).

## 4.0.1

Expand Down
3 changes: 2 additions & 1 deletion pkgs/markdown/lib/src/block_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ final _olPattern =
RegExp(r'^([ ]{0,3})(\d{1,9})([\.)])(([ \t])([ \t]*)(.*))?$');

/// A line of hyphens separated by at least one pipe.
final _tablePattern = RegExp(r'^[ ]{0,3}\|?( *:?\-+:? *\|)+( *:?\-+:? *)?$');
final _tablePattern = RegExp(
r'^[ ]{0,3}\|?([ \t]*:?\-+:?[ \t]*\|)+([ \t]|[ \t]*:?\-+:?[ \t]*)?$');

/// A pattern which should never be used. It just satisfies non-nullability of
/// pattern fields.
Expand Down
13 changes: 13 additions & 0 deletions pkgs/markdown/test/extensions/tables.unit
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ more | cells
| -- | --- |
| body | cells |

<<<
<table><thead><tr><th>head</th><th>cells</th></tr></thead><tbody><tr><td>body</td><td>cells</td></tr></tbody></table>
>>> rows wrapped in pipes, tabs in whitespace
| head | cells |
| -- | --- |
| body | cells |

<<<
<table><thead><tr><th>head</th><th>cells</th></tr></thead><tbody><tr><td>body</td><td>cells</td></tr></tbody></table>
>>> cells with inline syntax
Expand Down Expand Up @@ -91,3 +98,9 @@ too | many | cells | here

<<<
<table><thead><tr><th>Name</th><th>Character</th></tr></thead><tbody><tr><td>Pipe</td><td>| abcdef</td></tr></tbody></table>
>>> trailing whitespace after final pipe
| Name | Character |
| --- | --- |
| Pipe | abcdef |
<<<
<table><thead><tr><th>Name</th><th>Character</th></tr></thead><tbody><tr><td>Pipe</td><td>abcdef</td></tr></tbody></table>

0 comments on commit 8f18b16

Please sign in to comment.