Skip to content

Commit

Permalink
[#56779] Allow empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
as-op committed Sep 4, 2024
1 parent c4813fb commit 058f24b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/commonmark/commonmarkdataprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ export default class CommonMarkDataProcessor {
return node.nodeName === 'FIGURE' && tables.length;
},
replacement: function (_content, node) {
// Remove filler nodes
node.querySelectorAll('td br[data-cke-filler]')
.forEach((node) => node.remove());
node.querySelectorAll('td p.op-uc-p')
.forEach((node) => {
if (node.childNodes.length === 0) {
node.parentElement.insertBefore(document.createElement("br"), node);
node.remove();
}
});

return node.outerHTML;
}
Expand Down Expand Up @@ -189,6 +193,15 @@ export default class CommonMarkDataProcessor {
replacement: ( _content, node ) => node.outerHTML,
});

turndownService.addRule( 'emptyLines', {
filter: (node) => {
console.log(node);
return (node.nodeName === 'BR') ||
(node.nodeName === 'P' && node.childNodes.length === 1 && node.childNodes[0].nodeName === 'BR');
},
replacement: ( _content, node ) => "<br>",
});

let turndown = turndownService.turndown( domFragment );
// Escape non-breaking space characters
return turndown.replace(/\u00A0/, '&nbsp;');
Expand Down

0 comments on commit 058f24b

Please sign in to comment.