@qubit-ltd/json 1.2.2 → 1.2.3

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.
Files changed (37) hide show
  1. package/dist/json.cjs +188 -20
  2. package/dist/json.cjs.map +1 -1
  3. package/dist/json.min.cjs +1 -1
  4. package/dist/json.min.cjs.map +1 -1
  5. package/dist/json.min.mjs +1 -1
  6. package/dist/json.min.mjs.map +1 -1
  7. package/dist/json.mjs +188 -20
  8. package/dist/json.mjs.map +1 -1
  9. package/doc/api/Json.html +42 -0
  10. package/doc/api/LosslessNumber.html +3 -3
  11. package/doc/api/data/search.json +1 -1
  12. package/doc/api/global.html +3 -3
  13. package/doc/api/index.html +4 -4
  14. package/doc/api/scripts/core.js +719 -726
  15. package/doc/api/scripts/core.min.js +23 -23
  16. package/doc/api/scripts/resize.js +90 -90
  17. package/doc/api/scripts/search.js +267 -265
  18. package/doc/api/scripts/search.min.js +5 -5
  19. package/doc/api/scripts/third-party/Apache-License-2.0.txt +202 -202
  20. package/doc/api/scripts/third-party/fuse.js +1749 -9
  21. package/doc/api/scripts/third-party/hljs-line-num-original.js +367 -369
  22. package/doc/api/scripts/third-party/hljs-line-num.js +1 -1
  23. package/doc/api/scripts/third-party/hljs-original.js +5260 -5171
  24. package/doc/api/scripts/third-party/hljs.js +1 -1
  25. package/doc/api/scripts/third-party/popper.js +1287 -5
  26. package/doc/api/scripts/third-party/tippy.js +1499 -1
  27. package/doc/api/scripts/third-party/tocbot.js +757 -672
  28. package/doc/api/scripts/third-party/tocbot.min.js +1 -1
  29. package/doc/api/styles/clean-jsdoc-theme-base.css +1257 -1159
  30. package/doc/api/styles/clean-jsdoc-theme-dark.css +412 -412
  31. package/doc/api/styles/clean-jsdoc-theme-light.css +482 -482
  32. package/doc/api/styles/clean-jsdoc-theme-scrollbar.css +29 -29
  33. package/doc/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -1
  34. package/doc/api/styles/clean-jsdoc-theme.min.css +1 -1
  35. package/doc/json.min.visualization.html +15 -15
  36. package/doc/json.visualization.html +15 -15
  37. package/package.json +20 -20
