diff --git a/packages/client/ui-primitives/src/markdown/mathCompatibility.ts b/packages/client/ui-primitives/src/markdown/mathCompatibility.ts index 95f98a1b58..a7039cf328 100644 --- a/packages/client/ui-primitives/src/markdown/mathCompatibility.ts +++ b/packages/client/ui-primitives/src/markdown/mathCompatibility.ts @@ -236,8 +236,10 @@ function createMathFlow(marker: number, openMarker: number, closeMarker: number) // that line's ending while a later `$$` on the same line still closes; on // any later line it ends the candidate outright, so a following block is // not swallowed. A solitary `$` is content, not a failed fence. - if (crossedLineEnding) return nok(code) - if (sawClosingFenceSequence) failedClose = true + if (sawClosingFenceSequence) { + if (crossedLineEnding) return nok(code) + failedClose = true + } return markerValueStart(code) } diff --git a/packages/client/ui-primitives/tests/markdown.client.spec.tsx b/packages/client/ui-primitives/tests/markdown.client.spec.tsx index d0fbb9db95..a5c8037107 100644 --- a/packages/client/ui-primitives/tests/markdown.client.spec.tsx +++ b/packages/client/ui-primitives/tests/markdown.client.spec.tsx @@ -656,6 +656,12 @@ describe('MarkdownText', () => { } }) + it('keeps a lone dollar on a later line inside the block', () => { + const { container } = render() + + expect(container.querySelector('.katex-error')?.textContent).toBe('a+b\nc$d') + }) + it('keeps a fence that fails inside a comment and a trailing lone dollar parseable', () => { const commentFail = render() expect(commentFail.container.querySelector('.katex-display')).toBeNull()