1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
-
+
-
+
|
// JavaScript
/*jslint esversion: 6*/
/*global require,exports*/
"use strict";
if (typeof(require) !== 'undefined') {
var helpers = require("resource://grammalecte/helpers.js");
}
var text = {
getParagraph: function* (sText) {
getParagraph: function* (sText, sSepParagraph = "\n") {
// generator: returns paragraphs of text
let iStart = 0;
let iEnd = 0;
sText = sText.replace("\r\n", "\n").replace("\r", "\n");
while ((iEnd = sText.indexOf("\n", iStart)) !== -1) {
while ((iEnd = sText.indexOf(sSepParagraph, iStart)) !== -1) {
yield sText.slice(iStart, iEnd);
iStart = iEnd + 1;
}
yield sText.slice(iStart);
},
wrap: function* (sText, nWidth=80) {
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
-
+
|
}
yield sText;
},
getReadableError: function (oErr) {
// Returns an error oErr as a readable error
try {
let sResult = "\n* " + oErr['nStart'] + ":" + oErr['nEnd']
let sResult = "\n* " + oErr['nStart'] + ":" + oErr['nEnd']
+ " # " + oErr['sLineId'] + " # " + oErr['sRuleId'] + ":\n";
sResult += " " + oErr["sMessage"];
if (oErr["aSuggestions"].length > 0) {
sResult += "\n > Suggestions : " + oErr["aSuggestions"].join(" | ");
}
if (oErr["URL"] !== "") {
sResult += "\n > URL: " + oErr["URL"];
|