Repository navigation
fix(mobile): three-digit list numbers no longer lose their first digit #19742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
89a3832
72bdbd0
88d080d
a45f036
94ac683
158f0e8
7eb36bf
d6a2af4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { wideOrderedListMarkerDigits } from "./orderedListMarkers"; | ||
|
|
||
| const numberedList = (count: number, marker = "1.") => | ||
| Array.from({ length: count }, () => `${marker} item`).join("\n"); | ||
|
|
||
| describe("wideOrderedListMarkerDigits", () => { | ||
| it("ignores text and lists that fit the normal gutter", () => { | ||
| expect(wideOrderedListMarkerDigits("just a message")).toBe(0); | ||
| expect(wideOrderedListMarkerDigits("We shipped it in 2026. More later.")).toBe(0); | ||
| expect(wideOrderedListMarkerDigits(numberedList(99))).toBe(0); | ||
| }); | ||
|
|
||
| it("covers written and renderer-generated three-digit markers", () => { | ||
| expect(wideOrderedListMarkerDigits("100. item")).toBe(3); | ||
| expect(wideOrderedListMarkerDigits(numberedList(100))).toBe(3); | ||
| expect(wideOrderedListMarkerDigits(numberedList(100, "> 1."))).toBe(3); | ||
| }); | ||
|
|
||
| it("measures ordered markers nested in other list items", () => { | ||
| expect(wideOrderedListMarkerDigits("100. 1. item")).toBe(3); | ||
| expect(wideOrderedListMarkerDigits("- 1000. nested")).toBe(4); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // A line that may start an ordered-list item, including one nested after quote | ||
| // or list markers. Group 1 holds the container markers before the last number, | ||
| // which can include outer numbers. Each repeat starts with a marker or `>`, | ||
| // which keeps matching linear. | ||
| const ORDERED_MARKER_LINE = | ||
| /^([ \t>]*(?:(?:[-+*]|\d{1,9}[.)])[ \t]+(?:>[ \t>]*)?)*)(\d{1,9})[.)](?:[ \t\r]|$)/; | ||
| const PREFIX_NUMBER = /(\d{1,9})[.)]/g; | ||
| export function wideOrderedListMarkerDigits(markdown: string): number { | ||
| let widest = 0; | ||
| let items = 0; | ||
| for (const line of markdown.split("\n")) { | ||
| const marker = ORDERED_MARKER_LINE.exec(line); | ||
| if (!marker) continue; | ||
| items += 1; | ||
| widest = Math.max(widest, Number(marker[2])); | ||
| for (const outer of marker[1]!.matchAll(PREFIX_NUMBER)) { | ||
| widest = Math.max(widest, Number(outer[1])); | ||
| } | ||
| } | ||
| // The renderer increments repeated `1.` markers. Counting every matched item | ||
| // may over-size messages with many separate lists, but it cannot clip them. | ||
| const digits = String(Math.max(widest, items)).length; | ||
| return digits >= 3 ? digits : 0; | ||
|
Comment on lines
+22
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Restore the effective list-number calculation. For 🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.