Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render table with trailing whitespace #391

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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 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 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>