Render table with trailing whitespace (dart-lang/markdown#391)
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index 2f7969f..e22c442 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md
@@ -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
diff --git a/pkgs/markdown/lib/src/block_parser.dart b/pkgs/markdown/lib/src/block_parser.dart index 49ee387..7e67c19 100644 --- a/pkgs/markdown/lib/src/block_parser.dart +++ b/pkgs/markdown/lib/src/block_parser.dart
@@ -49,7 +49,8 @@ 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.
diff --git a/pkgs/markdown/test/extensions/tables.unit b/pkgs/markdown/test/extensions/tables.unit index 1a1fa11..9516fb3 100644 --- a/pkgs/markdown/test/extensions/tables.unit +++ b/pkgs/markdown/test/extensions/tables.unit
@@ -27,6 +27,13 @@ <<< <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 head `code` | _cells_ ------------|-------- @@ -91,3 +98,9 @@ <<< <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>