Skip to content

Commit 158f0e8

Browse files
PR Batch Testerclaude
andcommitted
fix(mobile): read outer numbers when one line holds several list markers
`100. 1. item` puts the outer marker in the matched prefix, so read the numbers there too, and count top-level items from the line start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 94ac683 commit 158f0e8

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎apps/mobile/src/lib/orderedListMarkers.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ describe("wideOrderedListMarkerDigits", () => {
3434
expect(wideOrderedListMarkerDigits("- 100000. nested")).toBe(6);
3535
expect(wideOrderedListMarkerDigits("> > 250. quoted")).toBe(3);
3636
expect(wideOrderedListMarkerDigits("1. a\n\n 100. nested")).toBe(3);
37+
expect(wideOrderedListMarkerDigits("100. 1. item")).toBe(3);
38+
expect(wideOrderedListMarkerDigits(numberedList(120, () => "1. 1."))).toBe(3);
3739
});
3840

3941
it("stays linear on long runs of bullets and spaces", () => {

‎apps/mobile/src/lib/orderedListMarkers.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// A line that may start an ordered-list item, including one nested after quote
2-
// or list markers. Group 1 is everything before the number. Each repeat starts
3-
// with a marker or `>`, which keeps matching linear.
2+
// or list markers. Group 1 holds the container markers before the last number,
3+
// which can include outer numbers. Each repeat starts with a marker or `>`,
4+
// which keeps matching linear.
45
const ORDERED_MARKER_LINE =
56
/^([ \t>]*(?:(?:[-+*]|\d{1,9}[.)])[ \t]+(?:>[ \t>]*)?)*)(\d{1,9})[.)](?:[ \t\r]|$)/;
6-
const TOP_LEVEL_PREFIX = /^ {0,3}$/;
7+
const PREFIX_NUMBER = /(\d{1,9})[.)]/g;
8+
const TOP_LEVEL_ITEM = /^ {0,3}\d/;
79

810
/**
911
* Digit count of the widest ordered-list number in `markdown`, when that is
@@ -21,7 +23,10 @@ export function wideOrderedListMarkerDigits(markdown: string): number {
2123
const marker = ORDERED_MARKER_LINE.exec(line);
2224
if (!marker) continue;
2325
widest = Math.max(widest, Number(marker[2]));
24-
if (TOP_LEVEL_PREFIX.test(marker[1]!)) topLevelItems += 1;
26+
for (const outer of marker[1]!.matchAll(PREFIX_NUMBER)) {
27+
widest = Math.max(widest, Number(outer[1]));
28+
}
29+
if (TOP_LEVEL_ITEM.test(line)) topLevelItems += 1;
2530
}
2631
const digits = String(Math.max(widest, topLevelItems)).length;
2732
return digits >= 3 ? digits : 0;

0 commit comments

Comments
 (0)