Skip to content

Commit dbcdae3

Browse files
authored
fix: handle double quoted fontNames for fontFamily/css (#1575)
* fix: handle double quoted fontNames * chore: add changeset
1 parent 97a209a commit dbcdae3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.changeset/tasty-ligers-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': patch
3+
---
4+
5+
Fix fontName parsing to handle double quotes

__tests__/common/transforms.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,15 @@ describe('common', () => {
13051305
).to.equal('Arial, sans-serif');
13061306
});
13071307

1308+
it('should handle double quoted fontFamily values', () => {
1309+
expect(
1310+
fontFamilyTransform({
1311+
value: 'Some Font, "With Double Quotes", \'And Single Quotes\'',
1312+
type: 'fontFamily',
1313+
}),
1314+
).to.equal("'Some Font', \"With Double Quotes\", 'And Single Quotes'");
1315+
});
1316+
13081317
it('should wrap fontFamily values with spaces in quotes', () => {
13091318
expect(fontFamilyTransform({ value: 'Gill Sans', type: 'fontFamily' })).to.equal(
13101319
"'Gill Sans'",

lib/common/transforms.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ function getBasePxFontSize(config) {
121121
*/
122122
function quoteWrapWhitespacedFont(fontString) {
123123
let fontName = fontString.trim();
124-
const isQuoted = fontName.startsWith("'") && fontName.endsWith("'");
124+
const isQuoted =
125+
(fontName.startsWith("'") && fontName.endsWith("'")) ||
126+
(fontName.startsWith('"') && fontName.endsWith('"'));
125127
if (!isQuoted) {
126128
fontName = fontName.replace(/'/g, "\\'");
127129
}

0 commit comments

Comments
 (0)