From 24454212700a8aced8781177a9e416f8f89522df Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 23 Sep 2019 15:06:22 +0200 Subject: [PATCH] add extra newline before P tags (when not first node) --- src/editor/deserialize.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/editor/deserialize.js b/src/editor/deserialize.js index 1b99d70946..947ce30ce7 100644 --- a/src/editor/deserialize.js +++ b/src/editor/deserialize.js @@ -76,7 +76,7 @@ function parseHeader(el, partCreator) { return partCreator.plain("#".repeat(depth) + " "); } -function parseElement(n, partCreator, state) { +function parseElement(n, partCreator, lastNode, state) { switch (n.nodeName) { case "H1": case "H2": @@ -107,6 +107,12 @@ function parseElement(n, partCreator, state) { return partCreator.plain(`${indent}- `); } } + case "P": { + if (lastNode) { + return partCreator.newline(); + } + break; + } case "OL": case "UL": state.listDepth = (state.listDepth || 0) + 1; @@ -183,7 +189,7 @@ function parseHtmlMessage(html, partCreator, isQuotedMessage) { if (n.nodeType === Node.TEXT_NODE) { newParts.push(...parseAtRoomMentions(n.nodeValue, partCreator)); } else if (n.nodeType === Node.ELEMENT_NODE) { - const parseResult = parseElement(n, partCreator, state); + const parseResult = parseElement(n, partCreator, lastNode, state); if (parseResult) { if (Array.isArray(parseResult)) { newParts.push(...parseResult);