From 695c41c3d296e20bf5726a5422eb3c06f682c6b2 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 17:41:14 -0600 Subject: [PATCH 1/2] id(web): carry ordered-list delimiter style through codec - fix #1380 --- pkgs/id/src/web/markdown.rs | 94 +++++++++++++++++++++++++++++++++++-- pkgs/id/web/src/editor.ts | 12 ++++- 2 files changed, 100 insertions(+), 6 deletions(-) diff --git a/pkgs/id/src/web/markdown.rs b/pkgs/id/src/web/markdown.rs index 0b67862e56..bdc09354ac 100644 --- a/pkgs/id/src/web/markdown.rs +++ b/pkgs/id/src/web/markdown.rs @@ -31,7 +31,7 @@ //! - `link`: Hyperlink with `href` and `title` attributes //! - `strikethrough`: Strikethrough text (GFM `~~text~~`) -use comrak::nodes::{AstNode, ListType, NodeValue}; +use comrak::nodes::{AstNode, ListDelimType, ListType, NodeValue}; use comrak::{Arena, Options, format_commonmark, parse_document}; use serde_json::{Value, json}; @@ -3190,9 +3190,29 @@ fn is_end_list_separator<'a>(node: &'a AstNode<'a>) -> bool { /// so numbering renders unchanged; `tight` is carried from the source /// list to every run. Placement validation and the editor schema are /// untouched: every emitted list is pure. +/// #1380: the PM `delimiter` attr spelling for a comrak ordered-list +/// delimiter (`.` vs `)`). The editor schema mirrors these spellings. +fn delimiter_attr(delimiter: ListDelimType) -> &'static str { + match delimiter { + ListDelimType::Period => "period", + ListDelimType::Paren => "paren", + } +} + +/// #1380: read the PM `delimiter` attr back to a comrak delimiter. +/// Absent or unknown (legacy PM docs stored by the old codec, which +/// dropped the delimiter) defaults to Period - exactly how the old +/// codec saved every ordered list. +fn delimiter_from_attrs(json: &Value) -> ListDelimType { + match json["attrs"]["delimiter"].as_str() { + Some("paren") => ListDelimType::Paren, + _ => ListDelimType::Period, + } +} + fn convert_list_runs<'a>(node: &'a AstNode<'a>) -> Vec { - let (list_type, start, tight) = match &node.data.borrow().value { - NodeValue::List(list) => (list.list_type, list.start, list.tight), + let (list_type, start, tight, delimiter) = match &node.data.borrow().value { + NodeValue::List(list) => (list.list_type, list.start, list.tight, list.delimiter), _ => return Vec::new(), }; // (is_task, items before this run, converted items) @@ -3214,7 +3234,7 @@ fn convert_list_runs<'a>(node: &'a AstNode<'a>) -> Vec { .map(|(is_task, offset, content)| match (is_task, list_type) { (true, ListType::Ordered) => json!({ "type": "task_list", - "attrs": {"order": start + offset, "tight": tight}, + "attrs": {"order": start + offset, "tight": tight, "delimiter": delimiter_attr(delimiter)}, "content": content }), (true, ListType::Bullet) => json!({ @@ -3224,7 +3244,7 @@ fn convert_list_runs<'a>(node: &'a AstNode<'a>) -> Vec { }), (false, ListType::Ordered) => json!({ "type": "ordered_list", - "attrs": {"order": start + offset, "tight": tight}, + "attrs": {"order": start + offset, "tight": tight, "delimiter": delimiter_attr(delimiter)}, "content": content }), (false, ListType::Bullet) => json!({ @@ -4481,10 +4501,13 @@ fn json_to_ast<'a>(arena: &'a Arena<'a>, json: &Value) -> Result<&'a AstNode<'a> #[allow(clippy::cast_possible_truncation)] // order is typically small let order = json["attrs"]["order"].as_u64().unwrap_or(1) as usize; let tight = json["attrs"]["tight"].as_bool().unwrap_or(false); + // #1380: carry the delimiter style; absent (legacy docs) + // defaults to Period in delimiter_from_attrs. NodeValue::List(comrak::nodes::NodeList { list_type: ListType::Ordered, start: order, tight, + delimiter: delimiter_from_attrs(json), ..Default::default() }) } @@ -4516,6 +4539,8 @@ fn json_to_ast<'a>(arena: &'a Arena<'a>, json: &Value) -> Result<&'a AstNode<'a> list_type: ListType::Ordered, start, tight, + // #1380: same delimiter carry as ordered_list. + delimiter: delimiter_from_attrs(json), ..Default::default() }), None => NodeValue::List(comrak::nodes::NodeList { @@ -8702,6 +8727,65 @@ Some text assert_eq!(bullet["content"][0]["attrs"]["tight"], true); } + #[test] + fn test_ordered_list_paren_delimiter_roundtrips() { + // #1380: the ordered-list delimiter style (`1)` vs `1.`) must + // survive the codec in both directions instead of every list + // being rewritten with periods. + let doc = markdown_to_prosemirror("1) one\n2) two\n"); + let content = doc["content"].as_array().unwrap(); + assert_eq!(content[0]["type"], "ordered_list"); + assert_eq!(content[0]["attrs"]["delimiter"], "paren"); + + let (first, second) = two_saves("1) one\n2) two\n"); + assert_eq!(first, "1) one\n2) two\n", "paren round-trip changed bytes"); + assert_eq!(first, second, "no fixpoint for paren list"); + + // Period lists are unchanged and now carry the attr explicitly. + let doc = markdown_to_prosemirror("1. one\n2. two\n"); + assert_eq!(doc["content"][0]["attrs"]["delimiter"], "period"); + let (first, second) = two_saves("1. one\n2. two\n"); + assert_eq!(first, "1. one\n2. two\n"); + assert_eq!(first, second, "no fixpoint for period list"); + } + + #[test] + fn test_ordered_task_list_paren_delimiter_roundtrips() { + // #1380: ordered task lists keep their delimiter too. + let doc = markdown_to_prosemirror("1) [ ] todo\n2) [x] done\n"); + let content = doc["content"].as_array().unwrap(); + assert_eq!(content[0]["type"], "task_list"); + assert_eq!(content[0]["attrs"]["order"], 1); + assert_eq!(content[0]["attrs"]["delimiter"], "paren"); + + let (first, second) = two_saves("1) [ ] todo\n2) [x] done\n"); + assert_eq!(first, "1) [ ] todo\n2) [x] done\n"); + assert_eq!(first, second, "no fixpoint for paren task list"); + } + + #[test] + fn test_legacy_ordered_list_without_delimiter_attr_saves_period() { + // #1380: legacy PM docs stored by the old codec carry no + // delimiter attr; they must save exactly as today (period). + let doc = json!({ + "type": "doc", + "content": [{ + "type": "ordered_list", + "attrs": {"order": 1, "tight": true}, + "content": [ + {"type": "list_item", "content": [ + {"type": "paragraph", "content": [{"type": "text", "text": "one"}]} + ]}, + {"type": "list_item", "content": [ + {"type": "paragraph", "content": [{"type": "text", "text": "two"}]} + ]} + ] + }] + }); + let md = prosemirror_to_markdown(&doc).unwrap(); + assert_eq!(md, "1. one\n2. two\n", "legacy doc changed: {md:?}"); + } + #[test] fn test_task_list_mixed_content() { // Task list items with text content diff --git a/pkgs/id/web/src/editor.ts b/pkgs/id/web/src/editor.ts index 2caa724a86..fba95ed76a 100644 --- a/pkgs/id/web/src/editor.ts +++ b/pkgs/id/web/src/editor.ts @@ -150,6 +150,10 @@ export const richSchema = new Schema({ attrs: { order: { default: 1, validate: "number" }, tight: { default: true }, + // #1380: mirror the codec's delimiter attr ("period"/"paren", + // default period) so paren-style lists are not rewritten on + // save; undeclared, it was dropped on editor load. + delimiter: { default: "period" }, }, }) .update("image", { @@ -211,7 +215,13 @@ export const richSchema = new Schema({ // depends on it so multi-block task items do not fuse on save. // #997: ordered task lists carry their start in `order` (null for // bullet task lists), mirroring the markdown codec's attrs.order. - attrs: { tight: { default: true }, order: { default: null } }, + // #1380: ordered task lists also carry `delimiter`, mirroring + // the codec (default period, as in ordered_list above). + attrs: { + tight: { default: true }, + order: { default: null }, + delimiter: { default: "period" }, + }, parseDOM: [ { tag: "ul", From ecb7a49f8387eb40f48c0898c9e3141650b1c56f Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 20:32:09 -0600 Subject: [PATCH 2/2] test(id/web): expect delimiter default in ordered-list round-trip (#1380) Codex P2 on PR #4666: adding the delimiter attr with default period makes nodeFromJSON(...).toJSON() include delimiter: "period" when the input omits it, so the existing round-trip expectations comparing the full attrs object failed (verified: 2 failed before, 117 pass after). --- pkgs/id/web/src/editor.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/id/web/src/editor.test.ts b/pkgs/id/web/src/editor.test.ts index 1d57a6b32b..ec1d8a1c38 100644 --- a/pkgs/id/web/src/editor.test.ts +++ b/pkgs/id/web/src/editor.test.ts @@ -245,7 +245,9 @@ describe("richSchema list tight attrs (#1469)", () => { content: [{ type: "ordered_list", attrs: { order: 3, tight }, content: [item("a"), item("b")] }], }; const out = richSchema.nodeFromJSON(json).toJSON(); - expect(out.content[0].attrs).toEqual({ order: 3, tight }); + // #1380: the schema fills the delimiter default ("period") when the + // input omits it, so the round-tripped attrs carry it explicitly. + expect(out.content[0].attrs).toEqual({ order: 3, tight, delimiter: "period" }); expect(out.content[0].content).toEqual([item("a"), item("b")]); }); });