@ohos-ports/advanced-mark.js 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +107 -0
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/jquery.mark.d.ts +235 -0
- package/dist/jquery.mark.es6.d.ts +235 -0
- package/dist/jquery.mark.es6.js +1281 -0
- package/dist/jquery.mark.es6.min.js +8 -0
- package/dist/jquery.mark.js +1681 -0
- package/dist/jquery.mark.min.js +8 -0
- package/dist/mark.d.ts +210 -0
- package/dist/mark.es6.d.ts +210 -0
- package/dist/mark.es6.js +1284 -0
- package/dist/mark.es6.min.js +8 -0
- package/dist/mark.js +1682 -0
- package/dist/mark.min.js +8 -0
- package/package.json +72 -0
- package/src/jquery.js +24 -0
- package/src/jquery_es6.js +23 -0
- package/src/lib/domiterator.js +419 -0
- package/src/lib/mark.js +1817 -0
- package/src/lib/regexpcreator.js +397 -0
- package/src/types/jquery.mark.d.ts +235 -0
- package/src/types/mark.d.ts +210 -0
- package/src/vanilla.js +25 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates regular expressions based on specified settings
|
|
3
|
+
* @example
|
|
4
|
+
* new RegExpCreator({caseSensitive: true, diacritics: false}).create('lorem');
|
|
5
|
+
* // => /()(lorem)/gm
|
|
6
|
+
*/
|
|
7
|
+
class RegExpCreator {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef RegExpCreator~accuracyObj
|
|
11
|
+
* @type {object.<string>}
|
|
12
|
+
* @property {string} value - An accuracy string value
|
|
13
|
+
* @property {string[]} limiters - A custom array of limiters. For example
|
|
14
|
+
* <code>["-", ","]</code>
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef RegExpCreator~accuracy
|
|
18
|
+
* @type {string}
|
|
19
|
+
* @property {"partially"|"complementary"|"exactly"|RegExpCreator~accuracyObj}
|
|
20
|
+
* [accuracy="partially"] - Either one of the following string values:
|
|
21
|
+
* <ul>
|
|
22
|
+
* <li><i>partially</i>: When searching for "lor" only "lor" inside
|
|
23
|
+
* "lorem" will be marked</li>
|
|
24
|
+
* <li><i>complementary</i>: When searching for "lor" the whole word
|
|
25
|
+
* "lorem" will be marked</li>
|
|
26
|
+
* <li><i>exactly</i>: When searching for "lor" only those exact words
|
|
27
|
+
* will be marked. In this example nothing inside "lorem".
|
|
28
|
+
* </ul>
|
|
29
|
+
* Or an object containing two properties:
|
|
30
|
+
* <ul>
|
|
31
|
+
* <li><i>value</i>: The value must be "exactly" or "complementary" or "startsWith"</li>
|
|
32
|
+
* <li><i>limiters</i>: A custom array of string limiters</li>
|
|
33
|
+
* </ul>
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* @typedef RegExpCreator~wildcards
|
|
37
|
+
* @type {string}
|
|
38
|
+
* @property {"disabled"|"enabled"|"withSpaces"}
|
|
39
|
+
* [wildcards="disabled"] - Set to any of the following string values:
|
|
40
|
+
* <ul>
|
|
41
|
+
* <li><i>disabled</i>: Disable wildcard usage</li>
|
|
42
|
+
* <li><i>enabled</i>: When searching for "lor?m", the "?" will match zero
|
|
43
|
+
* or one non-space character (e.g. "lorm", "loram", "lor3m", etc). When
|
|
44
|
+
* searching for "lor*m", the "*" will match zero or more non-space
|
|
45
|
+
* characters (e.g. "lorm", "loram", "lor123m", etc).</li>
|
|
46
|
+
* <li><i>withSpaces</i>: When searching for "lor?m", the "?" will
|
|
47
|
+
* match zero or one space or non-space character (e.g. "lor m", "loram",
|
|
48
|
+
* etc). When searching for "lor*m", the "*" will match zero or more space
|
|
49
|
+
* or non-space characters (e.g. "lorm", "lore et dolor ipsum", "lor: m",
|
|
50
|
+
* etc).</li>
|
|
51
|
+
* </ul>
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* @typedef RegExpCreator~ignorePunctuation
|
|
55
|
+
* @type {string[]}
|
|
56
|
+
* @property {string} The strings in this setting will contain punctuation
|
|
57
|
+
* marks that will be ignored:
|
|
58
|
+
* <ul>
|
|
59
|
+
* <li>These punctuation marks can be between any characters, e.g. setting
|
|
60
|
+
* this option to <code>["'"]</code> would match "Worlds", "World's" and
|
|
61
|
+
* "Wo'rlds"</li>
|
|
62
|
+
* <li>One or more apostrophes between the letters would still produce a
|
|
63
|
+
* match (e.g. "W'o''r'l'd's").</li>
|
|
64
|
+
* <li>A typical setting for this option could be as follows:
|
|
65
|
+
* <pre>ignorePunctuation: ":;.,-–—‒_(){}[]!'\"+=".split(""),</pre> This
|
|
66
|
+
* setting includes common punctuation as well as a minus, en-dash,
|
|
67
|
+
* em-dash and figure-dash
|
|
68
|
+
* ({@link https://en.wikipedia.org/wiki/Dash#Figure_dash ref}), as well
|
|
69
|
+
* as an underscore.</li>
|
|
70
|
+
* </ul>
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @typedef RegExpCreator~options
|
|
75
|
+
* @type {object.<string>}
|
|
76
|
+
* @property {boolean} [diacritics=true] - If diacritic characters should be
|
|
77
|
+
* matched. ({@link https://en.wikipedia.org/wiki/Diacritic Diacritics})
|
|
78
|
+
* @property {object.<string|string[]>} [synonyms] - An object with synonyms.
|
|
79
|
+
* The key will be a synonym for the value and the value for the key
|
|
80
|
+
* @property {RegExpCreator~accuracy} [accuracy]
|
|
81
|
+
* @property {boolean} [caseSensitive=false] - Whether to search case sensitive
|
|
82
|
+
* @property {boolean} [ignoreJoiners=false] - Whether to ignore word
|
|
83
|
+
* joiners inside of key words. These include soft-hyphens, zero-width
|
|
84
|
+
* space, zero-width non-joiners and zero-width joiners.
|
|
85
|
+
* @property {RegExpCreator~ignorePunctuation} [ignorePunctuation]
|
|
86
|
+
* @property {RegExpCreator~wildcards} [wildcards]
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* @typedef RegExpCreator~patternObj
|
|
90
|
+
* @type {object}
|
|
91
|
+
* @property {string} lookbehind - A lookbehind capturing group
|
|
92
|
+
* @property {string} pattern - A string pattern
|
|
93
|
+
* @property {string} lookahead - A positive lookahead assertion
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* @param {RegExpCreator~options} [options] - Optional options object
|
|
97
|
+
*/
|
|
98
|
+
constructor(options) {
|
|
99
|
+
this.opt = Object.assign({}, {
|
|
100
|
+
'diacritics': true,
|
|
101
|
+
'synonyms': {},
|
|
102
|
+
'accuracy': 'partially',
|
|
103
|
+
'caseSensitive': false,
|
|
104
|
+
'ignoreJoiners': false,
|
|
105
|
+
'ignorePunctuation': [],
|
|
106
|
+
'wildcards': 'disabled'
|
|
107
|
+
}, options);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The array with lower and upper cases diacritics characters
|
|
112
|
+
* @type {string[]}
|
|
113
|
+
* @access protected
|
|
114
|
+
*/
|
|
115
|
+
get chars() {
|
|
116
|
+
if ( !this._chars) {
|
|
117
|
+
this._chars = [];
|
|
118
|
+
// initialises an array with lower and upper cases diacritics characters
|
|
119
|
+
['aàáảãạăằắẳẵặâầấẩẫậäåāą', 'cçćč', 'dđď', 'eèéẻẽẹêềếểễệëěēę',
|
|
120
|
+
'iìíỉĩịîïī', 'lł', 'nñňń', 'oòóỏõọôồốổỗộơởỡớờợöøōő', 'rř',
|
|
121
|
+
'sšśșş', 'tťțţ', 'uùúủũụưừứửữựûüůūű', 'yýỳỷỹỵÿ', 'zžżź'].forEach(str => {
|
|
122
|
+
this._chars.push(str, str.toUpperCase());
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return this._chars;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Creates a regular expression to match the specified search term considering
|
|
130
|
+
* the available option settings
|
|
131
|
+
* @param {string} str - The search term to be used
|
|
132
|
+
* @return {RegExp}
|
|
133
|
+
*/
|
|
134
|
+
create(terms) {
|
|
135
|
+
const flags = `g${this.opt.caseSensitive ? '' : 'i'}`;
|
|
136
|
+
|
|
137
|
+
terms = terms.map(str => {
|
|
138
|
+
// wraps an individual term pattern in a capturing group; that allows to determine
|
|
139
|
+
// in filter callback which term is currently matched
|
|
140
|
+
return '(' + this.createPattern(str, flags) + ')';
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const obj = this.createAccuracy(terms.join('|'));
|
|
144
|
+
|
|
145
|
+
return new RegExp(`${obj.lookbehind}(${obj.pattern})${obj.lookahead}`, flags);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
createPattern(str, flags) {
|
|
149
|
+
str = this.checkWildcardsEscape(str);
|
|
150
|
+
str = this.createSynonyms(str, flags);
|
|
151
|
+
|
|
152
|
+
const joiners = this.getJoinersPunctuation();
|
|
153
|
+
|
|
154
|
+
if (joiners) {
|
|
155
|
+
str = this.setupIgnoreJoiners(str);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (this.opt.diacritics) {
|
|
159
|
+
str = this.createDiacritics(str);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
str = str.replace(/\s+/g, '[\\s]+');
|
|
163
|
+
|
|
164
|
+
if (joiners) {
|
|
165
|
+
str = this.createJoiners(str, joiners);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (this.opt.wildcards !== 'disabled') {
|
|
169
|
+
str = this.createWildcards(str);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return str;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Escapes the RegExp special characters
|
|
177
|
+
* @param {string} str - The string to escape
|
|
178
|
+
* @return {string}
|
|
179
|
+
*/
|
|
180
|
+
escape(str) {
|
|
181
|
+
return str.replace(/[[\]/{}()*+?.\\^$|]/g, '\\$&');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Splits val if it is a string, removes duplicates, escape '-^]\\' which are special in the RegExp characters set
|
|
186
|
+
* @param {array|string} val - The parameter to process
|
|
187
|
+
* @return {string}
|
|
188
|
+
*/
|
|
189
|
+
preprocess(val) {
|
|
190
|
+
if (val && val.length) {
|
|
191
|
+
return this.distinct(typeof val === 'string' ? val.split('') : val).join('').replace(/[-^\]\\]/g, '\\$&');
|
|
192
|
+
}
|
|
193
|
+
return '';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Removes duplicate or empty entries
|
|
198
|
+
* @param {array} array - The array to process
|
|
199
|
+
* @return {array}
|
|
200
|
+
*/
|
|
201
|
+
distinct(array) {
|
|
202
|
+
const result = [];
|
|
203
|
+
array.forEach(item => {
|
|
204
|
+
if (item.trim() && !result.includes(item)) {
|
|
205
|
+
result.push(item);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Creates a regular expression string to match the defined synonyms
|
|
213
|
+
* @param {string} str - The search term to be used
|
|
214
|
+
* @return {string}
|
|
215
|
+
*/
|
|
216
|
+
createSynonyms(str, flags) {
|
|
217
|
+
const syn = this.opt.synonyms;
|
|
218
|
+
|
|
219
|
+
for (const key in syn) {
|
|
220
|
+
if (syn.hasOwnProperty(key)) {
|
|
221
|
+
let array = Array.isArray(syn[key]) ? syn[key] : [syn[key]];
|
|
222
|
+
array.unshift(key);
|
|
223
|
+
array = this.distinct(array);
|
|
224
|
+
|
|
225
|
+
if (array.length > 1) {
|
|
226
|
+
array.sort((a, b) => b.length - a.length);
|
|
227
|
+
array = array.map(term => this.checkWildcardsEscape(term));
|
|
228
|
+
|
|
229
|
+
const pattern = array.map(term => this.escape(term)).join('|');
|
|
230
|
+
str = str.replace(new RegExp(pattern, flags), `(?:${array.join('|')})`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return str;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Check wildcards option creates placeholders in the regular expression string to allow later
|
|
239
|
+
* insertion of wildcard patterns and escapes RegExp special characters
|
|
240
|
+
* @param {string} str - The search term
|
|
241
|
+
* @return {string}
|
|
242
|
+
*/
|
|
243
|
+
checkWildcardsEscape(str) {
|
|
244
|
+
if (this.opt.wildcards !== 'disabled') {
|
|
245
|
+
// replaces single character wildcard with \x01, multiple character wildcard with \x02
|
|
246
|
+
str = str.replace(/(\\.)+|[?*]/g, (m, gr) => gr ? m : m === '?' ? '\x01' : '\x02')
|
|
247
|
+
// removes one backslash character before '?', '*', '\x01', and '\x02'
|
|
248
|
+
.replace(/\\(?=[?*\x01\x02])/g, '');
|
|
249
|
+
}
|
|
250
|
+
return this.escape(str);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Replaces the wildcard placeholders in a regular expression string
|
|
255
|
+
* @param {string} str - The search term to be used
|
|
256
|
+
* @return {string}
|
|
257
|
+
*/
|
|
258
|
+
createWildcards(str) {
|
|
259
|
+
// default to "enable" (i.e. to not include spaces)
|
|
260
|
+
// "withSpaces" uses `[^]` instead of `.` because the latter does not match new line characters
|
|
261
|
+
// or `[^\x01]` if blockElementsBoundary option is enabled
|
|
262
|
+
const spaces = this.opt.wildcards === 'withSpaces',
|
|
263
|
+
boundary = this.opt.blockElementsBoundary,
|
|
264
|
+
anyChar = `[^${spaces && boundary ? '\x01' : ''}]*?`;
|
|
265
|
+
|
|
266
|
+
return str
|
|
267
|
+
// replace \x01 with a RegExp class to match any single
|
|
268
|
+
// character, or any single non-whitespace character depending
|
|
269
|
+
// on the setting
|
|
270
|
+
.replace(/\x01/g, spaces ? '[^]?' : '\\S?')
|
|
271
|
+
// replace \x02 with a RegExp class to match zero or
|
|
272
|
+
// more characters, or zero or more non-whitespace characters
|
|
273
|
+
// depending on the setting
|
|
274
|
+
.replace(/\x02/g, spaces ? anyChar : '\\S*');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Creates placeholders in the regular expression string to allow later insertion of
|
|
279
|
+
* designated characters (soft hyphens, zero width characters, and punctuation)
|
|
280
|
+
* @param {string} str - The search term to be used
|
|
281
|
+
* @return {string}
|
|
282
|
+
*/
|
|
283
|
+
setupIgnoreJoiners(str) {
|
|
284
|
+
// it's not added '\0' after `(?:` grouping construct, around `|` char and wildcard `\x02` placeholder,
|
|
285
|
+
// before `)` char, and at the end of a string,
|
|
286
|
+
// not breaks the grouping construct `(?:`, continues pairs of backslashes, and UTF-16 surrogate pairs
|
|
287
|
+
const reg = /((?:\\\\)+|\x02|\(\?:|\|)|\\?(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|.)(?=([|)\x02]|$)|.)/g;
|
|
288
|
+
return str.replace(reg, (m, gr1, gr2) => {
|
|
289
|
+
return gr1 || typeof gr2 !== 'undefined' ? m : m + '\x00';
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Replaces '\x00' placeholders in a regular expression string by designated
|
|
295
|
+
* characters (soft hyphens, zero width characters, and punctuation) based on the
|
|
296
|
+
* specified option values of <code>ignorePunctuation</code> and
|
|
297
|
+
* <code>ignoreJoiners</code>
|
|
298
|
+
* @param {string} str - The search term to be used
|
|
299
|
+
* @return {string}
|
|
300
|
+
*/
|
|
301
|
+
createJoiners(str, joiners) {
|
|
302
|
+
return str.split(/\x00+/).join(`[${joiners}]*`);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Creates a punctuation and/or joiners pattern
|
|
307
|
+
* @return {string}
|
|
308
|
+
*/
|
|
309
|
+
getJoinersPunctuation() {
|
|
310
|
+
let punct = this.preprocess(this.opt.ignorePunctuation),
|
|
311
|
+
str = punct ? punct : '';
|
|
312
|
+
|
|
313
|
+
if (this.opt.ignoreJoiners) {
|
|
314
|
+
// u+00ad = soft hyphen
|
|
315
|
+
// u+200b = zero-width space
|
|
316
|
+
// u+200c = zero-width non-joiner
|
|
317
|
+
// u+200d = zero-width joiner
|
|
318
|
+
str += '\\u00ad\\u200b\\u200c\\u200d';
|
|
319
|
+
}
|
|
320
|
+
return str;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Creates a regular expression string to match diacritics
|
|
325
|
+
* @param {string} str - The search term to be used
|
|
326
|
+
* @return {string}
|
|
327
|
+
*/
|
|
328
|
+
createDiacritics(str) {
|
|
329
|
+
const array = this.chars;
|
|
330
|
+
|
|
331
|
+
return str.split('').map(ch => {
|
|
332
|
+
for (let i = 0; i < array.length; i += 2) {
|
|
333
|
+
const lowerCase = array[i].includes(ch);
|
|
334
|
+
|
|
335
|
+
if (this.opt.caseSensitive) {
|
|
336
|
+
if (lowerCase) {
|
|
337
|
+
return '[' + array[i] + ']';
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
if (array[i+1].includes(ch)) {
|
|
341
|
+
return '[' + array[i+1] + ']';
|
|
342
|
+
}
|
|
343
|
+
} else if (lowerCase || array[i+1].includes(ch)) {
|
|
344
|
+
return '[' + array[i] + array[i+1] + ']';
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return ch;
|
|
348
|
+
}).join('');
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Creates a regular expression string to match the specified string with the
|
|
353
|
+
* defined accuracy. All regular expressions created with two capturing groups.
|
|
354
|
+
* The first group is ignored (serves as lookbehind with values 'exactly' and 'startsWith'),
|
|
355
|
+
* the second is contained the actual match
|
|
356
|
+
* @param {string} str - The search term to be used
|
|
357
|
+
* @return {RegExpCreator~patternObj}
|
|
358
|
+
*/
|
|
359
|
+
createAccuracy(str) {
|
|
360
|
+
// '!"#$%&\'()*+,\\-./:;<=>?@[\\]\\\\^_`{|}~¡¿';
|
|
361
|
+
const chars = '!-/:-@[-`{-~¡¿';
|
|
362
|
+
let accuracy = this.opt.accuracy,
|
|
363
|
+
lookbehind = '()',
|
|
364
|
+
pattern = str,
|
|
365
|
+
lookahead = '',
|
|
366
|
+
limiters;
|
|
367
|
+
|
|
368
|
+
if (accuracy !== 'partially') {
|
|
369
|
+
if (typeof accuracy !== 'string') {
|
|
370
|
+
limiters = this.preprocess(accuracy.limiters);
|
|
371
|
+
accuracy = accuracy.value;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (accuracy === 'exactly') {
|
|
375
|
+
const charSet = limiters ? '[\\s' + limiters + ']' : '\\s';
|
|
376
|
+
lookbehind = `(^|${charSet})`;
|
|
377
|
+
lookahead = `(?=$|${charSet})`;
|
|
378
|
+
|
|
379
|
+
} else {
|
|
380
|
+
const chs = limiters || chars,
|
|
381
|
+
charSet = `[^\\s${chs}]*`;
|
|
382
|
+
pattern = `(?:${str})`;
|
|
383
|
+
|
|
384
|
+
if (accuracy === 'complementary') {
|
|
385
|
+
pattern = charSet + pattern + charSet;
|
|
386
|
+
|
|
387
|
+
} else if (accuracy === 'startsWith') {
|
|
388
|
+
lookbehind = `(^|[\\s${chs}])`;
|
|
389
|
+
pattern = pattern.split(/\[\\s\]\+/).join(charSet + '[\\s]+') + charSet;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return { lookbehind, pattern, lookahead };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export default RegExpCreator;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
|
|
2
|
+
// Type definitions for advanced-mark.js v1.1.0
|
|
3
|
+
// Based on "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mark.js"
|
|
4
|
+
|
|
5
|
+
/// <reference types="jquery"/>
|
|
6
|
+
|
|
7
|
+
declare namespace Mark {
|
|
8
|
+
|
|
9
|
+
interface BoundaryObject {
|
|
10
|
+
tags?: string[];
|
|
11
|
+
extend?: boolean;
|
|
12
|
+
char?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ShadowObject {
|
|
16
|
+
style: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface IframesObject {
|
|
20
|
+
style: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface AccuracyObject {
|
|
24
|
+
value: 'exactly' | 'startsWith' | 'complementary';
|
|
25
|
+
limiters: string | string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface MarkOptions {
|
|
29
|
+
element?: string;
|
|
30
|
+
window?: Window;
|
|
31
|
+
className?: string;
|
|
32
|
+
exclude?: string | string[];
|
|
33
|
+
separateWordSearch?: boolean | 'preserveTerms';
|
|
34
|
+
acrossElements?: boolean;
|
|
35
|
+
accuracy?: 'partially' | 'exactly' | 'startsWith' | 'complementary' | AccuracyObject;
|
|
36
|
+
diacritics?: boolean;
|
|
37
|
+
synonyms?: { [index: string] : string | string[] };
|
|
38
|
+
caseSensitive?: boolean;
|
|
39
|
+
ignoreJoiners?: boolean;
|
|
40
|
+
ignorePunctuation?: string | string[];
|
|
41
|
+
wildcards?: 'disabled' | 'enabled' | 'withSpaces';
|
|
42
|
+
iframes?: boolean | IframesObject;
|
|
43
|
+
iframesTimeout?: number;
|
|
44
|
+
|
|
45
|
+
highlight?: Highlight;
|
|
46
|
+
highlightName?: string;
|
|
47
|
+
staticRanges?: boolean;
|
|
48
|
+
rangeAcrossElements?: boolean;
|
|
49
|
+
combineby?: number;
|
|
50
|
+
blockElementsBoundary?: boolean | BoundaryObject;
|
|
51
|
+
shadowDOM?: boolean | ShadowObject;
|
|
52
|
+
|
|
53
|
+
filter?(
|
|
54
|
+
nodeOrArray: Text | Text[], term: string, totalMatchesSoFar: number, termMatchesSoFar: number, filterInfo: MarkFilterInfo
|
|
55
|
+
) : boolean;
|
|
56
|
+
each?(elementOrRange: Element | StaticRange | Range, eachInfo: MarkEachInfo) : void;
|
|
57
|
+
done?(totalMarks: number, totalMatches: number, termStats: TermStats) : void;
|
|
58
|
+
|
|
59
|
+
noMatch?(term: string[]) : void;
|
|
60
|
+
debug?: boolean;
|
|
61
|
+
log?: object;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface MarkFilterInfo {
|
|
65
|
+
match: RegExpExecArray;
|
|
66
|
+
matchStart?: boolean;
|
|
67
|
+
count: number;
|
|
68
|
+
abort: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface MarkEachInfo {
|
|
72
|
+
match: RegExpExecArray;
|
|
73
|
+
matchStart?: boolean;
|
|
74
|
+
count: number;
|
|
75
|
+
abort: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface TermStats {
|
|
79
|
+
[index: string] : number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface RegExpOptions {
|
|
83
|
+
element?: string;
|
|
84
|
+
className?: string;
|
|
85
|
+
exclude?: string | string[];
|
|
86
|
+
acrossElements?: boolean;
|
|
87
|
+
ignoreGroups?: number;
|
|
88
|
+
iframes?: boolean | IframesObject;
|
|
89
|
+
iframesTimeout?: number;
|
|
90
|
+
|
|
91
|
+
highlight?: Highlight;
|
|
92
|
+
highlightName?: string;
|
|
93
|
+
staticRanges?: boolean;
|
|
94
|
+
rangeAcrossElements?: boolean;
|
|
95
|
+
separateGroups?: boolean;
|
|
96
|
+
wrapAllRanges?: boolean;
|
|
97
|
+
blockElementsBoundary?: boolean | BoundaryObject;
|
|
98
|
+
shadowDOM?: boolean | ShadowObject;
|
|
99
|
+
|
|
100
|
+
filter?(nodeOrArray: Text | Text[], regexp: string, matchesSoFar: number, filterInfo: RegExpFilterInfo) : boolean;
|
|
101
|
+
each?(elementOrRange: Element | StaticRange | Range, eachInfo: RegExpEachInfo) : void;
|
|
102
|
+
done?(totalMarks: number, totalMatches: number) : void;
|
|
103
|
+
|
|
104
|
+
noMatch?(regexp: string) : void;
|
|
105
|
+
debug?: boolean;
|
|
106
|
+
log?: object;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface RegExpFilterInfo {
|
|
110
|
+
match: RegExpExecArray;
|
|
111
|
+
matchStart?: boolean;
|
|
112
|
+
count: number;
|
|
113
|
+
groupIndex?: number;
|
|
114
|
+
abort: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface RegExpEachInfo {
|
|
118
|
+
match: RegExpExecArray;
|
|
119
|
+
matchStart?: boolean;
|
|
120
|
+
count: number;
|
|
121
|
+
groupIndex?: number;
|
|
122
|
+
groupStart?: boolean;
|
|
123
|
+
abort: boolean;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface RangesOptions {
|
|
127
|
+
element?: string;
|
|
128
|
+
className?: string;
|
|
129
|
+
exclude?: string | string[];
|
|
130
|
+
iframes?: boolean | IframesObject;
|
|
131
|
+
iframesTimeout?: number;
|
|
132
|
+
|
|
133
|
+
highlight?: Highlight;
|
|
134
|
+
highlightName?: string;
|
|
135
|
+
staticRanges?: boolean;
|
|
136
|
+
rangeAcrossElements?: boolean;
|
|
137
|
+
wrapAllRanges?: boolean;
|
|
138
|
+
markLines?: boolean;
|
|
139
|
+
shadowDOM?: boolean | ShadowObject;
|
|
140
|
+
|
|
141
|
+
filter?(nodeOrArray: Text | Text[], range: MarkRange, matchingString: string, currentIndex: number) : boolean;
|
|
142
|
+
each?(elementOrRange: Element | StaticRange | Range, range: MarkRange, eachInfo: RangeEachInfo) : void;
|
|
143
|
+
done?(totalMarks: number, totalRanges: number) : void;
|
|
144
|
+
|
|
145
|
+
noMatch?(range: MarkRange) : void;
|
|
146
|
+
debug?: boolean;
|
|
147
|
+
log?: object;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface MarkRange {
|
|
151
|
+
start: number;
|
|
152
|
+
length: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface RangeEachInfo {
|
|
156
|
+
matchStart?: boolean;
|
|
157
|
+
count: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface UnmarkOptions {
|
|
161
|
+
element?: string;
|
|
162
|
+
className?: string;
|
|
163
|
+
exclude?: string | string[];
|
|
164
|
+
iframes?: boolean | IframesObject;
|
|
165
|
+
iframesTimeout?: number;
|
|
166
|
+
shadowDOM?: boolean;
|
|
167
|
+
highlight?: Highlight;
|
|
168
|
+
highlightName?: string | string[];
|
|
169
|
+
|
|
170
|
+
done?() : void;
|
|
171
|
+
debug?: boolean;
|
|
172
|
+
log?: object;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare class Mark {
|
|
177
|
+
constructor(context: string | HTMLElement | ReadonlyArray<HTMLElement> | NodeList | null);
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Highlights the specified search terms.
|
|
181
|
+
* @param term The string to be marked. Can also be an array with multiple strings.
|
|
182
|
+
* Note that keywords will be escaped. If you need to mark unescaped keywords (e.g. containing a pattern),
|
|
183
|
+
* have a look at the `markRegExp()`
|
|
184
|
+
* @param options Optional options
|
|
185
|
+
*/
|
|
186
|
+
mark(term: string | ReadonlyArray<string>, options?: Mark.MarkOptions) : void;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Highlights a custom regular expression.
|
|
190
|
+
* @param regexp The regular expression to be marked. Example: /Lor[^]?m/gmi.
|
|
191
|
+
* Note that the `g` flag must be present when `acrossElements : true`, otherwise the RegExp is recompiled.
|
|
192
|
+
* @param options Optional options
|
|
193
|
+
*/
|
|
194
|
+
markRegExp(regexp: RegExp, options?: Mark.RegExpOptions) : void;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* A method to mark ranges with a start position and length. They will be applied
|
|
198
|
+
* to text nodes in the specified context.
|
|
199
|
+
* @param ranges An array of objects with a start and length property.
|
|
200
|
+
* Note that the start positions must be specified including whitespace characters.
|
|
201
|
+
* @param options Optional options
|
|
202
|
+
*/
|
|
203
|
+
markRanges(ranges: ReadonlyArray<Mark.MarkRange>, options?: Mark.RangesOptions) : void;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* A method to remove mark elements created by mark.js and normalize text nodes.
|
|
207
|
+
* @param options Optional options
|
|
208
|
+
*/
|
|
209
|
+
unmark(options?: Mark.UnmarkOptions) : void;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export = Mark;
|
|
213
|
+
|
|
214
|
+
/* augment JQuery */
|
|
215
|
+
declare global {
|
|
216
|
+
interface JQuery {
|
|
217
|
+
mark(term: string | ReadonlyArray<string>, options?: Mark.MarkOptions) : void;
|
|
218
|
+
|
|
219
|
+
markRegExp(regexp: RegExp, options?: Mark.RegExpOptions) : void;
|
|
220
|
+
|
|
221
|
+
markRanges(ranges: ReadonlyArray<Mark.MarkRange>, options?: Mark.RangesOptions) : void;
|
|
222
|
+
|
|
223
|
+
unmark(options?: Mark.UnmarkOptions) : void;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface JQueryStatic {
|
|
227
|
+
mark(term: string | ReadonlyArray<string>, options?: Mark.MarkOptions) : void;
|
|
228
|
+
|
|
229
|
+
markRegExp(regexp: RegExp, options?: Mark.RegExpOptions) : void;
|
|
230
|
+
|
|
231
|
+
markRanges(ranges: ReadonlyArray<Mark.MarkRange>, options?: Mark.RangesOptions) : void;
|
|
232
|
+
|
|
233
|
+
unmark(options?: Mark.UnmarkOptions) : void;
|
|
234
|
+
}
|
|
235
|
+
}
|