1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #9543: Fix nested tables not preserved in rich text editor (#9579)

This commit is contained in:
Henry Heino 2023-12-22 01:27:20 -08:00 committed by GitHub
parent d4157e14fe
commit 144ec1eea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -1,10 +1,10 @@
<body>
<table border="5px" bordercolor="#8707B0">
<table>
<tr>
<td>Left side of the main table</td>
<td>
<table border="5px" bordercolor="#F35557">
<h4 align="center">Nested Table</h4>
<table>
<b>Nested Table</b>
<tr>
<td>nested table C1</td>
<td>nested table C2</td>

View File

@ -1 +1 @@
<table border="5px" bordercolor="#8707B0"><tbody><tr><td>Left side of the main table</td><td><h4 align="center">Nested Table</h4><table border="5px" bordercolor="#F35557"><tbody><tr><td>nested table C1</td><td>nested table C2</td></tr><tr><td>nested table</td><td>nested table</td></tr></tbody></table></td></tr></tbody></table>
<table><tbody><tr><td>Left side of the main table</td><td><b>Nested Table</b><table><tbody><tr><td>nested table C1</td><td>nested table C2</td></tr><tr><td>nested table</td><td>nested table</td></tr></tbody></table></td></tr></tbody></table>

View File

@ -74,8 +74,8 @@ rules.tableRow = {
rules.table = {
// Only convert tables that can result in valid Markdown
// Other tables are kept as HTML using `keep` (see below).
filter: function (node) {
return node.nodeName === 'TABLE' && !tableShouldBeHtml(node);
filter: function (node, options) {
return node.nodeName === 'TABLE' && !tableShouldBeHtml(node, options);
},
replacement: function (content, node) {
@ -174,7 +174,7 @@ const nodeContains = (node, types) => {
return false;
}
const tableShouldBeHtml = (tableNode, preserveNestedTables) => {
const tableShouldBeHtml = (tableNode, options) => {
const possibleTags = [
'UL',
'OL',
@ -193,7 +193,7 @@ const tableShouldBeHtml = (tableNode, preserveNestedTables) => {
// that's made of HTML tables. In that case we have this logic of removing the
// outer table and keeping only the inner ones. For the Rich Text editor
// however we always want to keep nested tables.
if (preserveNestedTables) possibleTags.push('TABLE');
if (options.preserveNestedTables) possibleTags.push('TABLE');
return nodeContains(tableNode, 'code') ||
nodeContains(tableNode, possibleTags);
@ -249,7 +249,7 @@ export default function tables (turndownService) {
isCodeBlock_ = turndownService.isCodeBlock;
turndownService.keep(function (node) {
if (node.nodeName === 'TABLE' && tableShouldBeHtml(node, turndownService.options.preserveNestedTables)) return true;
if (node.nodeName === 'TABLE' && tableShouldBeHtml(node, turndownService.options)) return true;
return false;
});
for (var key in rules) turndownService.addRule(key, rules[key])