Skip to content

Commit fe5f996

Browse files
committed
add table options, fix ext-gfm-tables and ext-tables
1 parent 48da29a commit fe5f996

File tree

47 files changed

+2727
-591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2727
-591
lines changed

META-INF/MANIFEST.MF

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+

VERSION.md

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
Version History
22
===============
33

4+
0.1.4
5+
-----
6+
7+
- Remove options argument from flexmark-ext-tables `TablesExtension::create()`
8+
9+
- Fix `ReferenceRepository` to use `Escaping::normalizeReference` for reference normalization.
10+
11+
- Fix `CoreNodeRenderer` to use `SUPPRESS_HTML_BLOCK` instead of `SUPPRESS_INLINE_HTML`
12+
13+
- Add `HtmlWriter::withCondLine()` to make next tag output an EOL only if there is child text
14+
between the opening and closing tags. Only works for methods that take a `Runnable` argument
15+
for output child text.
16+
17+
- Fix ext-gfm-tables for incorrect separator line parsing, introduced right before ext-gfm-tables
18+
and ext-tables split.
19+
20+
- Fix ext-tables to handle multi-line headers or no line headers with options MIN_HEADER_ROWS,
21+
MAX_HEADER_ROWS.
22+
23+
- Add ext-tables option HEADER_SEPARATOR_COLUMNS, if true will only recognize tables whose
24+
headers contain no more columns than the separator line. Default false, any number of columns
25+
in header lines will be accepted.
26+
427
0.1.3
528
-----
629

flexmark-ext-abbreviation/flexmark-ext-abbreviation.iml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
@@ -16,4 +16,4 @@
1616
<orderEntry type="module" module-name="flexmark" />
1717
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
1818
</component>
19-
</module>
19+
</module>

flexmark-ext-autolink/flexmark-ext-autolink.iml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
@@ -17,4 +17,4 @@
1717
<orderEntry type="module" module-name="flexmark" />
1818
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
1919
</component>
20-
</module>
20+
</module>

flexmark-ext-emoji/flexmark-ext-emoji.iml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
@@ -16,4 +16,4 @@
1616
<orderEntry type="module" module-name="flexmark" />
1717
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
1818
</component>
19-
</module>
19+
</module>

flexmark-ext-gfm-strikethrough/flexmark-ext-gfm-strikethrough.iml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
@@ -16,4 +16,4 @@
1616
<orderEntry type="module" module-name="flexmark" />
1717
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
1818
</component>
19-
</module>
19+
</module>

flexmark-ext-gfm-tables/flexmark-ext-gfm-tables.iml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
@@ -16,4 +16,4 @@
1616
<orderEntry type="module" module-name="flexmark" />
1717
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
1818
</component>
19-
</module>
19+
</module>

flexmark-ext-gfm-tables/src/main/java/com/vladsch/flexmark/ext/gfm/tables/internal/TableBlockParser.java

+20-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.vladsch.flexmark.ext.gfm.tables.internal;
22

33
import com.vladsch.flexmark.ext.gfm.tables.*;
4+
import com.vladsch.flexmark.internal.BlockContent;
45
import com.vladsch.flexmark.internal.util.BasedSequence;
56
import com.vladsch.flexmark.internal.util.SubSequence;
67
import com.vladsch.flexmark.node.Block;
@@ -22,18 +23,17 @@ public class TableBlockParser extends AbstractBlockParser {
2223
"\\|?" + "(?:" + COL + "\\|)+" + COL + "\\|?\\s*");
2324

2425
private final TableBlock block = new TableBlock();
25-
private final List<BasedSequence> rowLines = new ArrayList<>();
26+
private final BlockContent content = new BlockContent();
2627

27-
private boolean nextIsSeparatorLine = true;
28+
private boolean nextIsSeparatorLine = false;
2829
private BasedSequence separatorLine = SubSequence.NULL;
2930
private int separatorLineNumber = 0;
3031

3132
public static boolean bodyColumnsFilledToHead = true;
3233
public static boolean bodyColumnsTruncatedToHead = true;
3334
public static int maxHeaderRows = 1;
3435

