1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Desktop: Fixes #9586: Fix code blocks with blank lines break tables in the rich text editor (#9587)

This commit is contained in:
Henry Heino 2023-12-24 06:56:08 -08:00 committed by GitHub
parent 02232c0ca3
commit c623d98bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View File

@ -0,0 +1,31 @@
<div id="rendered-md">
<table class="jop-noMdConv">
<thead class="jop-noMdConv">
<tr class="jop-noMdConv">
<th class="jop-noMdConv">Code</th>
<th class="jop-noMdConv">Description</th>
</tr>
<tr class="jop-noMdConv">
<td class="jop-noMdConv">
<pre class="jop-noMdConv"><code class="jop-noMdConv">const test = "hello";
// Another line
console.log('Test...');
// Blank lines
// Should not break things.</code></pre>
</td>
<td class="jop-noMdConv">abcda</td>
</tr>
<tr class="jop-noMdConv">
<td class="jop-noMdConv">
<pre class="jop-noMdConv"><code class="jop-noMdConv">const test = "hello";</code></pre>
</td>
<td class="jop-noMdConv">abcd</td>
</tr>
</thead>
</table>
</div>

View File

@ -0,0 +1,10 @@
<table class="jop-noMdConv"><thead class="jop-noMdConv"><tr class="jop-noMdConv"><th class="jop-noMdConv">Code</th><th class="jop-noMdConv">Description</th></tr><tr class="jop-noMdConv"><td class="jop-noMdConv"><pre class="jop-noMdConv"><code class="">const test = "hello";
<!-- -->
// Another line
console.log('Test...');
<!-- -->
// Blank lines
<!-- -->
<!-- -->
<!-- -->
// Should not break things.</code></pre></td><td class="jop-noMdConv">abcda</td></tr><tr class="jop-noMdConv"><td class="jop-noMdConv"><pre class="jop-noMdConv"><code class="">const test = "hello";</code></pre></td><td class="jop-noMdConv">abcd</td></tr></thead></table>

View File

@ -44,7 +44,21 @@ export default function TurndownService (options) {
return node.isBlock ? '\n\n' : ''
},
keepReplacement: function (content, node) {
return node.isBlock ? '\n\n' + node.outerHTML + '\n\n' : node.outerHTML
// In markdown, multiple blank lines end an HTML block. We thus
// include an HTML comment to make otherwise blank lines not blank.
const mutliBlankLineRegex = /\n([ \t\r]*)\n/g;
// We run the replacement multiple times to handle multiple blank
// lines in a row.
//
// For example, "Foo\n\n\nBar" becomes "Foo\n<!-- -->\n\nBar" after the
// first replacement.
let html = node.outerHTML;
while (html.match(mutliBlankLineRegex)) {
html = html.replace(mutliBlankLineRegex, '\n<!-- -->$1\n');
}
return node.isBlock ? '\n\n' + html + '\n\n' : html
},
defaultReplacement: function (content, node) {
return node.isBlock ? '\n\n' + content + '\n\n' : content