Persist list indexes when editing
Signed-off-by: Tulir Asokan <tulir@maunium.net>
This commit is contained in:
parent
29367766fd
commit
a95f7be22d
1 changed files with 11 additions and 3 deletions
|
@ -108,7 +108,9 @@ function parseElement(n, partCreator, lastNode, state) {
|
||||||
case "LI": {
|
case "LI": {
|
||||||
const indent = " ".repeat(state.listDepth - 1);
|
const indent = " ".repeat(state.listDepth - 1);
|
||||||
if (n.parentElement.nodeName === "OL") {
|
if (n.parentElement.nodeName === "OL") {
|
||||||
return partCreator.plain(`${indent}1. `);
|
// The markdown parser doesn't do nested indexed lists at all, but this supports it anyway.
|
||||||
|
let index = state.listIndex[state.listIndex.length - 1]++;
|
||||||
|
return partCreator.plain(`${indent}${index}. `);
|
||||||
} else {
|
} else {
|
||||||
return partCreator.plain(`${indent}- `);
|
return partCreator.plain(`${indent}- `);
|
||||||
}
|
}
|
||||||
|
@ -120,9 +122,11 @@ function parseElement(n, partCreator, lastNode, state) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "OL":
|
case "OL":
|
||||||
|
state.listIndex.push(n.start || 1);
|
||||||
|
// fallthrough
|
||||||
case "UL":
|
case "UL":
|
||||||
state.listDepth = (state.listDepth || 0) + 1;
|
state.listDepth = (state.listDepth || 0) + 1;
|
||||||
// es-lint-disable-next-line no-fallthrough
|
// fallthrough
|
||||||
default:
|
default:
|
||||||
// don't textify block nodes we'll descend into
|
// don't textify block nodes we'll descend into
|
||||||
if (!checkDescendInto(n)) {
|
if (!checkDescendInto(n)) {
|
||||||
|
@ -177,7 +181,9 @@ function parseHtmlMessage(html, partCreator, isQuotedMessage) {
|
||||||
const parts = [];
|
const parts = [];
|
||||||
let lastNode;
|
let lastNode;
|
||||||
let inQuote = isQuotedMessage;
|
let inQuote = isQuotedMessage;
|
||||||
const state = {};
|
const state = {
|
||||||
|
listIndex: [],
|
||||||
|
};
|
||||||
|
|
||||||
function onNodeEnter(n) {
|
function onNodeEnter(n) {
|
||||||
if (checkIgnored(n)) {
|
if (checkIgnored(n)) {
|
||||||
|
@ -228,6 +234,8 @@ function parseHtmlMessage(html, partCreator, isQuotedMessage) {
|
||||||
inQuote = false;
|
inQuote = false;
|
||||||
break;
|
break;
|
||||||
case "OL":
|
case "OL":
|
||||||
|
state.listIndex.pop();
|
||||||
|
// fallthrough
|
||||||
case "UL":
|
case "UL":
|
||||||
state.listDepth -= 1;
|
state.listDepth -= 1;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue