Skip to content

Commit

Permalink
add table options, fix ext-gfm-tables and ext-tables
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Jun 14, 2016
1 parent 48da29a commit fe5f996
Show file tree
Hide file tree
Showing 47 changed files with 2,727 additions and 591 deletions.
2 changes: 2 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

23 changes: 23 additions & 0 deletions VERSION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
Version History
===============

0.1.4
-----

- Remove options argument from flexmark-ext-tables `TablesExtension::create()`

- Fix `ReferenceRepository` to use `Escaping::normalizeReference` for reference normalization.

- Fix `CoreNodeRenderer` to use `SUPPRESS_HTML_BLOCK` instead of `SUPPRESS_INLINE_HTML`

- Add `HtmlWriter::withCondLine()` to make next tag output an EOL only if there is child text
between the opening and closing tags. Only works for methods that take a `Runnable` argument
for output child text.

- Fix ext-gfm-tables for incorrect separator line parsing, introduced right before ext-gfm-tables
and ext-tables split.

- Fix ext-tables to handle multi-line headers or no line headers with options MIN_HEADER_ROWS,
MAX_HEADER_ROWS.

- Add ext-tables option HEADER_SEPARATOR_COLUMNS, if true will only recognize tables whose
headers contain no more columns than the separator line. Default false, any number of columns
in header lines will be accepted.

0.1.3
-----

Expand Down
4 changes: 2 additions & 2 deletions flexmark-ext-abbreviation/flexmark-ext-abbreviation.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Expand All @@ -16,4 +16,4 @@
<orderEntry type="module" module-name="flexmark" />
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
</component>
</module>
</module>
4 changes: 2 additions & 2 deletions flexmark-ext-autolink/flexmark-ext-autolink.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Expand All @@ -17,4 +17,4 @@
<orderEntry type="module" module-name="flexmark" />
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
</component>
</module>
</module>
4 changes: 2 additions & 2 deletions flexmark-ext-emoji/flexmark-ext-emoji.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Expand All @@ -16,4 +16,4 @@
<orderEntry type="module" module-name="flexmark" />
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
</component>
</module>
</module>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Expand All @@ -16,4 +16,4 @@
<orderEntry type="module" module-name="flexmark" />
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
</component>
</module>
</module>
4 changes: 2 additions & 2 deletions flexmark-ext-gfm-tables/flexmark-ext-gfm-tables.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="false" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Expand All @@ -16,4 +16,4 @@
<orderEntry type="module" module-name="flexmark" />
<orderEntry type="module" module-name="flexmark-test-util" scope="TEST" />
</component>
</module>
</module>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vladsch.flexmark.ext.gfm.tables.internal;

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

private final TableBlock block = new TableBlock();
private final List<BasedSequence> rowLines = new ArrayList<>();
private final BlockContent content = new BlockContent();

private boolean nextIsSeparatorLine = true;
private boolean nextIsSeparatorLine = false;
private BasedSequence separatorLine = SubSequence.NULL;
private int separatorLineNumber = 0;

public static boolean bodyColumnsFilledToHead = true;
public static boolean bodyColumnsTruncatedToHead = true;
public static int maxHeaderRows = 1;

private TableBlockParser(BasedSequence headerLine) {
rowLines.add(headerLine);
private TableBlockParser() {
}

@Override
Expand All @@ -55,16 +55,14 @@ public void addLine(BasedSequence line, int eolLength) {
if (nextIsSeparatorLine) {
nextIsSeparatorLine = false;
separatorLine = line;
separatorLineNumber = rowLines.size();
rowLines.add(line);
} else {
rowLines.add(line);
separatorLineNumber = content.getLineCount();
}
content.add(line, eolLength);
}

@Override
public void closeBlock(ParserState parserState) {
block.setCharsFromContent();
block.setContent(content);
}

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

int rowNumber = 0;
int headerColumns = -1;
for (BasedSequence rowLine : rowLines) {
int separatorColumns = alignments.size();

for (BasedSequence rowLine : content.getLines()) {
if (rowNumber == separatorLineNumber) {
section.setCharsFromContent();
section = new TableSeparator();
Expand All @@ -88,23 +87,15 @@ public void parseInlines(InlineParser inlineParser) {
}

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

int rowCells = countCells(cells);
int maxColumns = rowCells;

if (rowNumber < separatorLineNumber || headerColumns == -1) {
if (headerColumns == -1) {
headerColumns = rowCells;
} else if (headerColumns < rowCells) {
headerColumns = rowCells;
}
}

if (bodyColumnsTruncatedToHead && maxColumns > headerColumns) maxColumns = headerColumns;
if (bodyColumnsTruncatedToHead && maxColumns > separatorColumns) maxColumns = separatorColumns;
if (rowNumber >= separatorLineNumber) {
if (!bodyColumnsFilledToHead && rowCells < maxColumns) maxColumns = rowCells;
else if (bodyColumnsFilledToHead && maxColumns < headerColumns) maxColumns = headerColumns;
else if (bodyColumnsFilledToHead && maxColumns < separatorColumns) maxColumns = separatorColumns;
}

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

if (line.startsWith("|")) {
segments.add(line.subSequence(0, 1));
//segments.add(line.subSequence(0, 1));
line = line.subSequence(1, lineLength);
lineLength--;
}
Expand All @@ -207,7 +198,7 @@ private static List<BasedSequence> split(BasedSequence input) {
break;
case '|':
segments.add(line.subSequence(lastPos, i));
segments.add(line.subSequence(i, i + 1));
//segments.add(line.subSequence(i, i + 1));
lastPos = i + 1;
cellChars = 0;
break;
Expand Down Expand Up @@ -248,7 +239,11 @@ public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockPar
List<BasedSequence> headParts = split(paragraph);
List<BasedSequence> separatorParts = split(separatorLine);
if (separatorParts.size() >= headParts.size()) {
return BlockStart.of(new TableBlockParser(paragraph))
TableBlockParser tableBlockParser = new TableBlockParser();
tableBlockParser.addLine(paragraph, matchedBlockParser.getParagraphEolLengths().get(0));
tableBlockParser.nextIsSeparatorLine = true;

return BlockStart.of(tableBlockParser)
.atIndex(state.getIndex())
.replaceActiveBlockParser();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void renderBlock(TableBlock tableBlock) {
}

private void renderHead(TableHead tableHead) {
html.withAttr().tagIndent("thead", () -> {
html.withAttr().withCondLine().tagIndent("thead", () -> {
context.renderChildren(tableHead);
});
}
Expand All @@ -66,7 +66,7 @@ private void renderSeparator(TableSeparator tableSeparator) {
}

private void renderBody(TableBody tableBody) {
html.withAttr().tagIndent("tbody", () -> {
html.withAttr().withCondLine().tagIndent("tbody", () -> {
context.renderChildren(tableBody);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@org.junit.runner.RunWith(Suite.class)
@Suite.SuiteClasses({
//TablesTest.class,
TablesTest.class,
TablesFullSpecTest.class,
TablesSpecTest.class
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public void setAttributes(Node node, String tag, Map<String, String> attributes)
}
}
};

HtmlRenderer renderer = HtmlRenderer.builder()
.attributeProvider(attributeProvider)
.extensions(EXTENSIONS)
.build();

String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2"));
assertThat(rendered, is("<table test=\"block\">\n" +
"<thead test=\"head\">\n" +
Expand Down
Loading

0 comments on commit fe5f996

Please sign in to comment.