From 46a30383942304202c7b87bfb4f41e329cef03e2 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 29 Dec 2017 23:37:17 +0300 Subject: [PATCH] don't add soft hyphens at the end of text --- js/localization.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/js/localization.js b/js/localization.js index 809f587b..b33c3c29 100644 --- a/js/localization.js +++ b/js/localization.js @@ -141,6 +141,16 @@ function tDocLoader() { return JSON.parse(localStorage.L10N); } catch (e) {} })() || {}; + t.RX_WORD_BREAK = new RegExp([ + '(', + /[\d\w\u007B-\uFFFF]{10}/, + '|', + /[\d\w\u007B-\uFFFF]{5,10}[!-/]/, + '|', + /((?!\s)\W){10}/, + ')', + /(?!\b|\s|$)/, + ].map(rx => rx.source || rx).join(''), 'g'); // reset L10N cache on UI language change const UIlang = chrome.i18n.getUILanguage(); @@ -195,9 +205,10 @@ function tDocLoader() { function tWordBreak(text) { // adds soft hyphens every 10 characters to ensure the long words break before breaking the layout return text.length <= 10 ? text : - text.replace(/([\d\w\u007B-\uFFFF]{10}|[\d\w\u007B-\uFFFF]{5,10}[!-/]|((?!\s)\W){10})(?!\b|\s)/g, '$&\u00AD'); + text.replace(t.RX_WORD_BREAK, '$&\u00AD'); } + function formatDate(date) { return !date ? '' : tryCatch(() => { const newDate = new Date(Number(date) || date);