@@ -1,369 +1,367 @@
1
- // jshint multistr:true
2
-
3
- (function (w, d) {
4
- 'use strict';
5
-
6
- var TABLE_NAME = 'hljs-ln',
7
- LINE_NAME = 'hljs-ln-line',
8
- CODE_BLOCK_NAME = 'hljs-ln-code',
9
- NUMBERS_BLOCK_NAME = 'hljs-ln-numbers',
10
- NUMBER_LINE_NAME = 'hljs-ln-n',
11
- DATA_ATTR_NAME = 'data-line-number',
12
- BREAK_LINE_REGEXP = /\r\n|\r|\n/g;
13
-
14
- if (w.hljs) {
15
- w.hljs.initLineNumbersOnLoad = initLineNumbersOnLoad;
16
- w.hljs.lineNumbersBlock = lineNumbersBlock;
17
- w.hljs.lineNumbersValue = lineNumbersValue;
18
-
19
- addStyles();
20
- } else {
21
- w.console.error('highlight.js not detected!');
22
- }
23
-
24
- function isHljsLnCodeDescendant(domElt) {
25
- var curElt = domElt;
26
- while (curElt) {
27
- if (curElt.className && curElt.className.indexOf('hljs-ln-code') !== -1) {
28
- return true;
29
- }
30
- curElt = curElt.parentNode;
31
- }
32
- return false;
33
- }
34
-
35
- function getHljsLnTable(hljsLnDomElt) {
36
- var curElt = hljsLnDomElt;
37
- while (curElt.nodeName !== 'TABLE') {
38
- curElt = curElt.parentNode;
39
- }
40
- return curElt;
41
- }
42
-
43
- // Function to workaround a copy issue with Microsoft Edge.
44
- // Due to hljs-ln wrapping the lines of code inside a <table> element,
45
- // itself wrapped inside a <pre> element, window.getSelection().toString()
46
- // does not contain any line breaks. So we need to get them back using the
47
- // rendered code in the DOM as reference.
48
- function edgeGetSelectedCodeLines(selection) {
49
- // current selected text without line breaks
50
- var selectionText = selection.toString();
51
-
52
- // get the <td> element wrapping the first line of selected code
53
- var tdAnchor = selection.anchorNode;
54
- while (tdAnchor.nodeName !== 'TD') {
55
- tdAnchor = tdAnchor.parentNode;
56
- }
57
-
58
- // get the <td> element wrapping the last line of selected code
59
- var tdFocus = selection.focusNode;
60
- while (tdFocus.nodeName !== 'TD') {
61
- tdFocus = tdFocus.parentNode;
62
- }
63
-
64
- // extract line numbers
65
- var firstLineNumber = parseInt(tdAnchor.dataset.lineNumber);
66
- var lastLineNumber = parseInt(tdFocus.dataset.lineNumber);
67
-
68
- // multi-lines copied case
69
- if (firstLineNumber != lastLineNumber) {
70
-
71
- var firstLineText = tdAnchor.textContent;
72
- var lastLineText = tdFocus.textContent;
73
-
74
- // if the selection was made backward, swap values
75
- if (firstLineNumber > lastLineNumber) {
76
- var tmp = firstLineNumber;
77
- firstLineNumber = lastLineNumber;
78
- lastLineNumber = tmp;
79
- tmp = firstLineText;
80
- firstLineText = lastLineText;
81
- lastLineText = tmp;
82
- }
83
-
84
- // discard not copied characters in first line
85
- while (selectionText.indexOf(firstLineText) !== 0) {
86
- firstLineText = firstLineText.slice(1);
87
- }
88
-
89
- // discard not copied characters in last line
90
- while (selectionText.lastIndexOf(lastLineText) === -1) {
91
- lastLineText = lastLineText.slice(0, -1);
92
- }
93
-
94
- // reconstruct and return the real copied text
95
- var selectedText = firstLineText;
96
- var hljsLnTable = getHljsLnTable(tdAnchor);
97
- for (var i = firstLineNumber + 1 ; i < lastLineNumber ; ++i) {
98
- var codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i]);
99
- var codeLineElt = hljsLnTable.querySelector(codeLineSel);
100
- selectedText += '\n' + codeLineElt.textContent;
101
- }
102
- selectedText += '\n' + lastLineText;
103
- return selectedText;
104
- // single copied line case
105
- } else {
106
- return selectionText;
107
- }
108
- }
109
-
110
- // ensure consistent code copy/paste behavior across all browsers
111
- // (see https://github.com/wcoder/highlightjs-line-numbers.js/issues/51)
112
- document.addEventListener('copy', function(e) {
113
- // get current selection
114
- var selection = window.getSelection();
115
- // override behavior when one wants to copy line of codes
116
- if (isHljsLnCodeDescendant(selection.anchorNode)) {
117
- var selectionText;
118
- // workaround an issue with Microsoft Edge as copied line breaks
119
- // are removed otherwise from the selection string
120
- if (window.navigator.userAgent.indexOf('Edge') !== -1) {
121
- selectionText = edgeGetSelectedCodeLines(selection);
122
- } else {
123
- // other browsers can directly use the selection string
124
- selectionText = selection.toString();
125
- }
126
- e.clipboardData.setData(
127
- 'text/plain',
128
- selectionText
129
- .replace(/(^\t)/gm, '')
130
- );
131
- e.preventDefault();
132
- }
133
- });
134
-
135
- function addStyles () {
136
- var css = d.createElement('style');
137
- css.type = 'text/css';
138
- css.innerHTML = format(
139
- '.{0}{border-collapse:collapse}' +
140
- '.{0} td{padding:0}' +
141
- '.{1}:before{content:attr({2})}',
142
- [
143
- TABLE_NAME,
144
- NUMBER_LINE_NAME,
145
- DATA_ATTR_NAME
146
- ]);
147
- d.getElementsByTagName('head')[0].appendChild(css);
148
- }
149
-
150
- function initLineNumbersOnLoad (options) {
151
- if (d.readyState === 'interactive' || d.readyState === 'complete') {
152
- documentReady(options);
153
- } else {
154
- w.addEventListener('DOMContentLoaded', function () {
155
- documentReady(options);
156
- });
157
- }
158
- }
159
-
160
- function documentReady (options) {
161
- try {
162
- var blocks = d.querySelectorAll('code.hljs,code.nohighlight');
163
-
164
- for (var i in blocks) {
165
- if (blocks.hasOwnProperty(i)) {
166
- if (!isPluginDisabledForBlock(blocks[i])) {
167
- lineNumbersBlock(blocks[i], options);
168
- }
169
- }
170
- }
171
- } catch (e) {
172
- w.console.error('LineNumbers error: ', e);
173
- }
174
- }
175
-
176
- function isPluginDisabledForBlock(element) {
177
- return element.classList.contains('nohljsln');
178
- }
179
-
180
- function lineNumbersBlock (element, options) {
181
- if (typeof element !== 'object') return;
182
-
183
- async(function () {
184
- element.innerHTML = lineNumbersInternal(element, options);
185
- });
186
- }
187
-
188
- function lineNumbersValue (value, options) {
189
- if (typeof value !== 'string') return;
190
-
191
- var element = document.createElement('code')
192
- element.innerHTML = value
193
-
194
- return lineNumbersInternal(element, options);
195
- }
196
-
197
- function lineNumbersInternal (element, options) {
198
-
199
- var internalOptions = mapOptions(element, options);
200
-
201
- duplicateMultilineNodes(element);
202
-
203
- return addLineNumbersBlockFor(element.innerHTML, internalOptions);
204
- }
205
-
206
- function addLineNumbersBlockFor (inputHtml, options) {
207
- var lines = getLines(inputHtml);
208
-
209
- // if last line contains only carriage return remove it
210
- if (lines[lines.length-1].trim() === '') {
211
- lines.pop();
212
- }
213
-
214
- if (lines.length > 1 || options.singleLine) {
215
- var html = '';
216
-
217
- for (var i = 0, l = lines.length; i < l; i++) {
218
- html += format(
219
- '<tr>' +
220
- '<td class="{0} {1}" {3}="{5}">' +
221
- '</td>' +
222
- '<td class="{0} {4}" {3}="{5}">' +
223
- '{6}' +
224
- '</td>' +
225
- '</tr>',
226
- [
227
- LINE_NAME,
228
- NUMBERS_BLOCK_NAME,
229
- NUMBER_LINE_NAME,
230
- DATA_ATTR_NAME,
231
- CODE_BLOCK_NAME,
232
- i + options.startFrom,
233
- lines[i].length > 0 ? lines[i] : ' '
234
- ]);
235
- }
236
-
237
- return format('<table class="{0}">{1}</table>', [ TABLE_NAME, html ]);
238
- }
239
-
240
- return inputHtml;
241
- }
242
-
243
- /**
244
- * @param {HTMLElement} element Code block.
245
- * @param {Object} options External API options.
246
- * @returns {Object} Internal API options.
247
- */
248
- function mapOptions (element, options) {
249
- options = options || {};
250
- return {
251
- singleLine: getSingleLineOption(options),
252
- startFrom: getStartFromOption(element, options)
253
- };
254
- }
255
-
256
- function getSingleLineOption (options) {
257
- var defaultValue = false;
258
- if (!!options.singleLine) {
259
- return options.singleLine;
260
- }
261
- return defaultValue;
262
- }
263
-
264
- function getStartFromOption (element, options) {
265
- var defaultValue = 1;
266
- var startFrom = defaultValue;
267
-
268
- if (isFinite(options.startFrom)) {
269
- startFrom = options.startFrom;
270
- }
271
-
272
- // can be overridden because local option is priority
273
- var value = getAttribute(element, 'data-ln-start-from');
274
- if (value !== null) {
275
- startFrom = toNumber(value, defaultValue);
276
- }
277
-
278
- return startFrom;
279
- }
280
-
281
- /**
282
- * Recursive method for fix multi-line elements implementation in highlight.js
283
- * Doing deep passage on child nodes.
284
- * @param {HTMLElement} element
285
- */
286
- function duplicateMultilineNodes (element) {
287
- var nodes = element.childNodes;
288
- for (var node in nodes) {
289
- if (nodes.hasOwnProperty(node)) {
290
- var child = nodes[node];
291
- if (getLinesCount(child.textContent) > 0) {
292
- if (child.childNodes.length > 0) {
293
- duplicateMultilineNodes(child);
294
- } else {
295
- duplicateMultilineNode(child.parentNode);
296
- }
297
- }
298
- }
299
- }
300
- }
301
-
302
- /**
303
- * Method for fix multi-line elements implementation in highlight.js
304
- * @param {HTMLElement} element
305
- */
306
- function duplicateMultilineNode (element) {
307
- var className = element.className;
308
-
309
- if ( ! /hljs-/.test(className)) return;
310
-
311
- var lines = getLines(element.innerHTML);
312
-
313
- for (var i = 0, result = ''; i < lines.length; i++) {
314
- var lineText = lines[i].length > 0 ? lines[i] : ' ';
315
- result += format('<span class="{0}">{1}</span>\n', [ className, lineText ]);
316
- }
317
-
318
- element.innerHTML = result.trim();
319
- }
320
-
321
- function getLines (text) {
322
- if (text.length === 0) return [];
323
- return text.split(BREAK_LINE_REGEXP);
324
- }
325
-
326
- function getLinesCount (text) {
327
- return (text.trim().match(BREAK_LINE_REGEXP) || []).length;
328
- }
329
-
330
- ///
331
- /// HELPERS
332
- ///
333
-
334
- function async (func) {
335
- w.setTimeout(func, 0);
336
- }
337
-
338
- /**
339
- * {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript}
340
- * @param {string} format
341
- * @param {array} args
342
- */
343
- function format (format, args) {
344
- return format.replace(/\{(\d+)\}/g, function(m, n){
345
- return args[n] !== undefined ? args[n] : m;
346
- });
347
- }
348
-
349
- /**
350
- * @param {HTMLElement} element Code block.
351
- * @param {String} attrName Attribute name.
352
- * @returns {String} Attribute value or empty.
353
- */
354
- function getAttribute (element, attrName) {
355
- return element.hasAttribute(attrName) ? element.getAttribute(attrName) : null;
356
- }
357
-
358
- /**
359
- * @param {String} str Source string.
360
- * @param {Number} fallback Fallback value.
361
- * @returns Parsed number or fallback value.
362
- */
363
- function toNumber (str, fallback) {
364
- if (!str) return fallback;
365
- var number = Number(str);
366
- return isFinite(number) ? number : fallback;
367
- }
368
-
369
- }(window, document));
1
+ // jshint multistr:true
2
+
3
+ (function (w, d) {
4
+ var TABLE_NAME = "hljs-ln",
5
+ LINE_NAME = "hljs-ln-line",
6
+ CODE_BLOCK_NAME = "hljs-ln-code",
7
+ NUMBERS_BLOCK_NAME = "hljs-ln-numbers",
8
+ NUMBER_LINE_NAME = "hljs-ln-n",
9
+ DATA_ATTR_NAME = "data-line-number",
10
+ BREAK_LINE_REGEXP = /\r\n|\r|\n/g;
11
+
12
+ if (w.hljs) {
13
+ w.hljs.initLineNumbersOnLoad = initLineNumbersOnLoad;
14
+ w.hljs.lineNumbersBlock = lineNumbersBlock;
15
+ w.hljs.lineNumbersValue = lineNumbersValue;
16
+
17
+ addStyles();
18
+ } else {
19
+ w.console.error("highlight.js not detected!");
20
+ }
21
+
22
+ function isHljsLnCodeDescendant(domElt) {
23
+ var curElt = domElt;
24
+ while (curElt) {
25
+ if (curElt.className && curElt.className.indexOf("hljs-ln-code") !== -1) {
26
+ return true;
27
+ }
28
+ curElt = curElt.parentNode;
29
+ }
30
+ return false;
31
+ }
32
+
33
+ function getHljsLnTable(hljsLnDomElt) {
34
+ var curElt = hljsLnDomElt;
35
+ while (curElt.nodeName !== "TABLE") {
36
+ curElt = curElt.parentNode;
37
+ }
38
+ return curElt;
39
+ }
40
+
41
+ // Function to workaround a copy issue with Microsoft Edge.
42
+ // Due to hljs-ln wrapping the lines of code inside a <table> element,
43
+ // itself wrapped inside a <pre> element, window.getSelection().toString()
44
+ // does not contain any line breaks. So we need to get them back using the
45
+ // rendered code in the DOM as reference.
46
+ function edgeGetSelectedCodeLines(selection) {
47
+ // current selected text without line breaks
48
+ var selectionText = selection.toString();
49
+
50
+ // get the <td> element wrapping the first line of selected code
51
+ var tdAnchor = selection.anchorNode;
52
+ while (tdAnchor.nodeName !== "TD") {
53
+ tdAnchor = tdAnchor.parentNode;
54
+ }
55
+
56
+ // get the <td> element wrapping the last line of selected code
57
+ var tdFocus = selection.focusNode;
58
+ while (tdFocus.nodeName !== "TD") {
59
+ tdFocus = tdFocus.parentNode;
60
+ }
61
+
62
+ // extract line numbers
63
+ var firstLineNumber = parseInt(tdAnchor.dataset.lineNumber);
64
+ var lastLineNumber = parseInt(tdFocus.dataset.lineNumber);
65
+
66
+ // multi-lines copied case
67
+ if (firstLineNumber != lastLineNumber) {
68
+ var firstLineText = tdAnchor.textContent;
69
+ var lastLineText = tdFocus.textContent;
70
+
71
+ // if the selection was made backward, swap values
72
+ if (firstLineNumber > lastLineNumber) {
73
+ var tmp = firstLineNumber;
74
+ firstLineNumber = lastLineNumber;
75
+ lastLineNumber = tmp;
76
+ tmp = firstLineText;
77
+ firstLineText = lastLineText;
78
+ lastLineText = tmp;
79
+ }
80
+
81
+ // discard not copied characters in first line
82
+ while (selectionText.indexOf(firstLineText) !== 0) {
83
+ firstLineText = firstLineText.slice(1);
84
+ }
85
+
86
+ // discard not copied characters in last line
87
+ while (selectionText.lastIndexOf(lastLineText) === -1) {
88
+ lastLineText = lastLineText.slice(0, -1);
89
+ }
90
+
91
+ // reconstruct and return the real copied text
92
+ var selectedText = firstLineText;
93
+ var hljsLnTable = getHljsLnTable(tdAnchor);
94
+ for (var i = firstLineNumber + 1; i < lastLineNumber; ++i) {
95
+ var codeLineSel = format('.{0}[{1}="{2}"]', [
96
+ CODE_BLOCK_NAME,
97
+ DATA_ATTR_NAME,
98
+ i,
99
+ ]);
100
+ var codeLineElt = hljsLnTable.querySelector(codeLineSel);
101
+ selectedText += "\n" + codeLineElt.textContent;
102
+ }
103
+ selectedText += "\n" + lastLineText;
104
+ return selectedText;
105
+ // single copied line case
106
+ } else {
107
+ return selectionText;
108
+ }
109
+ }
110
+
111
+ // ensure consistent code copy/paste behavior across all browsers
112
+ // (see https://github.com/wcoder/highlightjs-line-numbers.js/issues/51)
113
+ document.addEventListener("copy", function (e) {
114
+ // get current selection
115
+ var selection = window.getSelection();
116
+ // override behavior when one wants to copy line of codes
117
+ if (isHljsLnCodeDescendant(selection.anchorNode)) {
118
+ var selectionText;
119
+ // workaround an issue with Microsoft Edge as copied line breaks
120
+ // are removed otherwise from the selection string
121
+ if (window.navigator.userAgent.indexOf("Edge") !== -1) {
122
+ selectionText = edgeGetSelectedCodeLines(selection);
123
+ } else {
124
+ // other browsers can directly use the selection string
125
+ selectionText = selection.toString();
126
+ }
127
+ e.clipboardData.setData(
128
+ "text/plain",
129
+ selectionText.replace(/(^\t)/gm, "")
130
+ );
131
+ e.preventDefault();
132
+ }
133
+ });
134
+
135
+ function addStyles() {
136
+ var css = d.createElement("style");
137
+ css.type = "text/css";
138
+ css.innerHTML = format(
139
+ ".{0}{border-collapse:collapse}" +
140
+ ".{0} td{padding:0}" +
141
+ ".{1}:before{content:attr({2})}",
142
+ [TABLE_NAME, NUMBER_LINE_NAME, DATA_ATTR_NAME]
143
+ );
144
+ d.getElementsByTagName("head")[0].appendChild(css);
145
+ }
146
+
147
+ function initLineNumbersOnLoad(options) {
148
+ if (d.readyState === "interactive" || d.readyState === "complete") {
149
+ documentReady(options);
150
+ } else {
151
+ w.addEventListener("DOMContentLoaded", function () {
152
+ documentReady(options);
153
+ });
154
+ }
155
+ }
156
+
157
+ function documentReady(options) {
158
+ try {
159
+ var blocks = d.querySelectorAll("code.hljs,code.nohighlight");
160
+
161
+ for (var i in blocks) {
162
+ if (blocks.hasOwnProperty(i)) {
163
+ if (!isPluginDisabledForBlock(blocks[i])) {
164
+ lineNumbersBlock(blocks[i], options);
165
+ }
166
+ }
167
+ }
168
+ } catch (e) {
169
+ w.console.error("LineNumbers error: ", e);
170
+ }
171
+ }
172
+
173
+ function isPluginDisabledForBlock(element) {
174
+ return element.classList.contains("nohljsln");
175
+ }
176
+
177
+ function lineNumbersBlock(element, options) {
178
+ if (typeof element !== "object") return;
179
+
180
+ async(function () {
181
+ element.innerHTML = lineNumbersInternal(element, options);
182
+ });
183
+ }
184
+
185
+ function lineNumbersValue(value, options) {
186
+ if (typeof value !== "string") return;
187
+
188
+ var element = document.createElement("code");
189
+ element.innerHTML = value;
190
+
191
+ return lineNumbersInternal(element, options);
192
+ }
193
+
194
+ function lineNumbersInternal(element, options) {
195
+ var internalOptions = mapOptions(element, options);
196
+
197
+ duplicateMultilineNodes(element);
198
+
199
+ return addLineNumbersBlockFor(element.innerHTML, internalOptions);
200
+ }
201
+
202
+ function addLineNumbersBlockFor(inputHtml, options) {
203
+ var lines = getLines(inputHtml);
204
+
205
+ // if last line contains only carriage return remove it
206
+ if (lines[lines.length - 1].trim() === "") {
207
+ lines.pop();
208
+ }
209
+
210
+ if (lines.length > 1 || options.singleLine) {
211
+ var html = "";
212
+
213
+ for (var i = 0, l = lines.length; i < l; i++) {
214
+ html += format(
215
+ "<tr>" +
216
+ '<td class="{0} {1}" {3}="{5}">' +
217
+ "</td>" +
218
+ '<td class="{0} {4}" {3}="{5}">' +
219
+ "{6}" +
220
+ "</td>" +
221
+ "</tr>",
222
+ [
223
+ LINE_NAME,
224
+ NUMBERS_BLOCK_NAME,
225
+ NUMBER_LINE_NAME,
226
+ DATA_ATTR_NAME,
227
+ CODE_BLOCK_NAME,
228
+ i + options.startFrom,
229
+ lines[i].length > 0 ? lines[i] : " ",
230
+ ]
231
+ );
232
+ }
233
+
234
+ return format('<table class="{0}">{1}</table>', [TABLE_NAME, html]);
235
+ }
236
+
237
+ return inputHtml;
238
+ }
239
+
240
+ /**
241
+ * @param {HTMLElement} element Code block.
242
+ * @param {Object} options External API options.
243
+ * @returns {Object} Internal API options.
244
+ */
245
+ function mapOptions(element, options) {
246
+ options = options || {};
247
+ return {
248
+ singleLine: getSingleLineOption(options),
249
+ startFrom: getStartFromOption(element, options),
250
+ };
251
+ }
252
+
253
+ function getSingleLineOption(options) {
254
+ var defaultValue = false;
255
+ if (options.singleLine) {
256
+ return options.singleLine;
257
+ }
258
+ return defaultValue;
259
+ }
260
+
261
+ function getStartFromOption(element, options) {
262
+ var defaultValue = 1;
263
+ var startFrom = defaultValue;
264
+
265
+ if (isFinite(options.startFrom)) {
266
+ startFrom = options.startFrom;
267
+ }
268
+
269
+ // can be overridden because local option is priority
270
+ var value = getAttribute(element, "data-ln-start-from");
271
+ if (value !== null) {
272
+ startFrom = toNumber(value, defaultValue);
273
+ }
274
+
275
+ return startFrom;
276
+ }
277
+
278
+ /**
279
+ * Recursive method for fix multi-line elements implementation in highlight.js
280
+ * Doing deep passage on child nodes.
281
+ * @param {HTMLElement} element
282
+ */
283
+ function duplicateMultilineNodes(element) {
284
+ var nodes = element.childNodes;
285
+ for (var node in nodes) {
286
+ if (nodes.hasOwnProperty(node)) {
287
+ var child = nodes[node];
288
+ if (getLinesCount(child.textContent) > 0) {
289
+ if (child.childNodes.length > 0) {
290
+ duplicateMultilineNodes(child);
291
+ } else {
292
+ duplicateMultilineNode(child.parentNode);
293
+ }
294
+ }
295
+ }
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Method for fix multi-line elements implementation in highlight.js
301
+ * @param {HTMLElement} element
302
+ */
303
+ function duplicateMultilineNode(element) {
304
+ var className = element.className;
305
+
306
+ if (!/hljs-/.test(className)) return;
307
+
308
+ var lines = getLines(element.innerHTML);
309
+
310
+ for (var i = 0, result = ""; i < lines.length; i++) {
311
+ var lineText = lines[i].length > 0 ? lines[i] : " ";
312
+ result += format('<span class="{0}">{1}</span>\n', [className, lineText]);
313
+ }
314
+
315
+ element.innerHTML = result.trim();
316
+ }
317
+
318
+ function getLines(text) {
319
+ if (text.length === 0) return [];
320
+ return text.split(BREAK_LINE_REGEXP);
321
+ }
322
+
323
+ function getLinesCount(text) {
324
+ return (text.trim().match(BREAK_LINE_REGEXP) || []).length;
325
+ }
326
+
327
+ ///
328
+ /// HELPERS
329
+ ///
330
+
331
+ function async(func) {
332
+ w.setTimeout(func, 0);
333
+ }
334
+
335
+ /**
336
+ * {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript}
337
+ * @param {string} format
338
+ * @param {array} args
339
+ */
340
+ function format(format, args) {
341
+ return format.replace(/\{(\d+)\}/g, function (m, n) {
342
+ return args[n] !== undefined ? args[n] : m;
343
+ });
344
+ }
345
+
346
+ /**
347
+ * @param {HTMLElement} element Code block.
348
+ * @param {String} attrName Attribute name.
349
+ * @returns {String} Attribute value or empty.
350
+ */
351
+ function getAttribute(element, attrName) {
352
+ return element.hasAttribute(attrName)
353
+ ? element.getAttribute(attrName)
354
+ : null;
355
+ }
356
+
357
+ /**
358
+ * @param {String} str Source string.
359
+ * @param {Number} fallback Fallback value.
360
+ * @returns Parsed number or fallback value.
361
+ */
362
+ function toNumber(str, fallback) {
363
+ if (!str) return fallback;
364
+ var number = Number(str);
365
+ return isFinite(number) ? number : fallback;
366
+ }
367
+ })(window, document);