Table tweaks
diff --git a/pkgs/markdown/lib/src/block_parser.dart b/pkgs/markdown/lib/src/block_parser.dart index 0b03b8a..c26056a 100644 --- a/pkgs/markdown/lib/src/block_parser.dart +++ b/pkgs/markdown/lib/src/block_parser.dart
@@ -116,8 +116,9 @@ /// /// `peek(1)` is equivalent to [next]. String peek(int linesAhead) { - if (linesAhead < 0) throw new ArgumentError( - 'Invalid linesAhead: $linesAhead; must be >= 0.'); + if (linesAhead < 0) { + throw new ArgumentError('Invalid linesAhead: $linesAhead; must be >= 0.'); + } // Don't read past the end. if (_pos >= lines.length - linesAhead) return null; return lines[_pos + linesAhead]; @@ -711,6 +712,8 @@ /// Parses tables. class TableSyntax extends BlockSyntax { + static final _pipePattern = new RegExp(r'\s*\|\s*'); + bool get canEndBlock => false; const TableSyntax(); @@ -758,29 +761,16 @@ var line = parser.current .replaceFirst(new RegExp(r'^\|\s*'), '') .replaceFirst(new RegExp(r'\s*\|$'), ''); - var contents = parser.document.parseInline(line); + var cells = line.split(_pipePattern); parser.advance(); - var row = <Node>[]; - var cellContents = <Node>[]; - var pipe = new RegExp(r'\s*\|\s*'); + var row = <Element>[]; - contents.forEach((Node node) { - if (node is Text) { - var cells = node.text.split(pipe); - cells.sublist(0, cells.length - 1).forEach((String cell) { - cellContents.add(new Text(cell)); - row.add(new Element(cellType, cellContents)); - cellContents = <Node>[]; - }); - cellContents.add(new Text(cells.last)); - } else { - // An Element or something else. - cellContents.add(node); - } - }); - row.add(new Element(cellType, cellContents)); + for (String cell in cells) { + var contents = new UnparsedContent(cell); + row.add(new Element(cellType, [contents])); + } - for (int i = 0; i < row.length && i < alignments.length; i++) { + for (var i = 0; i < row.length && i < alignments.length; i++) { if (alignments[i] == null) continue; row[i].attributes['style'] = 'text-align: ${alignments[i]};'; }
diff --git a/pkgs/markdown/test/extensions/tables.unit b/pkgs/markdown/test/extensions/tables.unit index e16cde5..c1d6934 100644 --- a/pkgs/markdown/test/extensions/tables.unit +++ b/pkgs/markdown/test/extensions/tables.unit
@@ -26,12 +26,20 @@ *text* | <span>text</span> <<< <table><thead><tr><th>head <code>code</code></th><th><em>cells</em></th></tr></thead><tbody><tr><td><em>text</em></td><td><span>text</span></td></tr></tbody></table> ->>> cells with inline syntax with pipes +>>> cells are parsed before inline syntax header | _foo | bar_ -------|------------ text | text <<< -<table><thead><tr><th>header</th><th><em>foo | bar</em></th></tr></thead><tbody><tr><td>text</td><td>text</td></tr></tbody></table> +<table><thead><tr><th>header</th><th>_foo</th><th>bar_</th></tr></thead><tbody><tr><td>text</td><td>text</td></tr></tbody></table> +>>> cells contain reference links +header | header +-------|-------- +text | [link][here] + +[here]: http://url +<<< +<table><thead><tr><th>header</th><th>header</th></tr></thead><tbody><tr><td>text</td><td><a href="http://url">link</a></td></tr></tbody></table> >>> one column tables head -----|-----