diff --git a/packages/app-cli/tests/html_to_md/table_with_caption.html b/packages/app-cli/tests/html_to_md/table_with_caption.html
new file mode 100644
index 000000000..0047f9549
--- /dev/null
+++ b/packages/app-cli/tests/html_to_md/table_with_caption.html
@@ -0,0 +1,15 @@
+
+ Caption
+
+
+ Row 1, Column 1 |
+ Row 1, Column 2 |
+ Row 1, Column 3 |
+
+
+ Row 2, Column 1 |
+ Row 2, Column 2 |
+ Row 2, Column 3 |
+
+
+
\ No newline at end of file
diff --git a/packages/app-cli/tests/html_to_md/table_with_caption.md b/packages/app-cli/tests/html_to_md/table_with_caption.md
new file mode 100644
index 000000000..99e085ccf
--- /dev/null
+++ b/packages/app-cli/tests/html_to_md/table_with_caption.md
@@ -0,0 +1,6 @@
+Caption
+
+| | | |
+| --- | --- | --- |
+| Row 1, Column 1 | Row 1, Column 2 | Row 1, Column 3 |
+| Row 2, Column 1 | Row 2, Column 2 | Row 2, Column 3 |
\ No newline at end of file
diff --git a/packages/app-cli/tests/html_to_md/table_with_colgroup.html b/packages/app-cli/tests/html_to_md/table_with_colgroup.html
new file mode 100644
index 000000000..2f0ff5d91
--- /dev/null
+++ b/packages/app-cli/tests/html_to_md/table_with_colgroup.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+ Row 1, Column 1 |
+ Row 1, Column 2 |
+ Row 1, Column 3 |
+
+
+ Row 2, Column 1 |
+ Row 2, Column 2 |
+ Row 2, Column 3 |
+
+
+
\ No newline at end of file
diff --git a/packages/app-cli/tests/html_to_md/table_with_colgroup.md b/packages/app-cli/tests/html_to_md/table_with_colgroup.md
new file mode 100644
index 000000000..befad14cf
--- /dev/null
+++ b/packages/app-cli/tests/html_to_md/table_with_colgroup.md
@@ -0,0 +1,4 @@
+| | | |
+| --- | --- | --- |
+| Row 1, Column 1 | Row 1, Column 2 | Row 1, Column 3 |
+| Row 2, Column 1 | Row 2, Column 2 | Row 2, Column 3 |
\ No newline at end of file
diff --git a/packages/turndown-plugin-gfm/src/tables.js b/packages/turndown-plugin-gfm/src/tables.js
index 0df0116d1..1492211f5 100644
--- a/packages/turndown-plugin-gfm/src/tables.js
+++ b/packages/turndown-plugin-gfm/src/tables.js
@@ -98,10 +98,23 @@ rules.table = {
}
}
- return '\n\n' + emptyHeader + content + '\n\n'
+ const captionContent = node.caption ? node.caption.textContent || '' : '';
+ const caption = captionContent ? `${captionContent}\n\n` : '';
+ const tableContent = `${emptyHeader}${content}`.trimStart();
+ return `\n\n${caption}${tableContent}\n\n`;
}
}
+rules.tableCaption = {
+ filter: ['caption'],
+ replacement: () => '',
+};
+
+rules.tableColgroup = {
+ filter: ['colgroup', 'col'],
+ replacement: () => '',
+};
+
rules.tableSection = {
filter: ['thead', 'tbody', 'tfoot'],
replacement: function (content) {