From 2750ff6269a33b31c22c1505fb65fc47bd112f8f Mon Sep 17 00:00:00 2001 From: mbracke Date: Mon, 5 May 2025 13:29:06 +0200 Subject: [PATCH 1/2] add test for HTML table with colspan 0 --- .../resources/flexmark_html_converter_spec.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md b/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md index eff2e6781..0ebe980d4 100644 --- a/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md +++ b/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md @@ -3010,6 +3010,25 @@ tables with row span cells ```````````````````````````````` +table where some rows end with colspan 0 + +```````````````````````````````` example Tables: 51 +| Abc | Def | +|---------|-----| +| no span | span + +. + + + + + + + +
AbcDef
no spanspan
+```````````````````````````````` + + ## Definition Lists a definition in a block quote From d9eda5dcf360ce2d8b4c451adeb41b0ac93d00ee Mon Sep 17 00:00:00 2001 From: mbracke Date: Mon, 5 May 2025 13:23:33 +0200 Subject: [PATCH 2/2] avoid counting table column with span 0 as 0 columns This fixes a bug where all rows of an HTML table ending with colspan 0 led to index out of bounds exceptions. --- .../resources/flexmark_html_converter_spec.md | 19 +++++++++++++++++++ .../flexmark/util/format/TableRow.java | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md b/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md index 0ebe980d4..9537c9910 100644 --- a/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md +++ b/flexmark-html2md-converter/src/test/resources/flexmark_html_converter_spec.md @@ -3029,6 +3029,25 @@ table where some rows end with colspan 0 ```````````````````````````````` +table where all rows end with colspan 0 + +```````````````````````````````` example Tables: 52 +| Abc | Def +|---------|-----| +| no span | span + +. + + + + + + + +
AbcDef
no spanspan
+```````````````````````````````` + + ## Definition Lists a definition in a block quote diff --git a/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/TableRow.java b/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/TableRow.java index 6a6d7f4bd..00d6ae114 100644 --- a/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/TableRow.java +++ b/flexmark-util-format/src/main/java/com/vladsch/flexmark/util/format/TableRow.java @@ -6,6 +6,7 @@ import java.util.List; import static com.vladsch.flexmark.util.format.TableCellManipulator.BREAK; +import static com.vladsch.flexmark.util.misc.Utils.max; import static com.vladsch.flexmark.util.misc.Utils.maxLimit; import static com.vladsch.flexmark.util.misc.Utils.minLimit; @@ -97,7 +98,7 @@ public int getSpannedColumns() { int columns = 0; for (TableCell cell : cells) { if (cell == null) continue; - columns += cell.columnSpan; + columns += max(cell.columnSpan, 1); } return columns; }