|
1 | 1 | package org.commonmark.ext.gfm.tables; |
2 | 2 |
|
3 | 3 | import org.commonmark.Extension; |
4 | | -import org.commonmark.node.Node; |
5 | | -import org.commonmark.node.SourceSpan; |
| 4 | +import org.commonmark.node.*; |
6 | 5 | import org.commonmark.parser.IncludeSourceSpans; |
7 | 6 | import org.commonmark.parser.Parser; |
8 | 7 | import org.commonmark.renderer.html.AttributeProvider; |
@@ -79,11 +78,6 @@ public void separatorNeedsPipes() { |
79 | 78 | assertRendering("Abc|Def\n|--- ---", "<p>Abc|Def\n|--- ---</p>\n"); |
80 | 79 | } |
81 | 80 |
|
82 | | - @Test |
83 | | - public void headerMustBeOneLine() { |
84 | | - assertRendering("No\nAbc|Def\n---|---", "<p>No\nAbc|Def\n---|---</p>\n"); |
85 | | - } |
86 | | - |
87 | 81 | @Test |
88 | 82 | public void oneHeadNoBody() { |
89 | 83 | assertRendering("Abc|Def\n---|---", "<table>\n" + |
@@ -702,6 +696,26 @@ public void danglingPipe() { |
702 | 696 | "<p>|</p>\n"); |
703 | 697 | } |
704 | 698 |
|
| 699 | + @Test |
| 700 | + public void interruptsParagraph() { |
| 701 | + assertRendering("text\n" + |
| 702 | + "|a |\n" + |
| 703 | + "|---|\n" + |
| 704 | + "|b |", "<p>text</p>\n" + |
| 705 | + "<table>\n" + |
| 706 | + "<thead>\n" + |
| 707 | + "<tr>\n" + |
| 708 | + "<th>a</th>\n" + |
| 709 | + "</tr>\n" + |
| 710 | + "</thead>\n" + |
| 711 | + "<tbody>\n" + |
| 712 | + "<tr>\n" + |
| 713 | + "<td>b</td>\n" + |
| 714 | + "</tr>\n" + |
| 715 | + "</tbody>\n" + |
| 716 | + "</table>\n"); |
| 717 | + } |
| 718 | + |
705 | 719 | @Test |
706 | 720 | public void attributeProviderIsApplied() { |
707 | 721 | AttributeProviderFactory factory = new AttributeProviderFactory() { |
@@ -835,6 +849,36 @@ public void sourceSpans() { |
835 | 849 | assertThat(bodyRow3Cell2.getSourceSpans()).isEqualTo(List.of()); |
836 | 850 | } |
837 | 851 |
|
| 852 | + @Test |
| 853 | + public void sourceSpansWhenInterrupting() { |
| 854 | + var parser = Parser.builder() |
| 855 | + .extensions(EXTENSIONS) |
| 856 | + .includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES) |
| 857 | + .build(); |
| 858 | + var document = parser.parse("a\n" + |
| 859 | + "bc\n" + |
| 860 | + "|de|\n" + |
| 861 | + "|---|\n" + |
| 862 | + "|fg|"); |
| 863 | + |
| 864 | + var paragraph = (Paragraph) document.getFirstChild(); |
| 865 | + var text = (Text) paragraph.getFirstChild(); |
| 866 | + assertThat(text.getLiteral()).isEqualTo("a"); |
| 867 | + assertThat(text.getNext()).isInstanceOf(SoftLineBreak.class); |
| 868 | + var text2 = (Text) text.getNext().getNext(); |
| 869 | + assertThat(text2.getLiteral()).isEqualTo("bc"); |
| 870 | + |
| 871 | + assertThat(paragraph.getSourceSpans()).isEqualTo(List.of( |
| 872 | + SourceSpan.of(0, 0, 0, 1), |
| 873 | + SourceSpan.of(1, 0, 2, 2))); |
| 874 | + |
| 875 | + var table = (TableBlock) document.getLastChild(); |
| 876 | + assertThat(table.getSourceSpans()).isEqualTo(List.of( |
| 877 | + SourceSpan.of(2, 0, 5, 4), |
| 878 | + SourceSpan.of(3, 0, 10, 5), |
| 879 | + SourceSpan.of(4, 0, 16, 4))); |
| 880 | + } |
| 881 | + |
838 | 882 | @Override |
839 | 883 | protected String render(String source) { |
840 | 884 | return RENDERER.render(PARSER.parse(source)); |
|
0 commit comments