diff --git a/.changeset/honest-seahorses-whisper.md b/.changeset/honest-seahorses-whisper.md
new file mode 100644
index 000000000..26907e370
--- /dev/null
+++ b/.changeset/honest-seahorses-whisper.md
@@ -0,0 +1,5 @@
+---
+'@keystatic/core': patch
+---
+
+Support ordered lists that don't start at 1 in `fields.markdoc` and `fields.mdx`
diff --git a/packages/keystatic/src/form/fields/markdoc/editor/inputrules/rules.ts b/packages/keystatic/src/form/fields/markdoc/editor/inputrules/rules.ts
index ba7d13f68..53669f647 100644
--- a/packages/keystatic/src/form/fields/markdoc/editor/inputrules/rules.ts
+++ b/packages/keystatic/src/form/fields/markdoc/editor/inputrules/rules.ts
@@ -28,8 +28,10 @@ export function inputRulesForSchema({ nodes, marks, config }: EditorSchema) {
}
if (nodes.ordered_list) {
rules.push({
- pattern: /^\s*\d+(?:\.|\))\s$/,
- handler: wrappingInputRuleHandler(nodes.ordered_list),
+ pattern: /^\s*(\d+)(?:\.|\))\s$/,
+ handler: wrappingInputRuleHandler(nodes.ordered_list, match => ({
+ start: parseInt(match[1], 10),
+ })),
});
}
if (nodes.unordered_list) {
diff --git a/packages/keystatic/src/form/fields/markdoc/editor/markdoc/parse.ts b/packages/keystatic/src/form/fields/markdoc/editor/markdoc/parse.ts
index e0bcd2cba..6e6f67b25 100644
--- a/packages/keystatic/src/form/fields/markdoc/editor/markdoc/parse.ts
+++ b/packages/keystatic/src/form/fields/markdoc/editor/markdoc/parse.ts
@@ -297,7 +297,13 @@ function markdocNodeToProseMirrorNode(
? schema.nodes.ordered_list
: schema.nodes.unordered_list;
if (!listType) return notAllowed(node, parentType);
- return createAndFill(node, listType, {});
+ return createAndFill(
+ node,
+ listType,
+ node.attributes.ordered && node.attributes.start !== undefined
+ ? { start: node.attributes.start }
+ : {}
+ );
}
if (node.type === 'table') {
if (!schema.nodes.table) return notAllowed(node, parentType);
diff --git a/packages/keystatic/src/form/fields/markdoc/editor/markdoc/serialize.ts b/packages/keystatic/src/form/fields/markdoc/editor/markdoc/serialize.ts
index bec3f9d19..3831248fd 100644
--- a/packages/keystatic/src/form/fields/markdoc/editor/markdoc/serialize.ts
+++ b/packages/keystatic/src/form/fields/markdoc/editor/markdoc/serialize.ts
@@ -244,7 +244,11 @@ export function proseMirrorToMarkdoc(
return new Ast.Node('item', {}, listItemContent);
}
if (node.type === schema.nodes.ordered_list) {
- return new Ast.Node('list', { ordered: true }, blocks(node.content));
+ return new Ast.Node(
+ 'list',
+ { ordered: true, start: node.attrs.start },
+ blocks(node.content)
+ );
}
if (node.type === schema.nodes.unordered_list) {
return new Ast.Node('list', { ordered: false }, blocks(node.content));
diff --git a/packages/keystatic/src/form/fields/markdoc/editor/mdx/parse.ts b/packages/keystatic/src/form/fields/markdoc/editor/mdx/parse.ts
index ebf38f1b6..13456fc96 100644
--- a/packages/keystatic/src/form/fields/markdoc/editor/mdx/parse.ts
+++ b/packages/keystatic/src/form/fields/markdoc/editor/mdx/parse.ts
@@ -318,7 +318,11 @@ function markdocNodeToProseMirrorNode(
? schema.nodes.ordered_list
: schema.nodes.unordered_list;
if (!listType) return notAllowed(node, parentType);
- return createAndFill(node, listType, {});
+ return createAndFill(
+ node,
+ listType,
+ node.ordered && node.start != null ? { start: node.start } : {}
+ );
}
if (node.type === 'table') {
if (!schema.nodes.table) return notAllowed(node, parentType);
diff --git a/packages/keystatic/src/form/fields/markdoc/editor/mdx/serialize.ts b/packages/keystatic/src/form/fields/markdoc/editor/mdx/serialize.ts
index 988aff370..b596fdcec 100644
--- a/packages/keystatic/src/form/fields/markdoc/editor/mdx/serialize.ts
+++ b/packages/keystatic/src/form/fields/markdoc/editor/mdx/serialize.ts
@@ -249,6 +249,7 @@ function proseMirrorToMDX(
type: 'list',
ordered: true,
spread: false,
+ start: node.attrs.start,
children: mapContent(node, node => convertListItem(blocks(node.content))),
};
}
diff --git a/packages/keystatic/src/form/fields/markdoc/editor/schema.tsx b/packages/keystatic/src/form/fields/markdoc/editor/schema.tsx
index 7c69f981e..cf5fc8c08 100644
--- a/packages/keystatic/src/form/fields/markdoc/editor/schema.tsx
+++ b/packages/keystatic/src/form/fields/markdoc/editor/schema.tsx
@@ -221,9 +221,26 @@ const nodeSpecs = {
ordered_list: {
content: 'list_item+',
group: 'block',
- parseDOM: [{ tag: 'ol' }],
- toDOM() {
- return olDOM;
+ attrs: {
+ start: { default: 1 },
+ },
+ parseDOM: [
+ {
+ tag: 'ol',
+ getAttrs: node => {
+ if (typeof node === 'string') {
+ return false;
+ }
+ if (!(node instanceof HTMLOListElement) || node.start < 0) {
+ return { start: 1 };
+ }
+ return { start: node.start };
+ },
+ },
+ ],
+ toDOM(node) {
+ if (node.attrs.start === 1) return olDOM;
+ return ['ol', { start: node.attrs.start }, 0];
},
insertMenu: {
label: 'Ordered list',
diff --git a/packages/keystatic/src/form/fields/markdoc/editor/tests/lists.test.tsx b/packages/keystatic/src/form/fields/markdoc/editor/tests/lists.test.tsx
index a5e1a5e19..9491f7064 100644
--- a/packages/keystatic/src/form/fields/markdoc/editor/tests/lists.test.tsx
+++ b/packages/keystatic/src/form/fields/markdoc/editor/tests/lists.test.tsx
@@ -19,7 +19,37 @@ test('ordered list shortcut', async () => {
await user.keyboard(' ');
expect(state()).toMatchInlineSnapshot(`