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

feat(i18n): allow simple HTML tags when using Translate component #5114

Merged
merged 1 commit into from
Nov 3, 2023

Conversation

rexxars
Copy link
Member

@rexxars rexxars commented Nov 2, 2023

Description

It's a bit tedious to pass in components like <Code> that just maps to <code>. This PR allows using this predefined list of tags without specifying it directly: <abbr>, <address>, <cite>, <code>, <del>, <em>, <ins>, <kbd>, <q>, <samp>, <strong>, <sub>, <sup>.

The reason for these specifically is that they are inline elements that do not require any attributes for use, and is not deprecated by the HTML5 spec.

I'm not sure if my solution in the parser was the best, but I didn't want to spend more time finding a more elegant way to approach it - open to suggestions.

What to review

  • Using simple tags with the <Translate/> component works as it should

Notes for release

None.

@rexxars rexxars requested review from bjoerge and a team November 2, 2023 20:53
Copy link

vercel bot commented Nov 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Nov 3, 2023 6:10pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 3, 2023 6:10pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Nov 3, 2023 6:10pm

Copy link
Contributor

github-actions bot commented Nov 2, 2023

Package Documentation Change
sanity +16%
@sanity/types +2%
sanity/desk +2%
Full Report
sanity
This branch Next branch
141 documented 122 documented
841 not documented 831 not documented
@sanity/types
This branch Next branch
54 documented 53 documented
233 not documented 233 not documented
sanity/desk
This branch Next branch
84 documented 83 documented
56 not documented 55 not documented
@sanity/diff
This branch Next branch
13 documented 13 documented
16 not documented 16 not documented
@sanity/block-tools
This branch Next branch
4 documented 4 documented
9 not documented 9 not documented
@sanity/portable-text-editor
This branch Next branch
21 documented 21 documented
44 not documented 44 not documented
@sanity/mutator
This branch Next branch
7 documented 7 documented
4 not documented 4 not documented
@sanity/cli
This branch Next branch
1 documented 1 documented
30 not documented 30 not documented
@sanity/schema/_internal
This branch Next branch
0 documented 0 documented
9 not documented 9 not documented
@sanity/util/paths
This branch Next branch
1 documented 1 documented
15 not documented 15 not documented
sanity/router
This branch Next branch
15 documented 15 documented
21 not documented 21 not documented
@sanity/util/legacyDateFormat
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
@sanity/schema
This branch Next branch
0 documented 0 documented
2 not documented 2 not documented
sanity/cli
This branch Next branch
2 documented 2 documented
0 not documented 0 not documented
@sanity/vision
This branch Next branch
0 documented 0 documented
2 not documented 2 not documented
@sanity/util/fs
This branch Next branch
0 documented 0 documented
3 not documented 3 not documented
sanity/_internal
This branch Next branch
0 documented 0 documented
1 not documented 1 not documented
@sanity/util/content
This branch Next branch
1 documented 1 documented
5 not documented 5 not documented

Copy link
Contributor

github-actions bot commented Nov 2, 2023

Component Testing Report Updated Nov 3, 2023 6:13 PM (UTC)

File Status Duration Passed Skipped Failed
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 8s 6 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 12s 9 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 44s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 10s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 5s 3 0 0

Copy link
Contributor

@ricokahler ricokahler left a comment

Choose a reason for hiding this comment

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

nice

Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

just a question/comment, otherwise great!

)
})
test('tags cant contain whitespace or special characters', () => {
expect(() => simpleParser('foo <Em@ail> bar</Em@ail>')).toThrow(
'Invalid tag "<Em@ail>". Tag names must start with an uppercase letter and can only include letters and numbers.',
'Invalid tag "<Em@ail>". Tag names must be lowercase HTML tags or start with an uppercase letter and can only include letters and numbers.',
Copy link
Member

Choose a reason for hiding this comment

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

should we mention the subset of tags we allow here?


throw new Error(
tagName.trim() === tagName
? `Invalid tag "<${tagName}>". Tag names must be lowercase HTML tags or start with an uppercase letter and can only include letters and numbers.`
Copy link
Member

Choose a reason for hiding this comment

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

re:previous comment: maybe this would be a better place to mention what subset of tags we allow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. It does print an error in the Translate component, so I think that is fine for now. I tried refactoring, but ran into some parser shenanigan holes that I don't want to reason about at the moment. We can get back to it later if it becomes a problem.

@rexxars rexxars force-pushed the feat/i18n-allow-basic-html-tags branch from cf327ca to f87050f Compare November 3, 2023 18:07
@rexxars rexxars merged commit 39640c5 into feat/i18n Nov 3, 2023
16 of 17 checks passed
@rexxars rexxars deleted the feat/i18n-allow-basic-html-tags branch November 3, 2023 18:07
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.

3 participants