Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit ef81705

Browse files
committed
markdown: normalize ordered list markers
1 parent 8134a34 commit ef81705

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

frontend/components/design-system-components/MessageMarkdown.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,25 @@ const markdownComponents: any = {
280280
}
281281
} as const
282282

283+
// Normalize ordered list markers so that lines starting with "1) " are
284+
// converted to the CommonMark style "1. ". This helps react-markdown parse
285+
// them as ordered lists. We avoid transforming content inside fenced code blocks.
286+
const normalizeOrderedListMarkers = (markdown: string) => {
287+
let inCodeFence = false
288+
const fenceRegex = /^\s*```/
289+
return markdown
290+
.split('\n')
291+
.map(line => {
292+
if (fenceRegex.test(line)) {
293+
inCodeFence = !inCodeFence
294+
return line
295+
}
296+
if (inCodeFence) return line
297+
return line.replace(/^(\s*)(\d+)\)\s+/, '$1$2. ')
298+
})
299+
.join('\n')
300+
}
301+
283302
const MessageMarkdown = ({
284303
children,
285304
className,
@@ -291,6 +310,7 @@ const MessageMarkdown = ({
291310
allowHtml?: boolean
292311
textSize?: MarkdownTextSize
293312
}) => {
313+
const normalizedChildren = normalizeOrderedListMarkers(children)
294314
return (
295315
<MarkdownContext.Provider value={textSize}>
296316
<MemoizedReactMarkdown
@@ -307,7 +327,7 @@ const MessageMarkdown = ({
307327
}
308328
components={markdownComponents}
309329
>
310-
{children}
330+
{normalizedChildren}
311331
</MemoizedReactMarkdown>
312332
</MarkdownContext.Provider>
313333
)

0 commit comments

Comments
 (0)