GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(id): keep a blank before ordered lists starting above 1 (#1397, C… · developing-today/code@cd4564a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkgs/id/src/web
    • markdown.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkgs/id/src/web/markdown.rs‎

Copy file name to clipboardExpand all lines: pkgs/id/src/web/markdown.rs
+51-9Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4529,8 +4529,9 @@ fn list_kind(node: &Value) -> Option<&str> {
45294529
/// the output is returned untouched.
45304530
fn strip_end_list_separators(doc: &Value, output: &str) -> String {
45314531
// Recompute with kinds: the drop decision needs them, so collect
4532-
// (prev_kind, kind, tight_pair, merge_safe) tuples alongside.
4533-
let mut kinds: Vec<(String, String, bool, bool)> = Vec::new();
4532+
// (prev_kind, kind, tight_pair, merge_safe, needs_blank) tuples
4533+
// alongside.
4534+
let mut kinds: Vec<(String, String, bool, bool, bool)> = Vec::new();
45344535
collect_boundary_kinds(doc, &mut kinds);
45354536
if kinds.is_empty() {
45364537
return output.to_string();
@@ -4581,16 +4582,21 @@ fn strip_end_list_separators(doc: &Value, output: &str) -> String {
45814582
let line = lines[idx];
45824583
if is_separator[idx] {
45834584
match boundary.next() {
4584-
Some((a, b, tight_pair, merge_safe)) if a != b && *merge_safe => {
4585+
Some((a, b, tight_pair, merge_safe, needs_blank)) if a != b && *merge_safe => {
45854586
// Drop the separator. The renderer also puts a blank
45864587
// line on each side of it; with the comment gone,
45874588
// blanks between the lists would fuse them into ONE
45884589
// loose list on reparse. A tight pair keeps no blank
4589-
// line at all; a loose pair keeps exactly one.
4590+
// line at all; a loose pair keeps exactly one. A
4591+
// needs_blank pair also keeps exactly one: an ordered
4592+
// list starting above 1 cannot interrupt the previous
4593+
// item's paragraph, so with no blank line at all its
4594+
// first line reparses as a lazy continuation and the
4595+
// list is lost (Codex review, PR #3258).
45904596
let prev_blank = kept.last().is_some_and(|l| is_blank_line(l));
45914597
let next_blank = lines.get(idx + 1).is_some_and(|l| is_blank_line(l));
45924598
if prev_blank && next_blank {
4593-
if *tight_pair {
4599+
if *tight_pair && !*needs_blank {
45944600
kept.pop();
45954601
}
45964602
idx += 1; // skip the following blank line too
@@ -4610,14 +4616,14 @@ fn strip_end_list_separators(doc: &Value, output: &str) -> String {
46104616
out
46114617
}
46124618

4613-
/// (prev PM kind, PM kind, both tight, merge-safe) for every list
4619+
/// (prev PM kind, PM kind, both tight, merge-safe, needs-blank) for every list
46144620
/// adjacency in the doc, in render order, interleaved with authored
4615-
/// htmlBlocks (recorded as ("", "", false, false) so they consume a
4621+
/// htmlBlocks (recorded as ("", "", false, false, false) so they consume a
46164622
/// separator-line slot but are never dropped - see
46174623
/// strip_end_list_separators' caller contract). Merge-safe is false
46184624
/// only when dropping the separator would merge two ordered-rendering
46194625
/// lists whose numbering does not continue across the boundary.
4620-
fn collect_boundary_kinds(node: &Value, out: &mut Vec<(String, String, bool, bool)>) {
4626+
fn collect_boundary_kinds(node: &Value, out: &mut Vec<(String, String, bool, bool, bool)>) {
46214627
let Some(content) = node["content"].as_array() else {
46224628
return;
46234629
};
@@ -4657,11 +4663,19 @@ fn collect_boundary_kinds(node: &Value, out: &mut Vec<(String, String, bool, boo
46574663
let tight_merge_safe =
46584664
!(renders_ordered(prev) == renders_ordered(child) && tight_differs);
46594665
let merge_safe = ordered_merge_safe && tight_merge_safe;
4666+
// Codex review, PR #3258: an ordered-rendering list that
4667+
// starts above 1 cannot interrupt a paragraph, so when the
4668+
// previous list does not itself render ordered, the boundary
4669+
// must keep a blank line or the second list's first line
4670+
// reparses as a lazy continuation of the previous item.
4671+
let needs_blank = matches!(ordered_start(child), Some(start) if start != 1)
4672+
&& ordered_start(prev).is_none();
46604673
out.push((
46614674
list_kind(prev).unwrap_or_default().to_string(),
46624675
kind.to_string(),
46634676
tight_pair,
46644677
merge_safe,
4678+
needs_blank,
46654679
));
46664680
}
46674681
if child["type"].as_str() == Some("code_block")
@@ -4675,7 +4689,7 @@ fn collect_boundary_kinds(node: &Value, out: &mut Vec<(String, String, bool, boo
46754689
== "<!-- end list -->"
46764690
})
46774691
{
4678-
out.push((String::new(), String::new(), false, false));
4692+
out.push((String::new(), String::new(), false, false, false));
46794693
}
46804694
// Codex review, PR #3258: lists inside a table cell are
46814695
// flattened to text by append_table_cell_child and emit no
@@ -6973,6 +6987,34 @@ mod tests {
69736987
assert!(!out.contains("end list"), "real separator dropped: {out:?}");
69746988
}
69756989

6990+
#[test]
6991+
fn test_adjacent_bullet_to_ordered_starting_above_one_keeps_blank() {
6992+
// Codex review on PR #3258 (P2): a tight bullet list followed by
6993+
// a tight ordered list starting above 1 saved as `- a\n2. b` -
6994+
// an ordered marker above 1 cannot interrupt a paragraph, so on
6995+
// reparse `2. b` became a lazy continuation of the bullet item
6996+
// and the ordered list (and its start) was lost. The boundary
6997+
// keeps exactly one blank line instead of none.
6998+
for original in ["- a\n\n2. b\n", "- [ ] a\n\n3. b\n"] {
6999+
let (first, second) = two_saves(original);
7000+
assert_eq!(first, original, "blank kept, start preserved: {first:?}");
7001+
assert!(
7002+
!first.contains("end list"),
7003+
"no end-list artefact for {original:?}: {first:?}"
7004+
);
7005+
assert_eq!(first, second, "fixpoint for {original:?}");
7006+
assert_eq!(
7007+
markdown_to_prosemirror(&first),
7008+
markdown_to_prosemirror(original),
7009+
"reparse yields the same two lists for {original:?}"
7010+
);
7011+
let doc = markdown_to_prosemirror(&first);
7012+
let content = doc["content"].as_array().unwrap();
7013+
assert_eq!(content.len(), 2, "two lists for {original:?}");
7014+
assert_eq!(content[1]["type"], "ordered_list", "second list stays ordered for {original:?}");
7015+
}
7016+
}
7017+
69767018
#[test]
69777019
fn test_adjacent_different_kind_lists_in_blockquote_fixpoint() {
69787020
// #1397: the blockquote shape was not even a save fixpoint.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.