add extra newline before P tags (when not first node)

This commit is contained in:
Bruno Windels 2019-09-23 15:06:22 +02:00
parent 0a663398ed
commit 2445421270

View File

@ -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);