Skip to content

4 files changed

+55
-2
lines changed

src/text/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,10 @@ export default async function* buildTextNodes(
219219
currentLineHeight = engine.height(word)
220220
}
221221

222-
const allowedToPutAtBeginning = ',.!?:-@)>]}%#'.indexOf(word[0]) < 0
223222
const allowedToJustify = textAlign === 'justify'
224223

225224
const willWrap =
226225
i &&
227-
allowedToPutAtBeginning &&
228226
// When determining whether a line break is necessary, the width of the
229227
// trailing spaces is not included in the calculation, as the end boundary
230228
// can be closely adjacent to the last non-space character.
3.88 KB
Loading
Loading

test/typesetting.test.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { it, describe, expect } from 'vitest'
2+
3+
import { initFonts, toImage } from './utils.js'
4+
import satori from '../src/index.js'
5+
6+
describe('typesetting', () => {
7+
let fonts
8+
initFonts((f) => (fonts = f))
9+
10+
it('should wrap normally', async () => {
11+
const svg = await satori(
12+
<div
13+
style={{
14+
width: '100%',
15+
height: '100%',
16+
fontSize: 18,
17+
color: 'black',
18+
wordBreak: 'break-word',
19+
}}
20+
>
21+
A quick brown fox jumps over the lazy dog.
22+
</div>,
23+
{
24+
width: 100,
25+
height: 100,
26+
fonts,
27+
}
28+
)
29+
30+
expect(toImage(svg, 100)).toMatchImageSnapshot()
31+
})
32+
33+
it('should wrap normally for special characters', async () => {
34+
const svg = await satori(
35+
<div
36+
style={{
37+
width: '100%',
38+
height: '100%',
39+
fontSize: 18,
40+
color: 'black',
41+
wordBreak: 'break-word',
42+
}}
43+
>
44+
{`@A #quick ?brown :fox !jumps -over ~the %lazy ^dog.`}
45+
</div>,
46+
{
47+
width: 100,
48+
height: 100,
49+
fonts,
50+
}
51+
)
52+
53+
expect(toImage(svg, 100)).toMatchImageSnapshot()
54+
})
55+
})

0 commit comments

Comments
 (0)