{diff.rows.map((row, index) => renderDiffRow(row, index, diffTokens?.get(index)))}
+ {diffRows.rows.map((row, index) => renderDiffRow(row, index, diffTokens?.get(index)))}
)
: streamedBody !== undefined
? streamedBody
@@ -238,7 +241,7 @@ export function CodeBlock({
)
return (
-
+ )
+}
+
+/**
+ * Render one `math` fence body as display TeX.
+ * @param props - the fence body without its closing newline.
+ * @returns the typeset formula.
+ */
+export function FenceMathBlock({ code }: { code: string }): ReactNode {
+ // rehype-katex parity: its text extraction saw the code block's trailing newline.
+ return <>{renderTexToReact(`${code}\n`, true)}>
+}
diff --git a/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx b/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx
index c070d67c35..df0491c34e 100644
--- a/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx
+++ b/packages/client/ui-primitives/src/markdown/MarkdownDelegate.tsx
@@ -16,6 +16,21 @@ export type MarkdownMenuTarget =
| { kind: 'url'; url: string }
| { kind: 'image'; url: string; path?: string; name?: string; mediaType?: string }
+/** One Markdown code fence whose language is final, as {@link MarkdownDelegate.renderCode} receives it. */
+export interface MarkdownDelegateFenceInfo {
+ /**
+ * The info string's language word, cut at its first character outside
+ * letters, digits, `_`, and `-`, then lowercased (`c++` yields `c`).
+ */
+ readonly lang: string
+ /** The fence body without its closing newline. */
+ readonly code: string
+ /** The surrounding document is still streaming, so `code` may still change. */
+ readonly streaming: boolean
+ /** The info string after the language word, as the author wrote it; absent when the fence names only a language. */
+ readonly meta?: string | undefined
+}
+
/** Navigation capabilities supplied by the nearest Markdown owner. */
export interface MarkdownDelegate {
/** Open an object menu without executing its normal activation. */
@@ -38,6 +53,14 @@ export interface MarkdownDelegate {
* @param options - First line to reveal when the destination specifies a line or range.
*/
readonly openFile?: ((path: string, options?: { line?: number }) => void) | undefined
+ /**
+ * Render one fence whose language is final: it has a language and content.
+ * Absent, the document renders fences with its built-in code and math blocks;
+ * present, the owner renders every such fence, including `diff` and `math`.
+ * @param fence - language, body, and streaming state.
+ * @returns the rendered block.
+ */
+ readonly renderCode?: ((fence: MarkdownDelegateFenceInfo) => ReactNode) | undefined
}
const MarkdownDelegateContext = createContextx
', streaming: false, meta: 'width=480 height=360' }) + expect(renderCode.mock.calls[0]?.[0]).toHaveProperty('meta', 'width=480 height=360') + }) + + it('keeps language-less and empty fences on the built-in blocks', () => { + const renderCode = renderFenceSpy() + const { container } = render( +')
+ })
+
+ it('hands math and diff fences to the delegate too', () => {
+ const renderCode = renderFenceSpy()
+ const { container } = render(
+