Skip to content

Commit

Permalink
Move normalize(NFC) to hyphenateElement
Browse files Browse the repository at this point in the history
  • Loading branch information
mnater committed May 27, 2018
1 parent 25a91fc commit a3229f7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 6 deletions.
13 changes: 8 additions & 5 deletions Hyphenopoly.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@
*/
function createWordHyphenator(lo, lang, cn) {
const classSettings = C[cn];
const normalize = C.normalize && String.prototype.normalize;
const hyphen = classSettings.hyphen;

lo.cache[cn] = empty();
Expand Down Expand Up @@ -367,9 +366,6 @@
* @returns {string} The hyphenated word
*/
function hyphenator(word) {
if (normalize) {
word = word.normalize("NFC");
}
let hw = lo.cache[cn][word];
if (!hw) {
if (lo.exceptions[word]) {
Expand Down Expand Up @@ -443,6 +439,8 @@
const cn = elo.class;
const classSettings = C[cn];
const minWordLength = classSettings.minWordLength;
const normalize = C.normalize &&
Boolean(String.prototype.normalize);
H.events.dispatch("beforeElementHyphenation", {
"el": el,
"lang": lang
Expand All @@ -462,7 +460,12 @@
n.nodeType === 3 &&
n.data.length >= minWordLength
) {
let tn = n.data.replace(re, wordHyphenator);
let tn = null;
if (normalize) {
tn = n.data.normalize("NFC").replace(re, wordHyphenator);
} else {
tn = n.data.replace(re, wordHyphenator);
}
if (classSettings.orphanControl !== 1) {
tn = tn.replace(
/(\u0020*)(\S+)(\s*)$/,
Expand Down
93 changes: 93 additions & 0 deletions testsuite/test22.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Test 022</title>
<script>
var Hyphenopoly = {
require: {
"de": "FORCEHYPHENOPOLY"
},
paths: {
maindir: "../",
patterndir: "../patterns/"
},
setup: {
classnames: {
"hyphenate": {
hyphen: "•"
}
},
normalize: true
},
handleEvent: {
hyphenopolyEnd: function (e) {
assert();
}
}
};
function assert() {
var tests = 1;
var i = 1;
var test = "";
var ref = "";
var result = false;
while (i <= tests) {
test = document.getElementById("test" + i).innerHTML;
ref = document.getElementById("ref" + i).innerHTML;
if (test === ref) {
document.getElementById("result").innerHTML += "<p style=\"background-color: #d6ffd6\">" + i + " passed</p>";
result = result || true;
} else {
document.getElementById("result").innerHTML += "<p style=\"background-color: #ffd6d6\">" + i + " failed</p>";
result = result || false;
}
i += 1;
}
if (parent != window) {
parent.postMessage(JSON.stringify({
desc: document.getElementById("desc").innerHTML,
index: 22,
result: (result ? "passed" : "failed")
}), window.location.href);
}
}
</script>
<script src="../Hyphenopoly_Loader.js"></script>
<style type="text/css">
body {
width:50%;
margin-left:25%;
margin-right:25%;
}

.test {
background-color: #D8E2F9;
}
.ref {
background-color: #FEEFC0;
}

.hyphenate {
hyphens: auto;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
}
</style>
</head>
<body>
<div id="navigate"><a href="index.html">&Larr;&nbsp;Index</a>&nbsp;|&nbsp;<a href="test21.html">&larr;&nbsp;Prev</a>&nbsp;|&nbsp;<a href="test23.html">Next&nbsp;&rarr;</a></div>

<h1>Test 022</h1>
<p id="desc">Normalize combined characters (not supported in all clients)</p>
<div id="result"></div>
<hr>
<p id="test1" class="test hyphenate" lang="de">Bärentöter Ba&#x0308;rento&#x0308;ter</p>
<p id="ref1" class="ref" lang="de">Bä•ren•tö•ter Bä•ren•tö•ter</p>

<hr>
<div><span class="test">Test</span> <span class="ref">Ref</span></div>

</body>
</html>
3 changes: 2 additions & 1 deletion testsuite/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
{exec: true, path: "test18.html"},
{exec: true, path: "test19.html"},
{exec: true, path: "test20.html"},
{exec: true, path: "test21.html"}
{exec: true, path: "test21.html"},
{exec: true, path: "test22.html"}
];
var testframe = document.getElementById("testframe");
var currentTest = 1;
Expand Down

0 comments on commit a3229f7

Please sign in to comment.