nodebb-plugin-markdown 8.14.5 → 9.0.2

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.
@@ -1,190 +1,373 @@
1
- /**
2
- * STOP! This file was edited from the version found in the repo
3
- * https://github.com/wcoder/highlightjs-line-numbers.js
4
- *
5
- * Changes:
6
- * - Made into a requirejs module
7
- * - Instead of passing window, document in as w and d, they
8
- * are defined at top of module
9
- */
10
- define('highlightjs-line-numbers', ['highlight'], function () {
11
- var w = window;
12
- var d = document;
13
-
14
- var TABLE_NAME = 'hljs-ln',
15
- LINE_NAME = 'hljs-ln-line',
16
- CODE_BLOCK_NAME = 'hljs-ln-code',
17
- NUMBERS_BLOCK_NAME = 'hljs-ln-numbers',
18
- NUMBER_LINE_NAME = 'hljs-ln-n',
19
- DATA_ATTR_NAME = 'data-line-number',
20
- BREAK_LINE_REGEXP = /\r\n|\r|\n/g;
21
-
22
- if (w.hljs) {
23
- w.hljs.initLineNumbersOnLoad = initLineNumbersOnLoad;
24
- w.hljs.lineNumbersBlock = lineNumbersBlock;
25
-
26
- addStyles();
27
- } else {
28
- w.console.error('highlight.js not detected!');
29
- }
30
-
31
- function addStyles () {
32
- var css = d.createElement('style');
33
- css.type = 'text/css';
34
- css.innerHTML = format(
35
- '.{0}{border-collapse:collapse}\
36
- .{0} td{padding:0}\
37
- .{1}:before{content:attr({2})}',
38
- [
39
- TABLE_NAME,
40
- NUMBER_LINE_NAME,
41
- DATA_ATTR_NAME
42
- ]);
43
- d.getElementsByTagName('head')[0].appendChild(css);
44
- }
45
-
46
- function initLineNumbersOnLoad (options) {
47
- if (d.readyState === 'complete') {
48
- documentReady(options);
49
- } else {
50
- w.addEventListener('DOMContentLoaded', function () {
51
- documentReady(options);
52
- });
53
- }
54
- }
55
-
56
- function documentReady (options) {
57
- try {
58
- var blocks = d.querySelectorAll('code.hljs');
59
-
60
- for (var i in blocks) {
61
- if (blocks.hasOwnProperty(i)) {
62
- lineNumbersBlock(blocks[i], options);
63
- }
64
- }
65
- } catch (e) {
66
- w.console.error('LineNumbers error: ', e);
67
- }
68
- }
69
-
70
- function lineNumbersBlock (element, options) {
71
- if (typeof element !== 'object') return;
72
-
73
- // define options or set default
74
- options = options || {
75
- singleLine: false
76
- };
77
-
78
- // convert options
79
- var firstLineIndex = !!options.singleLine ? 0 : 1;
80
-
81
- async(function () {
82
-
83
- duplicateMultilineNodes(element);
84
-
85
- element.innerHTML = addLineNumbersBlockFor(element.innerHTML, firstLineIndex);
86
- });
87
- }
88
-
89
- function addLineNumbersBlockFor (inputHtml, firstLineIndex) {
90
-
91
- var lines = getLines(inputHtml);
92
-
93
- // if last line contains only carriage return remove it
94
- if (lines[lines.length-1].trim() === '') {
95
- lines.pop();
96
- }
97
-
98
- if (lines.length > firstLineIndex) {
99
- var html = '';
100
-
101
- for (var i = 0, l = lines.length; i < l; i++) {
102
- html += format(
103
- '<tr>\
104
- <td class="{0}">\
105
- <div class="{1} {2}" {3}="{5}"></div>\
106
- </td>\
107
- <td class="{4}">\
108
- <div class="{1}">{6}</div>\
109
- </td>\
110
- </tr>',
111
- [
112
- NUMBERS_BLOCK_NAME,
113
- LINE_NAME,
114
- NUMBER_LINE_NAME,
115
- DATA_ATTR_NAME,
116
- CODE_BLOCK_NAME,
117
- i + 1,
118
- lines[i].length > 0 ? lines[i] : ' '
119
- ]);
120
- }
121
-
122
- return format('<table class="{0}">{1}</table>', [ TABLE_NAME, html ]);
123
- }
124
-
125
- return inputHtml;
126
- }
127
-
128
- /**
129
- * Recursive method for fix multi-line elements implementation in highlight.js
130
- * Doing deep passage on child nodes.
131
- * @param {HTMLElement} element
132
- */
133
- function duplicateMultilineNodes (element) {
134
- var nodes = element.childNodes;
135
- for (var node in nodes) {
136
- if (nodes.hasOwnProperty(node)) {
137
- var child = nodes[node];
138
- if (getLinesCount(child.textContent) > 0) {
139
- if (child.childNodes.length > 0) {
140
- duplicateMultilineNodes(child);
141
- } else {
142
- duplicateMultilineNode(child.parentNode);
143
- }
144
- }
145
- }
146
- }
147
- }
148
-
149
- /**
150
- * Method for fix multi-line elements implementation in highlight.js
151
- * @param {HTMLElement} element
152
- */
153
- function duplicateMultilineNode (element) {
154
- var className = element.className;
155
-
156
- if ( ! /hljs-/.test(className)) return;
157
-
158
- var lines = getLines(element.innerHTML);
159
-
160
- for (var i = 0, result = ''; i < lines.length; i++) {
161
- result += format('<span class="{0}">{1}</span>\n', [ className, lines[i] ]);
162
- }
163
-
164
- element.innerHTML = result.trim();
165
- }
166
-
167
- function getLines (text) {
168
- if (text.length === 0) return [];
169
- return text.split(BREAK_LINE_REGEXP);
170
- }
171
-
172
- function getLinesCount (text) {
173
- return (text.trim().match(BREAK_LINE_REGEXP) || []).length;
174
- }
175
-
176
- function async (func) {
177
- w.setTimeout(func, 0);
178
- }
179
-
180
- /**
181
- * {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript}
182
- * @param {string} format
183
- * @param {array} args
184
- */
185
- function format (format, args) {
186
- return format.replace(/\{(\d+)\}/g, function(m, n){
187
- return args[n] ? args[n] : m;
188
- });
189
- }
1
+ /**
2
+ * STOP! This file was edited from the version found in the repo
3
+ * https://github.com/wcoder/highlightjs-line-numbers.js
4
+ *
5
+ * Changes:
6
+ * - Made into a requirejs module
7
+ * - Instead of passing window, document in as w and d, they
8
+ * are defined at top of module
9
+ */
10
+ define('highlightjs-line-numbers', ['highlight'], function () {
11
+ var w = window;
12
+ var d = document;
13
+
14
+ var TABLE_NAME = 'hljs-ln',
15
+ LINE_NAME = 'hljs-ln-line',
16
+ CODE_BLOCK_NAME = 'hljs-ln-code',
17
+ NUMBERS_BLOCK_NAME = 'hljs-ln-numbers',
18
+ NUMBER_LINE_NAME = 'hljs-ln-n',
19
+ DATA_ATTR_NAME = 'data-line-number',
20
+ BREAK_LINE_REGEXP = /\r\n|\r|\n/g;
21
+
22
+ if (w.hljs) {
23
+ w.hljs.initLineNumbersOnLoad = initLineNumbersOnLoad;
24
+ w.hljs.lineNumbersBlock = lineNumbersBlock;
25
+ w.hljs.lineNumbersValue = lineNumbersValue;
26
+
27
+ addStyles();
28
+ } else {
29
+ w.console.error('highlight.js not detected!');
30
+ }
31
+
32
+ function isHljsLnCodeDescendant(domElt) {
33
+ var curElt = domElt;
34
+ while (curElt) {
35
+ if (curElt.className && curElt.className.indexOf('hljs-ln-code') !== -1) {
36
+ return true;
37
+ }
38
+ curElt = curElt.parentNode;
39
+ }
40
+ return false;
41
+ }
42
+
43
+ function getHljsLnTable(hljsLnDomElt) {
44
+ var curElt = hljsLnDomElt;
45
+ while (curElt.nodeName !== 'TABLE') {
46
+ curElt = curElt.parentNode;
47
+ }
48
+ return curElt;
49
+ }
50
+
51
+ // Function to workaround a copy issue with Microsoft Edge.
52
+ // Due to hljs-ln wrapping the lines of code inside a <table> element,
53
+ // itself wrapped inside a <pre> element, window.getSelection().toString()
54
+ // does not contain any line breaks. So we need to get them back using the
55
+ // rendered code in the DOM as reference.
56
+ function edgeGetSelectedCodeLines(selection) {
57
+ // current selected text without line breaks
58
+ var selectionText = selection.toString();
59
+
60
+ // get the <td> element wrapping the first line of selected code
61
+ var tdAnchor = selection.anchorNode;
62
+ while (tdAnchor.nodeName !== 'TD') {
63
+ tdAnchor = tdAnchor.parentNode;
64
+ }
65
+
66
+ // get the <td> element wrapping the last line of selected code
67
+ var tdFocus = selection.focusNode;
68
+ while (tdFocus.nodeName !== 'TD') {
69
+ tdFocus = tdFocus.parentNode;
70
+ }
71
+
72
+ // extract line numbers
73
+ var firstLineNumber = parseInt(tdAnchor.dataset.lineNumber);
74
+ var lastLineNumber = parseInt(tdFocus.dataset.lineNumber);
75
+
76
+ // multi-lines copied case
77
+ if (firstLineNumber != lastLineNumber) {
78
+
79
+ var firstLineText = tdAnchor.textContent;
80
+ var lastLineText = tdFocus.textContent;
81
+
82
+ // if the selection was made backward, swap values
83
+ if (firstLineNumber > lastLineNumber) {
84
+ var tmp = firstLineNumber;
85
+ firstLineNumber = lastLineNumber;
86
+ lastLineNumber = tmp;
87
+ tmp = firstLineText;
88
+ firstLineText = lastLineText;
89
+ lastLineText = tmp;
90
+ }
91
+
92
+ // discard not copied characters in first line
93
+ while (selectionText.indexOf(firstLineText) !== 0) {
94
+ firstLineText = firstLineText.slice(1);
95
+ }
96
+
97
+ // discard not copied characters in last line
98
+ while (selectionText.lastIndexOf(lastLineText) === -1) {
99
+ lastLineText = lastLineText.slice(0, -1);
100
+ }
101
+
102
+ // reconstruct and return the real copied text
103
+ var selectedText = firstLineText;
104
+ var hljsLnTable = getHljsLnTable(tdAnchor);
105
+ for (var i = firstLineNumber + 1 ; i < lastLineNumber ; ++i) {
106
+ var codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i]);
107
+ var codeLineElt = hljsLnTable.querySelector(codeLineSel);
108
+ selectedText += '\n' + codeLineElt.textContent;
109
+ }
110
+ selectedText += '\n' + lastLineText;
111
+ return selectedText;
112
+ // single copied line case
113
+ } else {
114
+ return selectionText;
115
+ }
116
+ }
117
+
118
+ // ensure consistent code copy/paste behavior across all browsers
119
+ // (see https://github.com/wcoder/highlightjs-line-numbers.js/issues/51)
120
+ document.addEventListener('copy', function(e) {
121
+ // get current selection
122
+ var selection = window.getSelection();
123
+ // override behavior when one wants to copy line of codes
124
+ if (isHljsLnCodeDescendant(selection.anchorNode)) {
125
+ var selectionText;
126
+ // workaround an issue with Microsoft Edge as copied line breaks
127
+ // are removed otherwise from the selection string
128
+ if (window.navigator.userAgent.indexOf('Edge') !== -1) {
129
+ selectionText = edgeGetSelectedCodeLines(selection);
130
+ } else {
131
+ // other browsers can directly use the selection string
132
+ selectionText = selection.toString();
133
+ }
134
+ e.clipboardData.setData('text/plain', selectionText);
135
+ e.preventDefault();
136
+ }
137
+ });
138
+
139
+ function addStyles () {
140
+ var css = d.createElement('style');
141
+ css.type = 'text/css';
142
+ css.innerHTML = format(
143
+ '.{0}{border-collapse:collapse}' +
144
+ '.{0} td{padding:0}' +
145
+ '.{1}:before{content:attr({2})}',
146
+ [
147
+ TABLE_NAME,
148
+ NUMBER_LINE_NAME,
149
+ DATA_ATTR_NAME
150
+ ]);
151
+ d.getElementsByTagName('head')[0].appendChild(css);
152
+ }
153
+
154
+ function initLineNumbersOnLoad (options) {
155
+ if (d.readyState === 'interactive' || d.readyState === 'complete') {
156
+ documentReady(options);
157
+ } else {
158
+ w.addEventListener('DOMContentLoaded', function () {
159
+ documentReady(options);
160
+ });
161
+ }
162
+ }
163
+
164
+ function documentReady (options) {
165
+ try {
166
+ var blocks = d.querySelectorAll('code.hljs,code.nohighlight');
167
+
168
+ for (var i in blocks) {
169
+ if (blocks.hasOwnProperty(i)) {
170
+ if (!isPluginDisabledForBlock(blocks[i])) {
171
+ lineNumbersBlock(blocks[i], options);
172
+ }
173
+ }
174
+ }
175
+ } catch (e) {
176
+ w.console.error('LineNumbers error: ', e);
177
+ }
178
+ }
179
+
180
+ function isPluginDisabledForBlock(element) {
181
+ return element.classList.contains('nohljsln');
182
+ }
183
+
184
+ function lineNumbersBlock (element, options) {
185
+ if (typeof element !== 'object') return;
186
+
187
+ async(function () {
188
+ element.innerHTML = lineNumbersInternal(element, options);
189
+ });
190
+ }
191
+
192
+ function lineNumbersValue (value, options) {
193
+ if (typeof value !== 'string') return;
194
+
195
+ var element = document.createElement('code')
196
+ element.innerHTML = value
197
+
198
+ return lineNumbersInternal(element, options);
199
+ }
200
+
201
+ function lineNumbersInternal (element, options) {
202
+
203
+ var internalOptions = mapOptions(element, options);
204
+
205
+ duplicateMultilineNodes(element);
206
+
207
+ return addLineNumbersBlockFor(element.innerHTML, internalOptions);
208
+ }
209
+
210
+ function addLineNumbersBlockFor (inputHtml, options) {
211
+ var lines = getLines(inputHtml);
212
+
213
+ // if last line contains only carriage return remove it
214
+ if (lines[lines.length-1].trim() === '') {
215
+ lines.pop();
216
+ }
217
+
218
+ if (lines.length > 1 || options.singleLine) {
219
+ var html = '';
220
+
221
+ for (var i = 0, l = lines.length; i < l; i++) {
222
+ html += format(
223
+ '<tr>' +
224
+ '<td class="{0} {1}" {3}="{5}">' +
225
+ '<div class="{2}" {3}="{5}"></div>' +
226
+ '</td>' +
227
+ '<td class="{0} {4}" {3}="{5}">' +
228
+ '{6}' +
229
+ '</td>' +
230
+ '</tr>',
231
+ [
232
+ LINE_NAME,
233
+ NUMBERS_BLOCK_NAME,
234
+ NUMBER_LINE_NAME,
235
+ DATA_ATTR_NAME,
236
+ CODE_BLOCK_NAME,
237
+ i + options.startFrom,
238
+ lines[i].length > 0 ? lines[i] : ' '
239
+ ]);
240
+ }
241
+
242
+ return format('<table class="{0}">{1}</table>', [ TABLE_NAME, html ]);
243
+ }
244
+
245
+ return inputHtml;
246
+ }
247
+
248
+ /**
249
+ * @param {HTMLElement} element Code block.
250
+ * @param {Object} options External API options.
251
+ * @returns {Object} Internal API options.
252
+ */
253
+ function mapOptions (element, options) {
254
+ options = options || {};
255
+ return {
256
+ singleLine: getSingleLineOption(options),
257
+ startFrom: getStartFromOption(element, options)
258
+ };
259
+ }
260
+
261
+ function getSingleLineOption (options) {
262
+ var defaultValue = false;
263
+ if (!!options.singleLine) {
264
+ return options.singleLine;
265
+ }
266
+ return defaultValue;
267
+ }
268
+
269
+ function getStartFromOption (element, options) {
270
+ var defaultValue = 1;
271
+ var startFrom = defaultValue;
272
+
273
+ if (isFinite(options.startFrom)) {
274
+ startFrom = options.startFrom;
275
+ }
276
+
277
+ // can be overridden because local option is priority
278
+ var value = getAttribute(element, 'data-ln-start-from');
279
+ if (value !== null) {
280
+ startFrom = toNumber(value, defaultValue);
281
+ }
282
+
283
+ return startFrom;
284
+ }
285
+
286
+ /**
287
+ * Recursive method for fix multi-line elements implementation in highlight.js
288
+ * Doing deep passage on child nodes.
289
+ * @param {HTMLElement} element
290
+ */
291
+ function duplicateMultilineNodes (element) {
292
+ var nodes = element.childNodes;
293
+ for (var node in nodes) {
294
+ if (nodes.hasOwnProperty(node)) {
295
+ var child = nodes[node];
296
+ if (getLinesCount(child.textContent) > 0) {
297
+ if (child.childNodes.length > 0) {
298
+ duplicateMultilineNodes(child);
299
+ } else {
300
+ duplicateMultilineNode(child.parentNode);
301
+ }
302
+ }
303
+ }
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Method for fix multi-line elements implementation in highlight.js
309
+ * @param {HTMLElement} element
310
+ */
311
+ function duplicateMultilineNode (element) {
312
+ var className = element.className;
313
+
314
+ if ( ! /hljs-/.test(className)) return;
315
+
316
+ var lines = getLines(element.innerHTML);
317
+
318
+ for (var i = 0, result = ''; i < lines.length; i++) {
319
+ var lineText = lines[i].length > 0 ? lines[i] : ' ';
320
+ result += format('<span class="{0}">{1}</span>\n', [ className, lineText ]);
321
+ }
322
+
323
+ element.innerHTML = result.trim();
324
+ }
325
+
326
+ function getLines (text) {
327
+ if (text.length === 0) return [];
328
+ return text.split(BREAK_LINE_REGEXP);
329
+ }
330
+
331
+ function getLinesCount (text) {
332
+ return (text.trim().match(BREAK_LINE_REGEXP) || []).length;
333
+ }
334
+
335
+ ///
336
+ /// HELPERS
337
+ ///
338
+
339
+ function async (func) {
340
+ w.setTimeout(func, 0);
341
+ }
342
+
343
+ /**
344
+ * {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript}
345
+ * @param {string} format
346
+ * @param {array} args
347
+ */
348
+ function format (format, args) {
349
+ return format.replace(/\{(\d+)\}/g, function(m, n){
350
+ return args[n] !== undefined ? args[n] : m;
351
+ });
352
+ }
353
+
354
+ /**
355
+ * @param {HTMLElement} element Code block.
356
+ * @param {String} attrName Attribute name.
357
+ * @returns {String} Attribute value or empty.
358
+ */
359
+ function getAttribute (element, attrName) {
360
+ return element.hasAttribute(attrName) ? element.getAttribute(attrName) : null;
361
+ }
362
+
363
+ /**
364
+ * @param {String} str Source string.
365
+ * @param {Number} fallback Fallback value.
366
+ * @returns Parsed number or fallback value.
367
+ */
368
+ function toNumber (str, fallback) {
369
+ if (!str) return fallback;
370
+ var number = Number(str);
371
+ return isFinite(number) ? number : fallback;
372
+ }
190
373
  });
@@ -1,11 +1,11 @@
1
- {
2
- "bold": "Fettschrift",
3
- "italic": "Kursivschrift",
4
- "list_item": "Listenpunkt",
5
- "strikethrough_text": "Durchgestrichen",
6
- "link_text": "Link Text",
7
- "link_url": "Link Adresse",
8
- "picture_text": "Bild Text",
9
- "picture_url": "Bild Link",
10
- "help_text": "Dieses Forum unterstützt Markdown. Für mehr Informationen, [hier klicken](http://commonmark.org/help/)"
11
- }
1
+ {
2
+ "bold": "Fettschrift",
3
+ "italic": "Kursivschrift",
4
+ "list_item": "Listenpunkt",
5
+ "strikethrough_text": "Durchgestrichen",
6
+ "link_text": "Link Text",
7
+ "link_url": "Link Adresse",
8
+ "picture_text": "Bild Text",
9
+ "picture_url": "Bild Link",
10
+ "help_text": "Dieses Forum unterstützt Markdown. Für mehr Informationen, [hier klicken](http://commonmark.org/help/)"
11
+ }
@@ -1,12 +1,12 @@
1
- {
2
- "bold": "bolded text",
3
- "italic": "italicised text",
4
- "list_item": "list item",
5
- "strikethrough_text": "strikethrough text",
6
- "code_text": "code_text",
7
- "link_text": "link text",
8
- "link_url": "link url",
9
- "picture_text": "alt text",
10
- "picture_url": "image url",
11
- "help_text": "This forum is powered by Markdown. For full documentation, [click here](http://commonmark.org/help/)"
1
+ {
2
+ "bold": "bolded text",
3
+ "italic": "italicised text",
4
+ "list_item": "list item",
5
+ "strikethrough_text": "strikethrough text",
6
+ "code_text": "code_text",
7
+ "link_text": "link text",
8
+ "link_url": "link url",
9
+ "picture_text": "alt text",
10
+ "picture_url": "image url",
11
+ "help_text": "This forum is powered by Markdown. For full documentation, [click here](http://commonmark.org/help/)"
12
12
  }
@@ -1,11 +1,11 @@
1
- {
2
- "bold": "متن پررنگ",
3
- "italic": "متن ایتالیک ( کج )",
4
- "list_item": "لیست",
5
- "strikethrough_text": "متن خط خورده",
6
- "link_text": "متن لینک",
7
- "link_url": "آدرس لینک",
8
- "picture_text": "متن جایگزین",
9
- "picture_url": "آدرس عکس",
10
- "help_text": "این انجمن از زبان مارک دون استفاده می کند، برای اطلاعات بیشتر [اینجا](http://commonmark.org/help/) کلیک کنید!"
11
- }
1
+ {
2
+ "bold": "متن پررنگ",
3
+ "italic": "متن ایتالیک ( کج )",
4
+ "list_item": "لیست",
5
+ "strikethrough_text": "متن خط خورده",
6
+ "link_text": "متن لینک",
7
+ "link_url": "آدرس لینک",
8
+ "picture_text": "متن جایگزین",
9
+ "picture_url": "آدرس عکس",
10
+ "help_text": "این انجمن از زبان مارک دون استفاده می کند، برای اطلاعات بیشتر [اینجا](http://commonmark.org/help/) کلیک کنید!"
11
+ }
@@ -1,11 +1,11 @@
1
- {
2
- "bold": "texte en gras",
3
- "italic": "texte en italique",
4
- "list_item": "élément de liste",
5
- "strikethrough_text": "strikethrough text",
6
- "link_text": "texte du lien",
7
- "link_url": "url du lien",
8
- "picture_text": "text alternatif",
9
- "picture_url": "url de l'image",
10
- "help_text": "Ce forum utilise la syntaxe Markdown. Pour accéder à la documentation, suivre ce [lien](http://commonmark.org/help/)"
11
- }
1
+ {
2
+ "bold": "texte en gras",
3
+ "italic": "texte en italique",
4
+ "list_item": "élément de liste",
5
+ "strikethrough_text": "strikethrough text",
6
+ "link_text": "texte du lien",
7
+ "link_url": "url du lien",
8
+ "picture_text": "text alternatif",
9
+ "picture_url": "url de l'image",
10
+ "help_text": "Ce forum utilise la syntaxe Markdown. Pour accéder à la documentation, suivre ce [lien](http://commonmark.org/help/)"
11
+ }