[js] [atoms] Fixed text transformation issue with text-transform: capitalize#16275
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
| // Preceded by start or a non-word (so it won't fire for snake_case) | ||
| re = /(^|[^'_0-9A-Za-z\u00C0-\u02AF\u1E00-\u1EFF\u24B6-\u24E9])([_*])([A-Za-z\u00C0-\u02AF\u1E00-\u1EFF\u24D0-\u24E9])/g; | ||
| text = text.replace(re, function () { | ||
| return arguments[1] + arguments[2] + arguments[3].toUpperCase(); |
There was a problem hiding this comment.
Here you can remove the magic numbers and leave something more descriptive like:
text = text.replace(re, function (_match, prefix, divider, char) {
return prefix + divider + char.toUpperCase();
});
There was a problem hiding this comment.
Sure, I just followed the existing implementation and coding style
There was a problem hiding this comment.
No worries, it's just a coding tip.
User description
🔗 Related Issues
Fixes #14271
💥 What does this PR do?
Fixes incorrect capitalization behavior for text-transform: capitalize, addressing:
🔧 Implementation Notes
Replaced the previous boundary regex:
First step uses a negated “separator” class that treats ASCII letters, extended Latin letters (\u00C0–\u02AF, \u1E00–\u1EFF) and combining marks (\u0300–\u036F, \u1AB0–\u1AFF, \u1DC0–\u1DFF) as in-word characters, and excludes _ and apostrophes from being boundaries (so we don’t split snake_case or contractions).
Second step: a small second regex capitalizes the first letter after an opening _ or * only when those symbols act as wrappers (preceded by start or a non-word), avoiding interference with snake_case.
All tests from the text_test.html are passed locally:
💡 Additional Considerations
Scope limited to Latin scripts + circled letters; other scripts (Greek/Cyrillic/etc.) can be added by extending ranges if needed.
🔄 Types of changes
PR Type
Bug fix
Description
Fixed text-transform: capitalize for accented Latin letters
Added support for enye and extended Unicode ranges
Improved boundary detection to preserve snake_case
Added test cases for Spanish accented characters
Diagram Walkthrough
File Walkthrough
dom.js
Enhanced text capitalization with Unicode supportjavascript/atoms/dom.js
text_test.html
Added Unicode capitalization test casesjavascript/atoms/test/text_test.html