diff --git a/src/tables.js b/src/tables.js index 39318c3c8..e4fd987af 100644 --- a/src/tables.js +++ b/src/tables.js @@ -32,7 +32,12 @@ rules.tableRow = { } rules.table = { - filter: 'table', + // Only convert tables with a heading row. + // Tables with no heading row are kept using `keep` (see below). + filter: function (node) { + return node.nodeName === 'TABLE' && isHeadingRow(node.rows[0]) + }, + replacement: function (content) { // Ensure there are no blank lines content = content.replace('\n\n', '\n') @@ -85,5 +90,8 @@ function cell (content, node) { } export default function tables (turndownService) { + turndownService.keep(function (node) { + return node.nodeName === 'TABLE' && !isHeadingRow(node.rows[0]) + }) for (var key in rules) turndownService.addRule(key, rules[key]) } diff --git a/test/index.html b/test/index.html index 885f738f0..f14088f61 100644 --- a/test/index.html +++ b/test/index.html @@ -151,6 +151,10 @@
+ + + + @@ -167,7 +171,9 @@
Heading 1Heading 2
Row 1
-
| Row 1 | Row 1 |
+
| Heading 1 | Heading 2 |
+| --- | --- |
+| Row 1 | Row 1 |
 | Row 3 | Row 3 |
@@ -233,23 +239,6 @@ | Content | -
-
- - - - - - - - - -
HeadingNot a heading
HeadingNot a heading
-
-
| Heading | Not a heading |
-| Heading | Not a heading |
-
-
@@ -273,6 +262,32 @@ | --- | +
+
+
+ + +
Row 1 Cell 1Row 1 Cell 2
Row 2 Cell 1Row 2 Cell 2
+
+
<table><tbody><tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr></tbody></table>
+
+ +
+
+ + + + + + + + + +
HeadingNot a heading
HeadingNot a heading
+
+
<table><tbody><tr><th>Heading</th><td>Not a heading</td></tr><tr><td>Heading</td><td>Not a heading</td></tr></tbody></table>
+
+