Fix list formatting alternating on edit (#7422)

Co-authored-by: Andy Balaam <andyb@element.io>
This commit is contained in:
Renan Cleyson 2021-12-21 07:07:44 -03:00 committed by GitHub
parent 8b2a478a25
commit 9ac85bcaa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View file

@ -242,7 +242,19 @@ function parseHtmlMessage(html: string, partCreator: PartCreator, isQuotedMessag
}
if (n.nodeType === Node.TEXT_NODE) {
newParts.push(...parseAtRoomMentions(n.nodeValue, partCreator));
let { nodeValue } = n;
// Sometimes commonmark adds a newline at the end of the list item text
if (n.parentNode.nodeName === "LI") {
nodeValue = nodeValue.trimEnd();
}
newParts.push(...parseAtRoomMentions(nodeValue, partCreator));
const grandParent = n.parentNode.parentNode;
const isTight = n.parentNode.nodeName !== "P" || grandParent?.nodeName !== "LI";
if (!isTight) {
newParts.push(partCreator.newline());
}
} else if (n.nodeType === Node.ELEMENT_NODE) {
const parseResult = parseElement(n, partCreator, lastNode, state);
if (parseResult) {