dobo 2.0.1 → 2.2.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/.github/FUNDING.yml +0 -0
- package/.github/workflows/repo-lockdown.yml +0 -0
- package/.jsdoc.conf.json +0 -0
- package/LICENSE +0 -0
- package/README.md +2 -2
- package/docs/Dobo.html +0 -0
- package/docs/data/search.json +0 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +0 -0
- package/docs/index.html +0 -0
- package/docs/index.js.html +0 -0
- package/docs/lib_collect-connections.js.html +0 -0
- package/docs/lib_collect-drivers.js.html +0 -0
- package/docs/lib_collect-features.js.html +0 -0
- package/docs/lib_collect-schemas.js.html +0 -0
- package/docs/lib_index.js.html +0 -0
- package/docs/method_model_create.js.html +0 -0
- package/docs/method_model_drop.js.html +0 -0
- package/docs/method_model_exists.js.html +0 -0
- package/docs/method_record_count.js.html +0 -0
- package/docs/method_record_create.js.html +0 -0
- package/docs/method_record_find-all.js.html +0 -0
- package/docs/method_record_find-one.js.html +0 -0
- package/docs/method_record_find.js.html +0 -0
- package/docs/method_record_get.js.html +0 -0
- package/docs/method_record_remove.js.html +0 -0
- package/docs/method_record_update.js.html +0 -0
- package/docs/method_record_upsert.js.html +0 -0
- package/docs/method_sanitize_body.js.html +0 -0
- package/docs/method_sanitize_date.js.html +0 -0
- package/docs/method_sanitize_id.js.html +0 -0
- package/docs/method_validate.js.html +0 -0
- package/docs/module-Lib.html +0 -0
- package/docs/scripts/core.js +476 -477
- package/docs/scripts/core.min.js +0 -0
- package/docs/scripts/resize.js +36 -36
- package/docs/scripts/search.js +105 -105
- package/docs/scripts/search.min.js +0 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
- package/docs/scripts/third-party/fuse.js +1 -1
- package/docs/scripts/third-party/hljs-line-num-original.js +282 -285
- package/docs/scripts/third-party/hljs-line-num.js +1 -1
- package/docs/scripts/third-party/hljs-original.js +1195 -1202
- package/docs/scripts/third-party/hljs.js +1 -1
- package/docs/scripts/third-party/popper.js +1 -1
- package/docs/scripts/third-party/tippy.js +1 -1
- package/docs/scripts/third-party/tocbot.js +508 -509
- package/docs/scripts/third-party/tocbot.min.js +0 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +0 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +0 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
- package/docs/styles/clean-jsdoc-theme-light.css +0 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
- package/docs/styles/clean-jsdoc-theme.min.css +0 -0
- package/extend/bajo/intl/en-US.json +66 -28
- package/extend/bajo/intl/id.json +55 -27
- package/extend/bajoCli/applet/clear-record.js +22 -0
- package/extend/bajoCli/applet/connection.js +0 -0
- package/extend/bajoCli/applet/count-record.js +27 -0
- package/extend/bajoCli/applet/create-aggregate.js +33 -0
- package/extend/bajoCli/applet/create-histogram.js +33 -0
- package/extend/bajoCli/applet/create-record.js +39 -0
- package/extend/bajoCli/applet/find-record.js +27 -0
- package/extend/bajoCli/applet/get-record.js +27 -0
- package/extend/bajoCli/applet/lib/post-process.js +10 -17
- package/extend/bajoCli/applet/model.js +22 -0
- package/extend/bajoCli/applet/rebuild-model.js +91 -0
- package/extend/bajoCli/applet/remove-record.js +27 -0
- package/extend/bajoCli/applet/update-record.js +44 -0
- package/extend/bajoCli/applet.js +0 -0
- package/extend/dobo/driver/memory.js +170 -0
- package/extend/dobo/feature/created-at.js +9 -7
- package/extend/dobo/feature/dt.js +0 -0
- package/extend/dobo/feature/immutable.js +30 -0
- package/extend/dobo/feature/int-id.js +0 -0
- package/extend/dobo/feature/removed-at.js +32 -54
- package/extend/dobo/feature/updated-at.js +14 -12
- package/extend/waibuMpa/route/attachment/@model/@id/@field/@file.js +2 -6
- package/extend/waibuStatic/virtual.json +0 -0
- package/index.js +291 -366
- package/lib/collect-connections.js +49 -21
- package/lib/collect-drivers.js +19 -33
- package/lib/collect-features.js +24 -17
- package/lib/collect-models.js +319 -0
- package/lib/factory/action.js +161 -0
- package/lib/factory/connection.js +62 -0
- package/lib/factory/driver.js +358 -0
- package/lib/factory/feature.js +33 -0
- package/lib/factory/model/_util.js +402 -0
- package/lib/factory/model/build.js +15 -0
- package/lib/factory/model/clear-record.js +17 -0
- package/lib/factory/model/count-record.js +17 -0
- package/lib/factory/model/create-aggregate.js +17 -0
- package/lib/factory/model/create-attachment.js +29 -0
- package/lib/factory/model/create-histogram.js +17 -0
- package/lib/factory/model/create-record.js +35 -0
- package/lib/factory/model/drop.js +15 -0
- package/lib/factory/model/exists.js +21 -0
- package/lib/factory/model/find-all-record.js +71 -0
- package/lib/factory/model/find-attachment.js +29 -0
- package/lib/factory/model/find-one-record.js +19 -0
- package/{method/record/find.js → lib/factory/model/find-record.js} +103 -115
- package/lib/factory/model/get-attachment.js +15 -0
- package/lib/factory/model/get-record.js +79 -0
- package/lib/factory/model/list-attachment.js +37 -0
- package/lib/{add-fixtures.js → factory/model/load-fixtures.js} +69 -67
- package/lib/factory/model/remove-attachment.js +15 -0
- package/lib/factory/model/remove-record.js +59 -0
- package/lib/factory/model/sanitize-body.js +62 -0
- package/lib/factory/model/sanitize-id.js +7 -0
- package/lib/factory/model/sanitize-record.js +26 -0
- package/lib/factory/model/update-attachment.js +9 -0
- package/lib/factory/model/update-record.js +81 -0
- package/lib/factory/model/upsert-record.js +95 -0
- package/{method → lib/factory/model}/validate.js +38 -52
- package/lib/factory/model.js +150 -0
- package/lib/index.js +0 -0
- package/package.json +8 -4
- package/wiki/APPLETS.md +0 -0
- package/wiki/CHANGES.md +46 -0
- package/wiki/CONFIG.md +0 -0
- package/wiki/CONTRIBUTING.md +0 -0
- package/wiki/DEV-GUIDE.md +0 -0
- package/wiki/ECOSYSTEM.md +0 -0
- package/wiki/GETTING-STARTED.md +10 -10
- package/wiki/QUERY-LANGUAGE.md +0 -0
- package/wiki/USER-GUIDE.md +0 -0
- package/extend/bajoCli/applet/model-clear.js +0 -11
- package/extend/bajoCli/applet/model-rebuild.js +0 -101
- package/extend/bajoCli/applet/record-create.js +0 -43
- package/extend/bajoCli/applet/record-find.js +0 -28
- package/extend/bajoCli/applet/record-get.js +0 -24
- package/extend/bajoCli/applet/record-remove.js +0 -24
- package/extend/bajoCli/applet/record-update.js +0 -47
- package/extend/bajoCli/applet/schema.js +0 -22
- package/extend/bajoCli/applet/stat-count.js +0 -24
- package/lib/build-bulk-action.js +0 -12
- package/lib/check-unique.js +0 -39
- package/lib/collect-schemas.js +0 -91
- package/lib/exec-feature-hook.js +0 -13
- package/lib/exec-validation.js +0 -21
- package/lib/generic-prop-sanitizer.js +0 -32
- package/lib/handle-attachment-upload.js +0 -16
- package/lib/mem-db/conn-sanitizer.js +0 -8
- package/lib/mem-db/instantiate.js +0 -41
- package/lib/mem-db/method/model/clear.js +0 -6
- package/lib/mem-db/method/model/create.js +0 -5
- package/lib/mem-db/method/model/drop.js +0 -5
- package/lib/mem-db/method/model/exists.js +0 -5
- package/lib/mem-db/method/record/create.js +0 -12
- package/lib/mem-db/method/record/find.js +0 -20
- package/lib/mem-db/method/record/get.js +0 -9
- package/lib/mem-db/method/record/remove.js +0 -13
- package/lib/mem-db/method/record/update.js +0 -15
- package/lib/mem-db/method/stat/count.js +0 -11
- package/lib/mem-db/start.js +0 -25
- package/lib/merge-attachment-info.js +0 -16
- package/lib/multi-rel-rows.js +0 -42
- package/lib/resolve-method.js +0 -16
- package/lib/sanitize-schema.js +0 -198
- package/lib/single-rel-rows.js +0 -38
- package/method/attachment/copy-uploaded.js +0 -34
- package/method/attachment/create.js +0 -29
- package/method/attachment/find.js +0 -27
- package/method/attachment/get-path.js +0 -12
- package/method/attachment/get.js +0 -12
- package/method/attachment/pre-check.js +0 -9
- package/method/attachment/remove.js +0 -11
- package/method/attachment/update.js +0 -7
- package/method/bulk/create.js +0 -46
- package/method/model/clear.js +0 -22
- package/method/model/create.js +0 -32
- package/method/model/drop.js +0 -31
- package/method/model/exists.js +0 -37
- package/method/record/clear.js +0 -24
- package/method/record/count.js +0 -66
- package/method/record/create.js +0 -111
- package/method/record/find-all.js +0 -41
- package/method/record/find-one.js +0 -70
- package/method/record/get.js +0 -89
- package/method/record/remove.js +0 -72
- package/method/record/update.js +0 -104
- package/method/record/upsert.js +0 -51
- package/method/sanitize/body.js +0 -85
- package/method/sanitize/date.js +0 -27
- package/method/sanitize/id.js +0 -17
- package/method/stat/aggregate.js +0 -23
- package/method/stat/histogram.js +0 -26
|
@@ -1,369 +1,366 @@
|
|
|
1
1
|
// jshint multistr:true
|
|
2
2
|
|
|
3
3
|
(function (w, d) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
'use strict'
|
|
5
|
+
|
|
6
|
+
const TABLE_NAME = 'hljs-ln'
|
|
7
|
+
const LINE_NAME = 'hljs-ln-line'
|
|
8
|
+
const CODE_BLOCK_NAME = 'hljs-ln-code'
|
|
9
|
+
const NUMBERS_BLOCK_NAME = 'hljs-ln-numbers'
|
|
10
|
+
const NUMBER_LINE_NAME = 'hljs-ln-n'
|
|
11
|
+
const DATA_ATTR_NAME = 'data-line-number'
|
|
12
|
+
const 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
|
+
let curElt = domElt
|
|
26
|
+
while (curElt) {
|
|
27
|
+
if (curElt.className && curElt.className.indexOf('hljs-ln-code') !== -1) {
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
curElt = curElt.parentNode
|
|
22
31
|
}
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
curElt = curElt.parentNode;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
35
|
+
function getHljsLnTable (hljsLnDomElt) {
|
|
36
|
+
let curElt = hljsLnDomElt
|
|
37
|
+
while (curElt.nodeName !== 'TABLE') {
|
|
38
|
+
curElt = curElt.parentNode
|
|
33
39
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
const selectionText = selection.toString()
|
|
51
|
+
|
|
52
|
+
// get the <td> element wrapping the first line of selected code
|
|
53
|
+
let tdAnchor = selection.anchorNode
|
|
54
|
+
while (tdAnchor.nodeName !== 'TD') {
|
|
55
|
+
tdAnchor = tdAnchor.parentNode
|
|
41
56
|
}
|
|
42
57
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
}
|
|
58
|
+
// get the <td> element wrapping the last line of selected code
|
|
59
|
+
let tdFocus = selection.focusNode
|
|
60
|
+
while (tdFocus.nodeName !== 'TD') {
|
|
61
|
+
tdFocus = tdFocus.parentNode
|
|
108
62
|
}
|
|
109
63
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
64
|
+
// extract line numbers
|
|
65
|
+
let firstLineNumber = parseInt(tdAnchor.dataset.lineNumber)
|
|
66
|
+
let lastLineNumber = parseInt(tdFocus.dataset.lineNumber)
|
|
67
|
+
|
|
68
|
+
// multi-lines copied case
|
|
69
|
+
if (firstLineNumber != lastLineNumber) {
|
|
70
|
+
let firstLineText = tdAnchor.textContent
|
|
71
|
+
let lastLineText = tdFocus.textContent
|
|
72
|
+
|
|
73
|
+
// if the selection was made backward, swap values
|
|
74
|
+
if (firstLineNumber > lastLineNumber) {
|
|
75
|
+
let tmp = firstLineNumber
|
|
76
|
+
firstLineNumber = lastLineNumber
|
|
77
|
+
lastLineNumber = tmp
|
|
78
|
+
tmp = firstLineText
|
|
79
|
+
firstLineText = lastLineText
|
|
80
|
+
lastLineText = tmp
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// discard not copied characters in first line
|
|
84
|
+
while (selectionText.indexOf(firstLineText) !== 0) {
|
|
85
|
+
firstLineText = firstLineText.slice(1)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// discard not copied characters in last line
|
|
89
|
+
while (selectionText.lastIndexOf(lastLineText) === -1) {
|
|
90
|
+
lastLineText = lastLineText.slice(0, -1)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// reconstruct and return the real copied text
|
|
94
|
+
let selectedText = firstLineText
|
|
95
|
+
const hljsLnTable = getHljsLnTable(tdAnchor)
|
|
96
|
+
for (let i = firstLineNumber + 1; i < lastLineNumber; ++i) {
|
|
97
|
+
const codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i])
|
|
98
|
+
const codeLineElt = hljsLnTable.querySelector(codeLineSel)
|
|
99
|
+
selectedText += '\n' + codeLineElt.textContent
|
|
100
|
+
}
|
|
101
|
+
selectedText += '\n' + lastLineText
|
|
102
|
+
return selectedText
|
|
103
|
+
// single copied line case
|
|
104
|
+
} else {
|
|
105
|
+
return selectionText
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ensure consistent code copy/paste behavior across all browsers
|
|
110
|
+
// (see https://github.com/wcoder/highlightjs-line-numbers.js/issues/51)
|
|
111
|
+
document.addEventListener('copy', function (e) {
|
|
112
|
+
// get current selection
|
|
113
|
+
const selection = window.getSelection()
|
|
114
|
+
// override behavior when one wants to copy line of codes
|
|
115
|
+
if (isHljsLnCodeDescendant(selection.anchorNode)) {
|
|
116
|
+
let selectionText
|
|
117
|
+
// workaround an issue with Microsoft Edge as copied line breaks
|
|
118
|
+
// are removed otherwise from the selection string
|
|
119
|
+
if (window.navigator.userAgent.indexOf('Edge') !== -1) {
|
|
120
|
+
selectionText = edgeGetSelectedCodeLines(selection)
|
|
121
|
+
} else {
|
|
122
|
+
// other browsers can directly use the selection string
|
|
123
|
+
selectionText = selection.toString()
|
|
124
|
+
}
|
|
125
|
+
e.clipboardData.setData(
|
|
126
|
+
'text/plain',
|
|
127
|
+
selectionText
|
|
128
|
+
.replace(/(^\t)/gm, '')
|
|
129
|
+
)
|
|
130
|
+
e.preventDefault()
|
|
131
|
+
}
|
|
132
|
+
})
|
|
134
133
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
function addStyles () {
|
|
135
|
+
const css = d.createElement('style')
|
|
136
|
+
css.type = 'text/css'
|
|
137
|
+
css.innerHTML = format(
|
|
138
|
+
'.{0}{border-collapse:collapse}' +
|
|
140
139
|
'.{0} td{padding:0}' +
|
|
141
140
|
'.{1}:before{content:attr({2})}',
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
[
|
|
142
|
+
TABLE_NAME,
|
|
143
|
+
NUMBER_LINE_NAME,
|
|
144
|
+
DATA_ATTR_NAME
|
|
145
|
+
])
|
|
146
|
+
d.getElementsByTagName('head')[0].appendChild(css)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function initLineNumbersOnLoad (options) {
|
|
150
|
+
if (d.readyState === 'interactive' || d.readyState === 'complete') {
|
|
151
|
+
documentReady(options)
|
|
152
|
+
} else {
|
|
153
|
+
w.addEventListener('DOMContentLoaded', function () {
|
|
154
|
+
documentReady(options)
|
|
155
|
+
})
|
|
148
156
|
}
|
|
157
|
+
}
|
|
149
158
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
} else {
|
|
154
|
-
w.addEventListener('DOMContentLoaded', function () {
|
|
155
|
-
documentReady(options);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
+
function documentReady (options) {
|
|
160
|
+
try {
|
|
161
|
+
const blocks = d.querySelectorAll('code.hljs,code.nohighlight')
|
|
159
162
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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);
|
|
163
|
+
for (const i in blocks) {
|
|
164
|
+
if (blocks.hasOwnProperty(i)) {
|
|
165
|
+
if (!isPluginDisabledForBlock(blocks[i])) {
|
|
166
|
+
lineNumbersBlock(blocks[i], options)
|
|
167
|
+
}
|
|
173
168
|
}
|
|
169
|
+
}
|
|
170
|
+
} catch (e) {
|
|
171
|
+
w.console.error('LineNumbers error: ', e)
|
|
174
172
|
}
|
|
173
|
+
}
|
|
175
174
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
function isPluginDisabledForBlock (element) {
|
|
176
|
+
return element.classList.contains('nohljsln')
|
|
177
|
+
}
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
function lineNumbersBlock (element, options) {
|
|
180
|
+
if (typeof element !== 'object') return
|
|
182
181
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
async(function () {
|
|
183
|
+
element.innerHTML = lineNumbersInternal(element, options)
|
|
184
|
+
})
|
|
185
|
+
}
|
|
187
186
|
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
function lineNumbersValue (value, options) {
|
|
188
|
+
if (typeof value !== 'string') return
|
|
190
189
|
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
const element = document.createElement('code')
|
|
191
|
+
element.innerHTML = value
|
|
193
192
|
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
return lineNumbersInternal(element, options)
|
|
194
|
+
}
|
|
196
195
|
|
|
197
|
-
|
|
196
|
+
function lineNumbersInternal (element, options) {
|
|
197
|
+
const internalOptions = mapOptions(element, options)
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
duplicateMultilineNodes(element)
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return addLineNumbersBlockFor(element.innerHTML, internalOptions);
|
|
204
|
-
}
|
|
201
|
+
return addLineNumbersBlockFor(element.innerHTML, internalOptions)
|
|
202
|
+
}
|
|
205
203
|
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
function addLineNumbersBlockFor (inputHtml, options) {
|
|
205
|
+
const lines = getLines(inputHtml)
|
|
208
206
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
207
|
+
// if last line contains only carriage return remove it
|
|
208
|
+
if (lines[lines.length - 1].trim() === '') {
|
|
209
|
+
lines.pop()
|
|
210
|
+
}
|
|
213
211
|
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
if (lines.length > 1 || options.singleLine) {
|
|
213
|
+
let html = ''
|
|
216
214
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
|
216
|
+
html += format(
|
|
217
|
+
'<tr>' +
|
|
220
218
|
'<td class="{0} {1}" {3}="{5}">' +
|
|
221
219
|
'</td>' +
|
|
222
220
|
'<td class="{0} {4}" {3}="{5}">' +
|
|
223
221
|
'{6}' +
|
|
224
222
|
'</td>' +
|
|
225
223
|
'</tr>',
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return inputHtml;
|
|
224
|
+
[
|
|
225
|
+
LINE_NAME,
|
|
226
|
+
NUMBERS_BLOCK_NAME,
|
|
227
|
+
NUMBER_LINE_NAME,
|
|
228
|
+
DATA_ATTR_NAME,
|
|
229
|
+
CODE_BLOCK_NAME,
|
|
230
|
+
i + options.startFrom,
|
|
231
|
+
lines[i].length > 0 ? lines[i] : ' '
|
|
232
|
+
])
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return format('<table class="{0}">{1}</table>', [TABLE_NAME, html])
|
|
241
236
|
}
|
|
242
237
|
|
|
243
|
-
|
|
238
|
+
return inputHtml
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
244
242
|
* @param {HTMLElement} element Code block.
|
|
245
243
|
* @param {Object} options External API options.
|
|
246
244
|
* @returns {Object} Internal API options.
|
|
247
245
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
};
|
|
246
|
+
function mapOptions (element, options) {
|
|
247
|
+
options = options || {}
|
|
248
|
+
return {
|
|
249
|
+
singleLine: getSingleLineOption(options),
|
|
250
|
+
startFrom: getStartFromOption(element, options)
|
|
254
251
|
}
|
|
252
|
+
}
|
|
255
253
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
return defaultValue;
|
|
254
|
+
function getSingleLineOption (options) {
|
|
255
|
+
const defaultValue = false
|
|
256
|
+
if (options.singleLine) {
|
|
257
|
+
return options.singleLine
|
|
262
258
|
}
|
|
259
|
+
return defaultValue
|
|
260
|
+
}
|
|
263
261
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (isFinite(options.startFrom)) {
|
|
269
|
-
startFrom = options.startFrom;
|
|
270
|
-
}
|
|
262
|
+
function getStartFromOption (element, options) {
|
|
263
|
+
const defaultValue = 1
|
|
264
|
+
let startFrom = defaultValue
|
|
271
265
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
startFrom = toNumber(value, defaultValue);
|
|
276
|
-
}
|
|
266
|
+
if (isFinite(options.startFrom)) {
|
|
267
|
+
startFrom = options.startFrom
|
|
268
|
+
}
|
|
277
269
|
|
|
278
|
-
|
|
270
|
+
// can be overridden because local option is priority
|
|
271
|
+
const value = getAttribute(element, 'data-ln-start-from')
|
|
272
|
+
if (value !== null) {
|
|
273
|
+
startFrom = toNumber(value, defaultValue)
|
|
279
274
|
}
|
|
280
275
|
|
|
281
|
-
|
|
276
|
+
return startFrom
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
282
280
|
* Recursive method for fix multi-line elements implementation in highlight.js
|
|
283
281
|
* Doing deep passage on child nodes.
|
|
284
282
|
* @param {HTMLElement} element
|
|
285
283
|
*/
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
}
|
|
284
|
+
function duplicateMultilineNodes (element) {
|
|
285
|
+
const nodes = element.childNodes
|
|
286
|
+
for (const node in nodes) {
|
|
287
|
+
if (nodes.hasOwnProperty(node)) {
|
|
288
|
+
const child = nodes[node]
|
|
289
|
+
if (getLinesCount(child.textContent) > 0) {
|
|
290
|
+
if (child.childNodes.length > 0) {
|
|
291
|
+
duplicateMultilineNodes(child)
|
|
292
|
+
} else {
|
|
293
|
+
duplicateMultilineNode(child.parentNode)
|
|
294
|
+
}
|
|
299
295
|
}
|
|
296
|
+
}
|
|
300
297
|
}
|
|
298
|
+
}
|
|
301
299
|
|
|
302
|
-
|
|
300
|
+
/**
|
|
303
301
|
* Method for fix multi-line elements implementation in highlight.js
|
|
304
302
|
* @param {HTMLElement} element
|
|
305
303
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if ( ! /hljs-/.test(className)) return;
|
|
304
|
+
function duplicateMultilineNode (element) {
|
|
305
|
+
const className = element.className
|
|
310
306
|
|
|
311
|
-
|
|
307
|
+
if (!/hljs-/.test(className)) return
|
|
312
308
|
|
|
313
|
-
|
|
314
|
-
var lineText = lines[i].length > 0 ? lines[i] : ' ';
|
|
315
|
-
result += format('<span class="{0}">{1}</span>\n', [ className, lineText ]);
|
|
316
|
-
}
|
|
309
|
+
const lines = getLines(element.innerHTML)
|
|
317
310
|
|
|
318
|
-
|
|
311
|
+
for (var i = 0, result = ''; i < lines.length; i++) {
|
|
312
|
+
const lineText = lines[i].length > 0 ? lines[i] : ' '
|
|
313
|
+
result += format('<span class="{0}">{1}</span>\n', [className, lineText])
|
|
319
314
|
}
|
|
320
315
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return text.split(BREAK_LINE_REGEXP);
|
|
324
|
-
}
|
|
316
|
+
element.innerHTML = result.trim()
|
|
317
|
+
}
|
|
325
318
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
319
|
+
function getLines (text) {
|
|
320
|
+
if (text.length === 0) return []
|
|
321
|
+
return text.split(BREAK_LINE_REGEXP)
|
|
322
|
+
}
|
|
329
323
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
324
|
+
function getLinesCount (text) {
|
|
325
|
+
return (text.trim().match(BREAK_LINE_REGEXP) || []).length
|
|
326
|
+
}
|
|
333
327
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
328
|
+
///
|
|
329
|
+
/// HELPERS
|
|
330
|
+
///
|
|
337
331
|
|
|
338
|
-
|
|
332
|
+
function async (func) {
|
|
333
|
+
w.setTimeout(func, 0)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
339
337
|
* {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript}
|
|
340
338
|
* @param {string} format
|
|
341
339
|
* @param {array} args
|
|
342
340
|
*/
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
341
|
+
function format (format, args) {
|
|
342
|
+
return format.replace(/\{(\d+)\}/g, function (m, n) {
|
|
343
|
+
return args[n] !== undefined ? args[n] : m
|
|
344
|
+
})
|
|
345
|
+
}
|
|
348
346
|
|
|
349
|
-
|
|
347
|
+
/**
|
|
350
348
|
* @param {HTMLElement} element Code block.
|
|
351
349
|
* @param {String} attrName Attribute name.
|
|
352
350
|
* @returns {String} Attribute value or empty.
|
|
353
351
|
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
352
|
+
function getAttribute (element, attrName) {
|
|
353
|
+
return element.hasAttribute(attrName) ? element.getAttribute(attrName) : null
|
|
354
|
+
}
|
|
357
355
|
|
|
358
|
-
|
|
356
|
+
/**
|
|
359
357
|
* @param {String} str Source string.
|
|
360
358
|
* @param {Number} fallback Fallback value.
|
|
361
359
|
* @returns Parsed number or fallback value.
|
|
362
360
|
*/
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}(window, document));
|
|
361
|
+
function toNumber (str, fallback) {
|
|
362
|
+
if (!str) return fallback
|
|
363
|
+
const number = Number(str)
|
|
364
|
+
return isFinite(number) ? number : fallback
|
|
365
|
+
}
|
|
366
|
+
}(window, document))
|