Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 53 additions & 0 deletions ui/desktop/src/components/MarkdownContent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,57 @@ Another very long URL: https://www.example.com/very/long/path/with/many/segments
expect(markdownContainer).toHaveClass('prose-a:overflow-wrap-anywhere');
});
});

describe('KaTeX Math Rendering - singleDollarTextMath: false', () => {
it('treats single dollar signs as plain text', async () => {
const content = 'The formula $x_i$ represents the i-th element.';

const { container } = render(<MarkdownContent content={content} />);

await waitFor(() => {
const katexElements = container.querySelectorAll('.katex');
expect(katexElements.length).toBe(0);
expect(container).toHaveTextContent('$x_i$');
});
});

it('renders double dollar signs as display math', async () => {
const content = `Calculate

$$
x^2 + y^2
$$

for the result.`;

const { container } = render(<MarkdownContent content={content} />);

await waitFor(() => {
const katexDisplay = container.querySelector('.katex-display');
expect(katexDisplay).toBeInTheDocument();
});
});

it('handles shell commands without triggering math mode', async () => {
const content = 'Run echo "$FOO_BAR" to see the value.';

const { container } = render(<MarkdownContent content={content} />);

await waitFor(() => {
const katexElements = container.querySelectorAll('.katex');
expect(katexElements.length).toBe(0);
expect(container).toHaveTextContent('$FOO_BAR');
});
});

it('preserves math in code blocks', async () => {
const content = 'The formula `math\nx^2\n` uses inline code.';

const { container } = render(<MarkdownContent content={content} />);

await waitFor(() => {
expect(container).toHaveTextContent('x^2');
});
});
});
});
3 changes: 1 addition & 2 deletions ui/desktop/src/components/MarkdownContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ const MarkdownContent = memo(function MarkdownContent({
setProcessedContent(processed);
} catch (error) {
console.error('Error processing content:', error);
// Fallback to original content if processing fails
setProcessedContent(content);
}
}, [content]);
Expand All @@ -180,7 +179,7 @@ const MarkdownContent = memo(function MarkdownContent({
prose-li:m-0 prose-li:font-sans ${className}`}
>
<ReactMarkdown
remarkPlugins={[remarkGfm, remarkBreaks, remarkMath]}
remarkPlugins={[remarkGfm, remarkBreaks, [remarkMath, { singleDollarTextMath: false }]]}
rehypePlugins={[
[
rehypeKatex,
Expand Down