Skip to content

Build your personal knowledge base with Trilium Notes

Fixed handling of tables with empty headers

Laurent Cozic1452200c79f7
diff --git a/build_for_test.sh b/build_for_test.sh
new file mode 100644
index 0000000000..3283e1c5de
--- /dev/null
+++ b/build_for_test.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+ROOT_DIR=/mnt/d/Web/www/joplin
+CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+set -e
+npm run build
+# rsync -a ./dist/ $ROOT_DIR/ElectronClient/app/node_modules/joplin-turndown-plugin-gfm/dist/
+# rsync -a ./lib/ $ROOT_DIR/ElectronClient/app/node_modules/joplin-turndown-plugin-gfm/lib/
+rm -rf $ROOT_DIR/CliClient/node_modules/joplin-turndown-plugin-gfm
+ln -s "$CURRENT_DIR" $ROOT_DIR/CliClient/node_modules/joplin-turndown-plugin-gfm
+$ROOT_DIR/CliClient/run_test.sh HtmlToMd
\ No newline at end of file
diff --git a/src/tables.js b/src/tables.js
index 980ed1e3d6..b76d87255b 100644
--- a/src/tables.js
+++ b/src/tables.js
@@ -49,16 +49,20 @@ rules.table = {
replacement: function (content, node) {
if (tableShouldBeSkipped(node)) return content;
+ // Ensure there are no blank lines
+ content = content.replace(/\n+/g, '\n')
+
// If table has no heading, add an empty one so as to get a valid Markdown table
- var firstRow = node.rows.length ? node.rows[0] : null
- var columnCount = tableColCount(node); //firstRow ? firstRow.childNodes.length : 0
+ var secondLine = content.split('\n');
+ if (secondLine.length >= 2) secondLine = secondLine[1]
+ var secondLineIsDivider = secondLine.indexOf('| ---') === 0
+
+ var columnCount = tableColCount(node);
var emptyHeader = ''
- if (columnCount && !isHeadingRow(firstRow)) {
+ if (columnCount && !secondLineIsDivider) {
emptyHeader = '|' + ' |'.repeat(columnCount) + '\n' + '|' + ' --- |'.repeat(columnCount)
}
- // Ensure there are no blank lines
- content = content.replace(/\n+/g, '\n')
return '\n\n' + emptyHeader + content + '\n\n'
}
}