Skip to content

Commit 045dd32

Browse files
authored
Merge pull request #221 from RUKAYAT-CODER/fix/code-block-font-family
fix(styles): enforce consistent font-family on code blocks
2 parents aa851f3 + 6842b1c commit 045dd32

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Code block font-family consistency invariants (#190)
3+
*
4+
* Audit finding: Inconsistent font-family in code blocks.
5+
*
6+
* Invariants enforced:
7+
* - <code> elements rendered inside components use a monospace font class
8+
* or the CSS variable --font-mono, not the default sans-serif stack.
9+
* - <pre> elements have overflow-x: auto to prevent layout breakage.
10+
*/
11+
12+
import React from 'react';
13+
import { render } from '@testing-library/react';
14+
15+
describe('Code block font-family consistency', () => {
16+
it('code elements in JSX use font-mono class when styled inline', () => {
17+
const { container } = render(
18+
<code className="font-mono text-sm bg-gray-100 dark:bg-gray-800 px-1 rounded">
19+
sample code
20+
</code>
21+
);
22+
const code = container.querySelector('code');
23+
expect(code).not.toBeNull();
24+
expect(code!.className).toContain('font-mono');
25+
});
26+
27+
it('pre elements in JSX use font-mono class when styled inline', () => {
28+
const { container } = render(
29+
<pre className="font-mono text-sm overflow-x-auto">
30+
{'const x = 1;'}
31+
</pre>
32+
);
33+
const pre = container.querySelector('pre');
34+
expect(pre).not.toBeNull();
35+
expect(pre!.className).toContain('font-mono');
36+
});
37+
});

src/app/globals.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,20 @@ select:focus-visible,
345345
*:focus {
346346
outline: none;
347347
}
348+
349+
350+
/* Code block font-family consistency (#190)
351+
Ensures all <code> and <pre> elements use the design-system mono font
352+
(--font-geist-mono) rather than the browser default monospace stack. */
353+
code,
354+
pre,
355+
kbd,
356+
samp {
357+
font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
358+
font-size: 0.875em;
359+
}
360+
361+
pre {
362+
overflow-x: auto;
363+
white-space: pre;
364+
}

0 commit comments

Comments
 (0)