@@ -159,22 +159,24 @@ function findTaskListMarkerOffset(markdown: string, listItemStart: number): numb
159159}
160160
161161/**
162- * The default `1.25rem` marker gutter (`.chat-markdown ol`) fits two-digit
163- * decimal markers. Once a list's last item reaches three digits (item 100+),
164- * `list-style-position: outside` paints the marker wider than that gutter and
165- * the leading digit gets clipped by the item's own overflow. Rather than
166- * widening the gutter for every list, only lists whose last marker is 3+
167- * digits get a wider `--list-gutter`, sized to that marker's digit count.
162+ * The default `1.25rem` marker gutter (`.chat-markdown ol`) fits markers up to
163+ * two characters wide. Once a marker reaches three characters (item 100+),
164+ * `list-style-position: outside` paints it wider than that gutter and clips
165+ * the leading character against the item's own overflow. Rather than widening
166+ * the gutter for every list, only lists whose widest marker is 3+ characters
167+ * get a wider `--list-gutter`. The width includes a negative marker's minus
168+ * sign.
168169 */
169170export function orderedListGutterStyle (
170171 itemCount : number ,
171- start : number | undefined ,
172+ start : unknown ,
172173) : { "--list-gutter" : string } | undefined {
173- const firstNumber = typeof start === "number" && Number . isFinite ( start ) ? start : 1 ;
174+ const parsedStart = Number . parseInt ( String ( start ?? 1 ) , 10 ) ;
175+ const firstNumber = Number . isNaN ( parsedStart ) ? 1 : parsedStart ;
174176 const lastNumber = firstNumber + Math . max ( itemCount - 1 , 0 ) ;
175- const digits = String ( Math . abs ( lastNumber ) ) . length ;
176- if ( digits <= 2 ) return undefined ;
177- return { "--list-gutter" : `${ digits + 1 } ch` } ;
177+ const markerWidth = Math . max ( String ( firstNumber ) . length , String ( lastNumber ) . length ) ;
178+ if ( markerWidth <= 2 ) return undefined ;
179+ return { "--list-gutter" : `${ markerWidth + 1 } ch` } ;
178180}
179181
180182const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
0 commit comments