Index: gc_lang/fr/modules-js/textformatter.js ================================================================== --- gc_lang/fr/modules-js/textformatter.js +++ gc_lang/fr/modules-js/textformatter.js @@ -322,10 +322,62 @@ } else if (this.bDebug){ console.log("# Error. TF: there is no option “" + sRuleName+ "”."); } return [sText, nCount]; } + + removeHyphenAtEndOfParagraphs (sText) { + sText = sText.replace(/-[  ]*\n/gm, ""); + return sText; + } + + removeHyphenAtEndOfParagraphsCount (sText) { + let nCount = (sText.match(/-[  ]*\n/gm) || []).length; + sText = sText.replace(/-[  ]*\n/gm, ""); + return [sText, nCount]; + } + + mergeContiguousParagraphs (sText) { + sText = sText.replace(/^[  ]+$/gm, ""); // clear empty paragraphs + let s = ""; + for (let sParagraph of this.getParagraph(sText)) { + if (sParagraph === "") { + s += "\n"; + } else { + s += sParagraph + " "; + } + } + s = s.replace(/ +/gm, " ").replace(/ $/gm, ""); + return s; + } + + mergeContiguousParagraphsCount (sText) { + let nCount = 0; + sText = sText.replace(/^[  ]+$/gm, ""); // clear empty paragraphs + let s = ""; + for (let sParagraph of this.getParagraph(sText)) { + if (sParagraph === "") { + s += "\n"; + } else { + s += sParagraph + " "; + nCount += 1; + } + } + s = s.replace(/ +/gm, " ").replace(/ $/gm, ""); + return [s, nCount]; + } + + * getParagraph (sText, sSep="\n") { + // generator: returns paragraphs of text + let iStart = 0; + let iEnd = 0; + while ((iEnd = sText.indexOf(sSep, iStart)) !== -1) { + yield sText.slice(iStart, iEnd); + iStart = iEnd + 1; + } + yield sText.slice(iStart); + } getDefaultOptions () { //we return a copy to make sure they are no modification in external return dTFDefaultOptions.gl_shallowCopy(); } Index: gc_lang/fr/webext/content_scripts/panel_tf.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel_tf.js +++ gc_lang/fr/webext/content_scripts/panel_tf.js @@ -12,10 +12,13 @@ this.xPanelContent.appendChild(this.xTFNode); this.xTextArea = null; this.TextFormatter = new TextFormatter(); this.formatText = this.TextFormatter.formatTextRuleCount; + this.removeHyphenAtEndOfParagraphs = this.TextFormatter.removeHyphenAtEndOfParagraphsCount; + this.mergeContiguousParagraphs = this.TextFormatter.mergeContiguousParagraphsCount; + this.getParagraph = this.TextFormatter.getParagraph; } _createTextFormatter () { let xTFNode = document.createElement("div"); try { @@ -511,43 +514,10 @@ catch (e) { showError(e); } } - removeHyphenAtEndOfParagraphs (sText) { - let nCount = (sText.match(/-[  ]*\n/gm) || []).length; - sText = sText.replace(/-[  ]*\n/gm, ""); - return [sText, nCount]; - } - - mergeContiguousParagraphs (sText) { - let nCount = 0; - sText = sText.replace(/^[  ]+$/gm, ""); // clear empty paragraphs - let s = ""; - for (let sParagraph of this.getParagraph(sText)) { - if (sParagraph === "") { - s += "\n"; - } else { - s += sParagraph + " "; - nCount += 1; - } - } - s = s.replace(/ +/gm, " ").replace(/ $/gm, ""); - return [s, nCount]; - } - - * getParagraph (sText) { - // generator: returns paragraphs of text - let iStart = 0; - let iEnd = 0; - while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { - yield sText.slice(iStart, iEnd); - iStart = iEnd + 1; - } - yield sText.slice(iStart); - } - getTimeRes (n) { // returns duration in seconds as string if (n < 10) { return n.toFixed(3).toString() + " s"; }