Skip to content

Commit 0942d8b

Browse files
authored
Fix code block line height in Safari
Safari renders a small space between inline-block elements, resulting in a variable height of lines which cause a scroll overflow depending on their width. On iOS this results in the font size of each token being scaled up individually depending on the width of the token element. On desktop Safari the font size stays consistent and the text causes a line break.
1 parent cf5b00a commit 0942d8b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/prism/src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ export default ({ children, className: outerClassName, title, ...props }) => {
2424
<Styled.pre className={`${outerClassName} ${className}`} style={style}>
2525
{tokens.map((line, i) => (
2626
<div {...getLineProps({ line, key: i })}>
27-
{line.map((token, key) => (
28-
<span
29-
{...getTokenProps({ token, key })}
30-
sx={{ display: 'inline-block' }}
31-
/>
32-
))}
27+
{line.map((token, key) => {
28+
const tokenProps = getTokenProps({ token, key })
29+
30+
if (line.length === 1 && !tokenProps.children) {
31+
tokenProps.sx = { display: 'inline-block' }
32+
}
33+
34+
return <span {...tokenProps} />
35+
})}
3336
</div>
3437
))}
3538
</Styled.pre>

0 commit comments

Comments
 (0)