Skip to content

Build your personal knowledge base with Trilium Notes

Don't render table outline if it contains only one cell, or no cell at all

Laurent Cozic11225771b657
diff --git a/src/tables.js b/src/tables.js
index f60d5dd777..980ed1e3d6 100644
--- a/src/tables.js
+++ b/src/tables.js
@@ -5,7 +5,7 @@ var rules = {}
rules.tableCell = {
filter: ['th', 'td'],
replacement: function (content, node) {
- if (nodeContainsTable(nodeParentTable(node))) return content;
+ if (tableShouldBeSkipped(nodeParentTable(node))) return content;
return cell(content, node)
}
}
@@ -14,7 +14,7 @@ rules.tableRow = {
filter: 'tr',
replacement: function (content, node) {
const parentTable = nodeParentTable(node);
- if (nodeContainsTable(parentTable)) return content;
+ if (tableShouldBeSkipped(parentTable)) return content;
var borderCells = ''
var alignMap = { left: ':--', right: '--:', center: ':-:' }
@@ -47,7 +47,7 @@ rules.table = {
},
replacement: function (content, node) {
- if (nodeContainsTable(node)) return content;
+ if (tableShouldBeSkipped(node)) return content;
// 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
@@ -121,6 +121,16 @@ function nodeContainsTable(node) {
return false;
}
+// Various conditions under which a table should be skipped - i.e. each cell
+// will be rendered one after the other as if they were paragraphs.
+function tableShouldBeSkipped(tableNode) {
+ if (!tableNode) return true;
+ if (!tableNode.rows) return true;
+ if (tableNode.rows.length <= 1 && tableNode.rows[0].childNodes.length <= 1) return true; // Table with only one cell
+ if (nodeContainsTable(tableNode)) return true;
+ return false;
+}
+
function nodeParentTable(node) {
let parent = node.parentNode;
while (parent.nodeName !== 'TABLE') {