35-
private TableBlockParser(BasedSequence headerLine) {
36-
rowLines.add(headerLine);
36+
private TableBlockParser() {
3737
}
3838

3939
@Override
@@ -55,16 +55,14 @@ public void addLine(BasedSequence line, int eolLength) {
5555
if (nextIsSeparatorLine) {
5656
nextIsSeparatorLine = false;
5757
separatorLine = line;
58-
separatorLineNumber = rowLines.size();
59-
rowLines.add(line);
60-
} else {
61-
rowLines.add(line);
58+
separatorLineNumber = content.getLineCount();
6259
}
60+
content.add(line, eolLength);
6361
}
6462

6563
@Override
6664
public void closeBlock(ParserState parserState) {
67-
block.setCharsFromContent();
65+
block.setContent(content);
6866
}
6967

7068
@Override
@@ -75,8 +73,9 @@ public void parseInlines(InlineParser inlineParser) {
7573
List<TableCell.Alignment> alignments = parseAlignment(separatorLine);
7674

7775
int rowNumber = 0;
78-
int headerColumns = -1;
79-
for (BasedSequence rowLine : rowLines) {
76+
int separatorColumns = alignments.size();
77+
78+
for (BasedSequence rowLine : content.getLines()) {
8079
if (rowNumber == separatorLineNumber) {
8180
section.setCharsFromContent();
8281
section = new TableSeparator();
@@ -88,23 +87,15 @@ public void parseInlines(InlineParser inlineParser) {
8887
}
8988

9089
List<BasedSequence> cells = split(rowLine);
91-
TableRow tableRow = new TableRow();
90+
TableRow tableRow = new TableRow(rowLine.subSequence(0, rowLine.length() - content.getEolLength()));
9291

9392
int rowCells = countCells(cells);
9493
int maxColumns = rowCells;
9594

96-
if (rowNumber < separatorLineNumber || headerColumns == -1) {
97-
if (headerColumns == -1) {
98-
headerColumns = rowCells;
99-
} else if (headerColumns < rowCells) {
100-
headerColumns = rowCells;
101-
}
102-
}
103-
104-
if (bodyColumnsTruncatedToHead && maxColumns > headerColumns) maxColumns = headerColumns;
95+
if (bodyColumnsTruncatedToHead && maxColumns > separatorColumns) maxColumns = separatorColumns;
10596
if (rowNumber >= separatorLineNumber) {
10697
if (!bodyColumnsFilledToHead && rowCells < maxColumns) maxColumns = rowCells;
107-
else if (bodyColumnsFilledToHead && maxColumns < headerColumns) maxColumns = headerColumns;
98+
else if (bodyColumnsFilledToHead && maxColumns < separatorColumns) maxColumns = separatorColumns;
10899
}
109100

110101
int segmentOffset = 0;
@@ -185,7 +176,7 @@ private static List<BasedSequence> split(BasedSequence input) {
185176
List<BasedSequence> segments = new ArrayList<>();
186177

187178
if (line.startsWith("|")) {
188-
segments.add(line.subSequence(0, 1));
179+
//segments.add(line.subSequence(0, 1));
189180
line = line.subSequence(1, lineLength);
190181
lineLength--;
191182
}
@@ -207,7 +198,7 @@ private static List<BasedSequence> split(BasedSequence input) {
207198
break;
208199
case '|':
209200
segments.add(line.subSequence(lastPos, i));
210-
segments.add(line.subSequence(i, i + 1));
201+
//segments.add(line.subSequence(i, i + 1));
211202
lastPos = i + 1;
212203
cellChars = 0;
213204
break;
@@ -248,7 +239,11 @@ public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockPar
248239
List<BasedSequence> headParts = split(paragraph);
249240
List<BasedSequence> separatorParts = split(separatorLine);
250241
if (separatorParts.size() >= headParts.size()) {
251-
return BlockStart.of(new TableBlockParser(paragraph))
242+
TableBlockParser tableBlockParser = new TableBlockParser();
243+
tableBlockParser.addLine(paragraph, matchedBlockParser.getParagraphEolLengths().get(0));
244+
tableBlockParser.nextIsSeparatorLine = true;
245+
246+
return BlockStart.of(tableBlockParser)
252247
.atIndex(state.getIndex())
253248
.replaceActiveBlockParser();
254249
}

flexmark-ext-gfm-tables/src/main/java/com/vladsch/flexmark/ext/gfm/tables/internal/TableNodeRenderer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void renderBlock(TableBlock tableBlock) {
5656
}
5757

5858
private void renderHead(TableHead tableHead) {
59-
html.withAttr().tagIndent("thead", () -> {
59+
html.withAttr().withCondLine().tagIndent("thead", () -> {
6060
context.renderChildren(tableHead);
6161
});
6262
}
@@ -66,7 +66,7 @@ private void renderSeparator(TableSeparator tableSeparator) {
6666
}
6767

6868
private void renderBody(TableBody tableBody) {
69-
html.withAttr().tagIndent("tbody", () -> {
69+
html.withAttr().withCondLine().tagIndent("tbody", () -> {
7070
context.renderChildren(tableBody);
7171
});
7272
}

flexmark-ext-gfm-tables/src/test/java/com/vladsch/flexmark/ext/gfm/tables/ExtGfmTablesTestSuite.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
@org.junit.runner.RunWith(Suite.class)
2727
@Suite.SuiteClasses({
28-
//TablesTest.class,
28+
TablesTest.class,
2929
TablesFullSpecTest.class,
3030
TablesSpecTest.class
3131
})

flexmark-ext-gfm-tables/src/test/java/com/vladsch/flexmark/ext/gfm/tables/TablesFullSpecTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public void setAttributes(Node node, String tag, Map<String, String> attributes)
5454
}
5555
}
5656
};
57-
57+
5858
HtmlRenderer renderer = HtmlRenderer.builder()
5959
.attributeProvider(attributeProvider)
6060
.extensions(EXTENSIONS)
6161
.build();
62-
62+
6363
String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2"));
6464
assertThat(rendered, is("<table test=\"block\">\n" +
6565
"<thead test=\"head\">\n" +

0 commit comments

Comments
 (0)