Skip to content

Commit c216020

Browse files
authored
Merge branch 'trunk' into py-bidi-network-data-urls
2 parents 2ea15c8 + 775cfb3 commit c216020

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

javascript/atoms/dom.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,11 +1173,18 @@ bot.dom.appendVisibleTextLinesFromTextNode_ = function (textNode, lines,
11731173
}
11741174

11751175
if (textTransform == 'capitalize') {
1176-
// the unicode regex ending with /gu does not work in IE
1177-
var re = goog.userAgent.IE ? /(^|\s|\b)(\S)/g : /(^|\s|\b)(\S)/gu;
1176+
// 1) don't treat '_' as a separator (protects snake_case)
1177+
var re = /(^|[^'_0-9A-Za-z\u00C0-\u02AF\u1E00-\u1EFF\u24B6-\u24E9\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF])([A-Za-z\u00C0-\u02AF\u1E00-\u1EFF\u24B6-\u24E9])/g;
11781178
text = text.replace(re, function () {
11791179
return arguments[1] + arguments[2].toUpperCase();
11801180
});
1181+
1182+
// 2) capitalize after opening "_" or "*"
1183+
// Preceded by start or a non-word (so it won't fire for snake_case)
1184+
re = /(^|[^'_0-9A-Za-z\u00C0-\u02AF\u1E00-\u1EFF\u24B6-\u24E9])([_*])([A-Za-z\u00C0-\u02AF\u1E00-\u1EFF\u24D0-\u24E9])/g;
1185+
text = text.replace(re, function () {
1186+
return arguments[1] + arguments[2] + arguments[3].toUpperCase();
1187+
});
11811188
} else if (textTransform == 'uppercase') {
11821189
text = text.toUpperCase();
11831190
} else if (textTransform == 'lowercase') {

javascript/atoms/test/text_test.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@
235235
function testShouldRetainTheFormattingOfTextWithinAPreElement() {
236236
var text = getVisibleTextByElementId("preformatted");
237237

238-
assertEquals(" This section has a preformatted\n text block \n split in four lines\n ", text);
238+
assertEquals(" This section has a preformatted\n text block\n split in four lines\n ", text);
239239
}
240240

241241
function testShouldRetainTheFormattingOfTextWithinAPreElementThatIsWithinARegularBlock() {
242242
var text = getVisibleTextByElementId("div-with-pre");
243243

244-
assertEquals("before pre\n This section has a preformatted\n text block \n split in four lines\n \nafter pre", text);
244+
assertEquals("before pre\n This section has a preformatted\n text block\n split in four lines\n \nafter pre", text);
245245
}
246246

247247
function testGetVisibleTextShouldHandleCssContentReplacement() {
@@ -264,6 +264,11 @@
264264
text = getVisibleTextByElementId("uppercased");
265265
assertEquals("HELLO, WORLD! BLA-BLA-BLA", text);
266266

267+
text = getVisibleTextByElementId("capitalized_accented_character");
268+
assertEquals("Fecha De Expiración", text);
269+
text = getVisibleTextByElementId("capitalized_enye");
270+
assertEquals("Mañana", text);
271+
267272
text = getVisibleTextByElementId("capitalized-1");
268273
assertEquals("Äåìî", text);
269274
text = getVisibleTextByElementId("capitalized-2");
@@ -423,6 +428,11 @@
423428
<a id="uppercased" style="text-transform: uppercase">hello, world! bla-bla-BLA</a><br/>
424429
</div>
425430

431+
<div>
432+
<a id="capitalized_accented_character" style="text-transform: capitalize">Fecha de expiración</a><br/>
433+
<a id="capitalized_enye" style="text-transform: capitalize">mañana</a><br/>
434+
</div>
435+
426436
<div>
427437
<a lang="ru" id="capitalized-1" style="text-transform: capitalize">äåìî</a><br/>
428438
<a id="capitalized-2" style="text-transform: capitalize">Manipulowanie przepływem</a><br/>

0 commit comments

Comments
 (0)