1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
// JavaScript
// Text formatter
"use strict";
class GrammalecteTextFormatter extends GrammalectePanel {
constructor (...args) {
super(...args);
this.xTFNode = this._createTextFormatter();
this.xPanelContent.appendChild(this.xTFNode);
this.xTextArea = null;
}
_createTextFormatter () {
let xTFNode = document.createElement("div");
try {
// Options
let xOptions = oGrammalecte.createNode("div", {id: "grammalecte_tf_options"});
|
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
// JavaScript
// Text formatter
"use strict";
class GrammalecteTextFormatter extends GrammalectePanel {
constructor (...args) {
super(...args);
this.xTFNode = this._createTextFormatter();
this.xPanelContent.appendChild(this.xTFNode);
this.xTextArea = null;
this.TextFormatter = new TextFormatter();
this.formatText = this.TextFormatter.formatTextRuleCount;
}
_createTextFormatter () {
let xTFNode = document.createElement("div");
try {
// Options
let xOptions = oGrammalecte.createNode("div", {id: "grammalecte_tf_options"});
|
︙ | | | ︙ | |
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
_createOrdinalOptions () {
let xLine = oGrammalecte.createNode("div", {className: "grammalecte_tf_blockopt grammalecte_tf_underline"});
xLine.appendChild(this._createOption("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)"));
xLine.appendChild(this._createOption("o_ordinals_exponant", true, "e → ᵉ"));
xLine.appendChild(oGrammalecte.createNode("div", {id: "res_"+"o_ordinals_no_exponant", className: "grammalecte_tf_result", textContent: "·"}));
return xLine;
}
/*
Actions
*/
start (xNode) {
if (xNode !== null && xNode.tagName == "TEXTAREA") {
this.xTextArea = xNode;
if (bChrome) {
|
|
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
_createOrdinalOptions () {
let xLine = oGrammalecte.createNode("div", {className: "grammalecte_tf_blockopt grammalecte_tf_underline"});
xLine.appendChild(this._createOption("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)"));
xLine.appendChild(this._createOption("o_ordinals_exponant", true, "e → ᵉ"));
xLine.appendChild(oGrammalecte.createNode("div", {id: "res_"+"o_ordinals_no_exponant", className: "grammalecte_tf_result", textContent: "·"}));
return xLine;
}
/*
Actions
*/
start (xNode) {
if (xNode !== null && xNode.tagName == "TEXTAREA") {
this.xTextArea = xNode;
if (bChrome) {
|
︙ | | | ︙ | |
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
try {
const t0 = Date.now();
//window.setCursor("wait"); // change pointer
this.resetProgressBar();
let sText = this.xTextArea.value.normalize("NFC");
document.getElementById('grammalecte_tf_progressbar').max = 7;
let n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0;
// Restructuration
if (this.isSelected("o_group_struct")) {
if (this.isSelected("o_remove_hyphens_at_end_of_paragraphs")) {
[sText, n1] = this.removeHyphenAtEndOfParagraphs(sText);
document.getElementById('res_o_remove_hyphens_at_end_of_paragraphs').textContent = n1;
}
if (this.isSelected("o_merge_contiguous_paragraphs")) {
|
|
|
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
try {
const t0 = Date.now();
//window.setCursor("wait"); // change pointer
this.resetProgressBar();
let sText = this.xTextArea.value.normalize("NFC");
document.getElementById('grammalecte_tf_progressbar').max = 7;
let n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0;
// Restructuration
if (this.isSelected("o_group_struct")) {
if (this.isSelected("o_remove_hyphens_at_end_of_paragraphs")) {
[sText, n1] = this.removeHyphenAtEndOfParagraphs(sText);
document.getElementById('res_o_remove_hyphens_at_end_of_paragraphs').textContent = n1;
}
if (this.isSelected("o_merge_contiguous_paragraphs")) {
|
︙ | | | ︙ | |
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
|
this.xTextArea.value = sText;
}
catch (e) {
showError(e);
}
}
formatText (sText, sOptName) {
let nCount = 0;
try {
if (!oReplTable.hasOwnProperty(sOptName)) {
console.log("# Error. TF: there is no option “" + sOptName+ "”.");
return [sText, nCount];
}
for (let [zRgx, sRep] of oReplTable[sOptName]) {
nCount += (sText.match(zRgx) || []).length;
sText = sText.replace(zRgx, sRep);
}
}
catch (e) {
showError(e);
}
return [sText, nCount];
}
removeHyphenAtEndOfParagraphs (sText) {
let nCount = (sText.match(/-[ ]*\n/gm) || []).length;
sText = sText.replace(/-[ ]*\n/gm, "");
return [sText, nCount];
}
mergeContiguousParagraphs (sText) {
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
this.xTextArea.value = sText;
}
catch (e) {
showError(e);
}
}
removeHyphenAtEndOfParagraphs (sText) {
let nCount = (sText.match(/-[ ]*\n/gm) || []).length;
sText = sText.replace(/-[ ]*\n/gm, "");
return [sText, nCount];
}
mergeContiguousParagraphs (sText) {
|
︙ | | | ︙ | |