Skip to content

Commit

Permalink
fix: should respect stringify number for line-height (#543)
Browse files Browse the repository at this point in the history
Close #535

Co-authored-by: Shu Ding <[email protected]>
  • Loading branch information
Jackie1210 and shuding authored Sep 17, 2023
1 parent fcaae1d commit 0a016f1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/handler/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ function handleFallbackColor(
}

function purify(name: string, value?: string | number) {
if (typeof value === 'number') {
if (!optOutPx.has(name)) return value + 'px'
if (keepNumber.has(name)) return value
return String(value)
}
return value
const num = Number(value)
if (isNaN(num)) return value
if (!optOutPx.has(name)) return num + 'px'
if (keepNumber.has(name)) return num
return String(value)
}

function handleSpecialCase(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions test/line-height.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { it, describe, expect } from 'vitest'

import { initFonts, toImage } from './utils.js'
import satori from '../src/index.js'

describe('line-height', () => {
let fonts
initFonts((f) => (fonts = f))
it('should work correctly', async () => {
const svgs = await Promise.all(
[1, '1'].map((lineHeight) =>
satori(
<div
style={{
margin: 0,
padding: 0,
fontSize: '30px',
width: '100px',
height: '100px',
background: 'white',
lineHeight,
}}
>
Hello I am some text that is here.
</div>,
{ width: 100, height: 100, fonts, embedFont: true }
)
)
)

svgs.forEach((svg) => {
expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})
})

1 comment on commit 0a016f1

@vercel
Copy link

@vercel vercel bot commented on 0a016f1 Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.