diff --git a/javascript/atoms/dom.js b/javascript/atoms/dom.js
index d9eef5fb7b500..87a0fd559c5f8 100644
--- a/javascript/atoms/dom.js
+++ b/javascript/atoms/dom.js
@@ -1173,11 +1173,18 @@ bot.dom.appendVisibleTextLinesFromTextNode_ = function (textNode, lines,
}
if (textTransform == 'capitalize') {
- // the unicode regex ending with /gu does not work in IE
- var re = goog.userAgent.IE ? /(^|\s|\b)(\S)/g : /(^|\s|\b)(\S)/gu;
+ // 1) don't treat '_' as a separator (protects snake_case)
+ 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;
text = text.replace(re, function () {
return arguments[1] + arguments[2].toUpperCase();
});
+
+ // 2) capitalize after opening "_" or "*"
+ // 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();
+ });
} else if (textTransform == 'uppercase') {
text = text.toUpperCase();
} else if (textTransform == 'lowercase') {
diff --git a/javascript/atoms/test/text_test.html b/javascript/atoms/test/text_test.html
index 5620902711039..5dc1a12c25de2 100644
--- a/javascript/atoms/test/text_test.html
+++ b/javascript/atoms/test/text_test.html
@@ -235,13 +235,13 @@
function testShouldRetainTheFormattingOfTextWithinAPreElement() {
var text = getVisibleTextByElementId("preformatted");
- assertEquals(" This section has a preformatted\n text block \n split in four lines\n ", text);
+ assertEquals(" This section has a preformatted\n text block\n split in four lines\n ", text);
}
function testShouldRetainTheFormattingOfTextWithinAPreElementThatIsWithinARegularBlock() {
var text = getVisibleTextByElementId("div-with-pre");
- assertEquals("before pre\n This section has a preformatted\n text block \n split in four lines\n \nafter pre", text);
+ assertEquals("before pre\n This section has a preformatted\n text block\n split in four lines\n \nafter pre", text);
}
function testGetVisibleTextShouldHandleCssContentReplacement() {
@@ -264,6 +264,11 @@
text = getVisibleTextByElementId("uppercased");
assertEquals("HELLO, WORLD! BLA-BLA-BLA", text);
+ text = getVisibleTextByElementId("capitalized_accented_character");
+ assertEquals("Fecha De Expiración", text);
+ text = getVisibleTextByElementId("capitalized_enye");
+ assertEquals("Mañana", text);
+
text = getVisibleTextByElementId("capitalized-1");
assertEquals("Äåìî", text);
text = getVisibleTextByElementId("capitalized-2");
@@ -423,6 +428,11 @@
hello, world! bla-bla-BLA
+