mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 21:24:59 +08:00
Merge pull request #3128 from matrix-org/bwindels/edit-nested-lists
Fix: take list nesting into account for indenting
This commit is contained in:
commit
701e18d588
@ -70,7 +70,7 @@ function parseCodeBlock(n, partCreator) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
function parseElement(n, partCreator) {
|
||||
function parseElement(n, partCreator, state) {
|
||||
switch (n.nodeName) {
|
||||
case "A":
|
||||
return parseLink(n, partCreator);
|
||||
@ -86,12 +86,18 @@ function parseElement(n, partCreator) {
|
||||
return partCreator.plain(`\`${n.textContent}\``);
|
||||
case "DEL":
|
||||
return partCreator.plain(`<del>${n.textContent}</del>`);
|
||||
case "LI":
|
||||
case "LI": {
|
||||
const indent = " ".repeat(state.listDepth - 1);
|
||||
if (n.parentElement.nodeName === "OL") {
|
||||
return partCreator.plain(` 1. `);
|
||||
return partCreator.plain(`${indent}1. `);
|
||||
} else {
|
||||
return partCreator.plain(` - `);
|
||||
return partCreator.plain(`${indent}- `);
|
||||
}
|
||||
}
|
||||
case "OL":
|
||||
case "UL":
|
||||
state.listDepth = (state.listDepth || 0) + 1;
|
||||
// es-lint-disable-next-line no-fallthrough
|
||||
default:
|
||||
// don't textify block nodes we'll decend into
|
||||
if (!checkDecendInto(n)) {
|
||||
@ -161,6 +167,7 @@ function parseHtmlMessage(html, partCreator) {
|
||||
const parts = [];
|
||||
let lastNode;
|
||||
let inQuote = false;
|
||||
const state = {};
|
||||
|
||||
function onNodeEnter(n) {
|
||||
if (checkIgnored(n)) {
|
||||
@ -178,7 +185,7 @@ function parseHtmlMessage(html, partCreator) {
|
||||
if (n.nodeType === Node.TEXT_NODE) {
|
||||
newParts.push(...parseAtRoomMentions(n.nodeValue, partCreator));
|
||||
} else if (n.nodeType === Node.ELEMENT_NODE) {
|
||||
const parseResult = parseElement(n, partCreator);
|
||||
const parseResult = parseElement(n, partCreator, state);
|
||||
if (parseResult) {
|
||||
if (Array.isArray(parseResult)) {
|
||||
newParts.push(...parseResult);
|
||||
@ -207,8 +214,14 @@ function parseHtmlMessage(html, partCreator) {
|
||||
if (checkIgnored(n)) {
|
||||
return;
|
||||
}
|
||||
if (n.nodeName === "BLOCKQUOTE") {
|
||||
switch (n.nodeName) {
|
||||
case "BLOCKQUOTE":
|
||||
inQuote = false;
|
||||
break;
|
||||
case "OL":
|
||||
case "UL":
|
||||
state.listDepth -= 1;
|
||||
break;
|
||||
}
|
||||
lastNode = n;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user