diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e6c272b..cb5d30fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Version History +## Version 2.3.0 (Juli 26, 2018) +### Hyphenopoly_Loader.js and Hyphenopoly.js: +* Don't use template strings [#28](https://github.com/mnater/Hyphenopoly/issues/28) +* run feature test for wasm support only if necessary + +### hyphenopoly.module.js: +* define node >=8.3.0 as requirement (for util.TextDecoder) +* small refactorings + ## Version 2.2.0 (June 26, 2018) * provide example.js for RunKit * use tap instead of mocha diff --git a/Hyphenopoly.js b/Hyphenopoly.js index 6c1b1eca..e39498f8 100644 --- a/Hyphenopoly.js +++ b/Hyphenopoly.js @@ -1,5 +1,5 @@ /** - * @license Hyphenopoly 2.3.0 - client side hyphenation for webbrowsers + * @license Hyphenopoly 2.4.0 - client side hyphenation for webbrowsers * ©2018 Mathias Nater, Zürich (mathiasnater at gmail dot com) * https://github.com/mnater/Hyphenopoly * diff --git a/Hyphenopoly_Loader.js b/Hyphenopoly_Loader.js index 4632cc21..dc2d6859 100644 --- a/Hyphenopoly_Loader.js +++ b/Hyphenopoly_Loader.js @@ -1,5 +1,5 @@ /** - * @license Hyphenopoly_Loader 2.3.0 - client side hyphenation + * @license Hyphenopoly_Loader 2.4.0 - client side hyphenation * ©2018 Mathias Nater, Zürich (mathiasnater at gmail dot com) * https://github.com/mnater/Hyphenopoly * @@ -299,32 +299,33 @@ * or with xmlHttpRequest * @param {string} path Where the script is stored * @param {string} fne Filename of the script with extension + * @param {string} name Name of the ressource * @param {Object} msg Message * @returns {undefined} */ - function binLoader(path, fne, msg) { + function binLoader(path, fne, name, msg) { /** * Get bin file using fetch * @param {string} p Where the script is stored * @param {string} f Filename of the script with extension + * @param {string} n Name of the ressource * @param {Object} m Message * @returns {undefined} */ - function fetchBinary(p, f, m) { + function fetchBinary(p, f, n, m) { if (!loadedBins[f]) { loadedBins[f] = true; window.fetch(p + f).then( function resolve(response) { if (response.ok) { - const name = f.slice(0, f.lastIndexOf(".")); - if (name === "hyphenEngine") { - H.binaries[name] = response.arrayBuffer().then( + if (n === "hyphenEngine") { + H.binaries[n] = response.arrayBuffer().then( function getModule(buf) { return new WebAssembly.Module(buf); } ); } else { - H.binaries[name] = response.arrayBuffer(); + H.binaries[n] = response.arrayBuffer(); } H.events.dispatch(m[0], {"msg": m[1]}); } @@ -337,17 +338,17 @@ * Get bin file using XHR * @param {string} p Where the script is stored * @param {string} f Filename of the script with extension + * @param {string} n Name of the ressource * @param {Object} m Message * @returns {undefined} */ - function requestBinary(p, f, m) { + function requestBinary(p, f, n, m) { if (!loadedBins[f]) { loadedBins[f] = true; const xhr = new XMLHttpRequest(); xhr.open("GET", p + f); xhr.onload = function onload() { - const name = f.slice(0, f.lastIndexOf(".")); - H.binaries[name] = xhr.response; + H.binaries[n] = xhr.response; H.events.dispatch(m[0], {"msg": m[1]}); }; xhr.responseType = "arraybuffer"; @@ -356,9 +357,9 @@ } if (H.clientFeat.wasm) { - fetchBinary(path, fne, msg); + fetchBinary(path, fne, name, msg); } else { - requestBinary(path, fne, msg); + requestBinary(path, fne, name, msg); } } @@ -415,6 +416,10 @@ * @returns {undefined} */ function loadRessources(lang) { + let filename = lang + ".hpb"; + if (H.fallbacks && H.fallbacks[lang]) { + filename = H.fallbacks[lang] + ".hpb"; + } if (!H.binaries) { H.binaries = empty(); } @@ -424,12 +429,13 @@ binLoader( H.paths.maindir, "hyphenEngine.wasm", + "hyphenEngine", ["engineLoaded", "wasm"] ); } else { scriptLoader(H.paths.maindir, "hyphenEngine.asm.js"); } - binLoader(H.paths.patterndir, lang + ".hpb", ["hpbLoaded", lang]); + binLoader(H.paths.patterndir, filename, lang, ["hpbLoaded", lang]); allocateMemory(lang); } diff --git a/README.md b/README.md index 81700a51..e6fde125 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Hyphenopoly.js -[![Build Status](https://travis-ci.org/mnater/Hyphenopoly.svg?branch=master)](https://travis-ci.org/mnater/Hyphenopoly) [![dependencies Status](https://david-dm.org/mnater/Hyphenopoly/status.svg)](https://david-dm.org/mnater/Hyphenopoly) [![devDependencies Status](https://david-dm.org/mnater/Hyphenopoly/dev-status.svg)](https://david-dm.org/mnater/Hyphenopoly?type=dev) [![Coverage Status](https://coveralls.io/repos/github/mnater/Hyphenopoly/badge.svg?branch=master)](https://coveralls.io/github/mnater/Hyphenopoly?branch=master) [![Try hyphenopoly on RunKit](https://badge.runkitcdn.com/hyphenopoly.svg)](https://npm.runkit.com/hyphenopoly) [![npms score](https://badges.npms.io/hyphenopoly.svg)](https://npms.io/search?q=hyphenopoly) +[![Build Status](https://travis-ci.org/mnater/Hyphenopoly.svg?branch=master)](https://travis-ci.org/mnater/Hyphenopoly) [![Coverage Status](https://coveralls.io/repos/github/mnater/Hyphenopoly/badge.svg?branch=master)](https://coveralls.io/github/mnater/Hyphenopoly?branch=master) [![dependencies Status](https://david-dm.org/mnater/Hyphenopoly/status.svg)](https://david-dm.org/mnater/Hyphenopoly) [![devDependencies Status](https://david-dm.org/mnater/Hyphenopoly/dev-status.svg)](https://david-dm.org/mnater/Hyphenopoly?type=dev) [![npms score](https://badges.npms.io/hyphenopoly.svg)](https://npms.io/search?q=hyphenopoly) Hyphenopoly.js is a __JavaScript-polyfill for hyphenation in HTML__: it hyphenates text if the user agent does not support CSS-hyphenation at all or not for the required languages and it is a __Node.js-module__. @@ -89,6 +89,7 @@ If the browser supports all required languages the script deletes the `Hyphenopo Hyphenopoly by default hyphenates elements (and their children) with the classname `.hyphenate`. Don't forget to enable CSS-hyphenation for the classes eventually handled by Hyphenopoly. # Usage (node) +[![Try hyphenopoly on RunKit](https://badge.runkitcdn.com/hyphenopoly.svg)](https://npm.runkit.com/hyphenopoly) Install: ```` diff --git a/hyphenEngine.asm.js b/hyphenEngine.asm.js index 55ed2223..ceef1f57 100644 --- a/hyphenEngine.asm.js +++ b/hyphenEngine.asm.js @@ -1,11 +1,12 @@ /** - * @license hyphenEngine.asm.js 2.3.0 - hyphenation for node and webbrowsers + * @license hyphenEngine.asm.js 2.4.0 - client side hyphenation for webbrowsers * ©2018 Mathias Nater, Zürich (mathiasnater at gmail dot com) * https://github.com/mnater/Hyphenopoly * * Released under the MIT license * http://mnater.github.io/Hyphenopoly/LICENSE */ + function asmHyphenEngine(std, ext, heap) { "use asm"; var ui8 = new std.Uint8Array(heap); diff --git a/hyphenopoly.module.js b/hyphenopoly.module.js index e18899fc..5e15198c 100644 --- a/hyphenopoly.module.js +++ b/hyphenopoly.module.js @@ -1,7 +1,7 @@ /** - * @license Hyphenopoly.module.js 2.3.0 - hyphenation for node - * ©2018 Mathias Nater, Zürich (mathiasnater at gmail dot com) - * https://github.com/mnater/Hyphenopoly + * @license Hyphenopoly.module.js 2.4.0 - hyphenation for node + * ©2018 Mathias Nater, Zürich (mathiasnater at gmail dot com) + * https://github.com/mnater/Hyphenopoly * * Released under the MIT license * http://mnater.github.io/Hyphenopoly/LICENSE diff --git a/package.json b/package.json index b636e19d..8a5b1fdc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hyphenopoly", - "version": "2.3.0", - "description": "Hyphenation for node and polyfill for client-side hyphenation.", + "version": "2.4.0", + "description": "Hyphenation for node and Polyfill for client-side hyphenation.", "keywords": [ "hyphenation", "html", @@ -40,9 +40,9 @@ }, "dependencies": {}, "devDependencies": { - "eslint": "^5.1.0", + "eslint": "^5.5.0", "tap": "^12.0.1", - "uglify-es": "^3.3.9" + "terser": "^3.8.2" }, "eslintConfig": { "parserOptions": { @@ -57,15 +57,19 @@ }, "extends": "eslint:all", "rules": { - "require-jsdoc": ["error", { + "require-unicode-regexp": 0, + "require-jsdoc": [ + "error", + { "require": { - "FunctionDeclaration": true, - "MethodDefinition": true, - "ClassDeclaration": true, - "ArrowFunctionExpression": true, - "FunctionExpression": true + "FunctionDeclaration": true, + "MethodDefinition": true, + "ClassDeclaration": true, + "ArrowFunctionExpression": true, + "FunctionExpression": true } - }], + } + ], "no-template-curly-in-string": 2, "prefer-template": 0, "wrap-iife": 1, diff --git a/patterns/th.hpb b/patterns/th.hpb index 2d8c58fb..af46b3c7 100644 Binary files a/patterns/th.hpb and b/patterns/th.hpb differ diff --git a/testsuite/test24.html b/testsuite/test24.html new file mode 100644 index 00000000..c398595d --- /dev/null +++ b/testsuite/test24.html @@ -0,0 +1,104 @@ + + +
+ +Hyphenate a text marked with lang 'en-au'. Hyphenopoly should use 'en-gb'-patterns.
+ +A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.
+A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.
+A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.
+A hyphenation algorithm is a set of rules that decides at which points a word can be broken over two lines with a hyphen.
+ +