Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace escapeApostrophes with specialCharacterFontStringFormatter (Transforms 'Suisse Int'l' into 'Suisse intl') #229

Closed
wants to merge 2 commits into from

Conversation

niborium
Copy link
Contributor

@niborium niborium commented Nov 23, 2023

In this update, i have replaced the escapeApostrophes function with specialCharacterFontStringFormatter. The previous escapeApostrophes function was intended to escape apostrophes in font family names, but it led to invalid CSS formatting in certain cases. An example of this issue was evident with the 'Suisse Int'l' font family, where the output --sdTypographyMobileBody: 400 14px/20 'Suisse Int\'l'; was not a valid CSS format.

The escapeApostrophes approach incorrectly added a backslash before the apostrophe, which is not a standard or recognized escape sequence in CSS font family names. This resulted in malformed CSS that could cause rendering issues or be ignored by the browser.

The new specialCharacterFontStringFormatter function directly addresses this problem by specifically targeting and correctly formatting the 'Suisse Int'l' font family name. Instead of attempting a broad and potentially erroneous escape of apostrophes, it transforms 'Suisse Int'l' into 'Suisse intl', a format that is valid and compatible with CSS standards. This targeted approach provides a more robust and accurate solution for handling special cases in the CSS typography processing.

If you need more special caces for special character font families you can add it to specialCharacterFontStringFormatter (that's why i named it like that) and just add test for it. It should not be that many font families that have special characters like this.

Copy link

changeset-bot bot commented Nov 23, 2023

🦋 Changeset detected

Latest commit: 59fb67e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tokens-studio/sd-transforms Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jorenbroekema
Copy link
Member

jorenbroekema commented Nov 24, 2023

image

This works fine for me. https://www.w3.org/TR/CSS21/fonts.html#value-def-family-name
The spec also recommends using quoted font-family strings and escaping characters when needed, so it doesn't seem like a problem to me?

That said, you can always add your own Style-Dictionary transform that transforms fontFamilies type tokens and removes ' or other special characters from the font-family, but I don't think this should be default behavior in sd-transforms repo

@niborium
Copy link
Contributor Author

niborium commented Nov 24, 2023

image

This works fine for me. https://www.w3.org/TR/CSS21/fonts.html#value-def-family-name The spec also recommends using quoted font-family strings and escaping characters when needed, so it doesn't seem like a problem to me?

That said, you can always add your own Style-Dictionary transform that transforms fontFamilies type tokens and removes ' or other special characters from the font-family, but I don't think this should be default behavior in sd-transforms repo

Will do some more testing and check.

Update: Sorry my bad, it works as expected :)

@niborium niborium closed this Nov 24, 2023
@niborium niborium deleted the escapeAccentMarks branch November 24, 2023 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants