Skip to content

Commit eb9a404

Browse files
authoredNov 20, 2023
fix: should render spaces other than U+0020 when white-space: normal (#557)
### Description Should render spaces other than U+0020 when `white-space: normal`. Before: ![image](https://github.com/vercel/satori/assets/22126563/132f9345-88ff-4ee7-8dcf-5a290a8f2ed6) After: ![image](https://github.com/vercel/satori/assets/22126563/78d61815-7695-4b48-900b-b481d8891047)
1 parent a2abe37 commit eb9a404

4 files changed

+8
-3
lines changed
 

‎src/text/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ export default async function* buildTextNodes(
264264
}
265265
if (forceBreak || willWrap) {
266266
// Start a new line, spaces can be ignored.
267-
// @TODO Lack of support for Japanese spacing
268267
if (shouldCollapseTabsAndSpaces && word === Space) {
269268
w = 0
270269
}

‎src/text/processor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function processWhiteSpace(
148148
}
149149

150150
if (shouldCollapseTabsAndSpaces) {
151-
content = content.replace(/([ ]|\t)+/g, Space).trim()
151+
content = content.replace(/([ ]|\t)+/g, Space).replace(/^[ ]|[ ]$/g, '')
152152
}
153153

154154
return { content, shouldCollapseTabsAndSpaces, allowSoftWrap }

‎test/white-space.test.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ describe('white-space', () => {
99

1010
describe('normal', () => {
1111
it('should not render extra spaces with `white-space: normal`', async () => {
12+
const EnSpace = String.fromCodePoint(Number('0x2002'))
13+
1214
const svg = await satori(
1315
<div
1416
style={{
1517
whiteSpace: 'normal',
18+
display: 'flex',
19+
flexDirection: 'column',
1620
}}
1721
>
18-
{' hello '}
22+
<div>{'hello'}</div>
23+
<div>{' hello '}</div>
24+
<div>{EnSpace + 'hello'}</div>
1925
</div>,
2026
{
2127
width: 100,

1 commit comments

Comments
 (1)

vercel[bot] commented on Nov 20, 2023

@vercel[bot]
Please sign in to comment.