compose: Fix bug where extra line breaks were pasted between blocks.

Due to the way turndown pads every block element with 2 new lines, and
makes `br` double space by default, we would get 3 blank lines pasted
when there's just 1 line break between 2 paragraphs.

Now we set `br` to an empty string, and since turndown collapses
sequences of multiple new lines to `\n\n` (1 blank line), so any 2 block
elements will now always have 1 blank line between them, irrespective of
if and how many line breaks there are between them in the copied HTML.
This commit is contained in:
N-Shar-ma
2023-11-17 14:49:19 +05:30
committed by Tim Abbott
parent 34fcb3a393
commit 6bc9092786
2 changed files with 6 additions and 0 deletions

View File

@@ -337,6 +337,7 @@ export function paste_handler_converter(paste_html) {
emDelimiter: "*",
codeBlockStyle: "fenced",
headingStyle: "atx",
br: "",
});
turndownService.addRule("style", {
filter: "style",

View File

@@ -97,6 +97,11 @@ run_test("paste_handler_converter", () => {
"* bulleted\n* nested\n * nested level 1\n * nested level 1 continue\n * nested level 2\n * nested level 2 continue",
);
// 2 paragraphs with line break/s in between
input =
'<meta http-equiv="content-type" content="text/html; charset=utf-8"><p>paragraph 1</p><br><p>paragraph 2</p>';
assert.equal(copy_and_paste.paste_handler_converter(input), "paragraph 1\n\nparagraph 2");
// Pasting from external sources
// Pasting list from GitHub
input =