Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/src/components/assistant-ui/markdown-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
type CodeHeaderProps,
} from '@assistant-ui/react-markdown'
import remarkGfm from 'remark-gfm'
import remarkDisableIndentedCode from '@/lib/remark-disable-indented-code'
import { cn } from '@/lib/utils'
import { SyntaxHighlighter } from '@/components/assistant-ui/shiki-highlighter'
import { useCopyToClipboard } from '@/hooks/useCopyToClipboard'
import { CopyIcon, CheckIcon } from '@/components/icons'

export const MARKDOWN_PLUGINS = [remarkGfm]
export const MARKDOWN_PLUGINS = [remarkGfm, remarkDisableIndentedCode]

function CodeHeader(props: CodeHeaderProps) {
const { copied, copy } = useCopyToClipboard()
Expand Down
15 changes: 15 additions & 0 deletions web/src/lib/remark-disable-indented-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Remark plugin that disables indented code blocks (4-space indent).
*
* In CommonMark, text indented by 4+ spaces becomes a code block. This
* frequently misparses LLM output where numbered-list items with nested
* content or quoted text are indented. Fenced code blocks (``` … ```)
* still work normally.
*/
export default function remarkDisableIndentedCode() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const self = this as any
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] const self = this as any still uses an implicit-any this before the cast, so this should trip the repo's strict TypeScript settings (tsconfig.base.json:7).

Suggested fix:

type RemarkData = {
    micromarkExtensions?: Array<{ disable: { null: string[] } }>
}

export default function remarkDisableIndentedCode(this: { data(): RemarkData }) {
    const data = this.data()
    const extensions = data.micromarkExtensions ?? (data.micromarkExtensions = [])
    extensions.push({ disable: { null: ['codeIndented'] } })
}

const data = self.data()
const extensions = data.micromarkExtensions ?? (data.micromarkExtensions = [])
extensions.push({ disable: { null: ['codeIndented'] } })
}
Loading