@licium/editor-plugin-code-syntax-highlight 3.1.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/LICENSE +21 -0
- package/README.md +310 -0
- package/dist/toastui-editor-plugin-code-syntax-highlight-all.js +19547 -0
- package/dist/toastui-editor-plugin-code-syntax-highlight.css +171 -0
- package/dist/toastui-editor-plugin-code-syntax-highlight.js +1305 -0
- package/package.json +59 -0
- package/types/index.d.ts +21 -0
|
@@ -0,0 +1,1305 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* TOAST UI Editor : Code Syntax Highlight Plugin
|
|
3
|
+
* @version 3.1.0 | Sun Dec 28 2025
|
|
4
|
+
* @author NHN Cloud FE Development Lab <dl_javascript@nhn.com>
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
/******/ (function() { // webpackBootstrap
|
|
8
|
+
/******/ "use strict";
|
|
9
|
+
/******/ var __webpack_modules__ = ({
|
|
10
|
+
|
|
11
|
+
/***/ 928:
|
|
12
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
13
|
+
|
|
14
|
+
/* eslint-disable complexity */
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Returns the first index at which a given element can be found in the array.
|
|
17
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var isArray = __webpack_require__(322);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @module array
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns the first index at which a given element can be found in the array
|
|
30
|
+
* from start index(default 0), or -1 if it is not present.
|
|
31
|
+
* It compares searchElement to elements of the Array using strict equality
|
|
32
|
+
* (the same method used by the ===, or triple-equals, operator).
|
|
33
|
+
* @param {*} searchElement Element to locate in the array
|
|
34
|
+
* @param {Array} array Array that will be traversed.
|
|
35
|
+
* @param {number} startIndex Start index in array for searching (default 0)
|
|
36
|
+
* @returns {number} the First index at which a given element, or -1 if it is not present
|
|
37
|
+
* @memberof module:array
|
|
38
|
+
* @example
|
|
39
|
+
* // ES6
|
|
40
|
+
* import inArray from 'tui-code-snippet/array/inArray';
|
|
41
|
+
*
|
|
42
|
+
* // CommonJS
|
|
43
|
+
* const inArray = require('tui-code-snippet/array/inArray');
|
|
44
|
+
*
|
|
45
|
+
* const arr = ['one', 'two', 'three', 'four'];
|
|
46
|
+
* const idx1 = inArray('one', arr, 3); // -1
|
|
47
|
+
* const idx2 = inArray('one', arr); // 0
|
|
48
|
+
*/
|
|
49
|
+
function inArray(searchElement, array, startIndex) {
|
|
50
|
+
var i;
|
|
51
|
+
var length;
|
|
52
|
+
startIndex = startIndex || 0;
|
|
53
|
+
|
|
54
|
+
if (!isArray(array)) {
|
|
55
|
+
return -1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (Array.prototype.indexOf) {
|
|
59
|
+
return Array.prototype.indexOf.call(array, searchElement, startIndex);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
length = array.length;
|
|
63
|
+
for (i = startIndex; startIndex >= 0 && i < length; i += 1) {
|
|
64
|
+
if (array[i] === searchElement) {
|
|
65
|
+
return i;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return -1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = inArray;
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/***/ }),
|
|
76
|
+
|
|
77
|
+
/***/ 690:
|
|
78
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @fileoverview Execute the provided callback once for each property of object(or element of array) which actually exist.
|
|
82
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
var isArray = __webpack_require__(322);
|
|
88
|
+
var forEachArray = __webpack_require__(893);
|
|
89
|
+
var forEachOwnProperties = __webpack_require__(956);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @module collection
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Execute the provided callback once for each property of object(or element of array) which actually exist.
|
|
97
|
+
* If the object is Array-like object(ex-arguments object), It needs to transform to Array.(see 'ex2' of example).
|
|
98
|
+
* If the callback function returns false, the loop will be stopped.
|
|
99
|
+
* Callback function(iteratee) is invoked with three arguments:
|
|
100
|
+
* 1) The value of the property(or The value of the element)
|
|
101
|
+
* 2) The name of the property(or The index of the element)
|
|
102
|
+
* 3) The object being traversed
|
|
103
|
+
* @param {Object} obj The object that will be traversed
|
|
104
|
+
* @param {function} iteratee Callback function
|
|
105
|
+
* @param {Object} [context] Context(this) of callback function
|
|
106
|
+
* @memberof module:collection
|
|
107
|
+
* @example
|
|
108
|
+
* // ES6
|
|
109
|
+
* import forEach from 'tui-code-snippet/collection/forEach';
|
|
110
|
+
*
|
|
111
|
+
* // CommonJS
|
|
112
|
+
* const forEach = require('tui-code-snippet/collection/forEach');
|
|
113
|
+
*
|
|
114
|
+
* let sum = 0;
|
|
115
|
+
*
|
|
116
|
+
* forEach([1,2,3], function(value){
|
|
117
|
+
* sum += value;
|
|
118
|
+
* });
|
|
119
|
+
* alert(sum); // 6
|
|
120
|
+
*
|
|
121
|
+
* // In case of Array-like object
|
|
122
|
+
* const array = Array.prototype.slice.call(arrayLike); // change to array
|
|
123
|
+
* forEach(array, function(value){
|
|
124
|
+
* sum += value;
|
|
125
|
+
* });
|
|
126
|
+
*/
|
|
127
|
+
function forEach(obj, iteratee, context) {
|
|
128
|
+
if (isArray(obj)) {
|
|
129
|
+
forEachArray(obj, iteratee, context);
|
|
130
|
+
} else {
|
|
131
|
+
forEachOwnProperties(obj, iteratee, context);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = forEach;
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
/***/ }),
|
|
139
|
+
|
|
140
|
+
/***/ 893:
|
|
141
|
+
/***/ (function(module) {
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @fileoverview Execute the provided callback once for each element present in the array(or Array-like object) in ascending order.
|
|
145
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Execute the provided callback once for each element present
|
|
152
|
+
* in the array(or Array-like object) in ascending order.
|
|
153
|
+
* If the callback function returns false, the loop will be stopped.
|
|
154
|
+
* Callback function(iteratee) is invoked with three arguments:
|
|
155
|
+
* 1) The value of the element
|
|
156
|
+
* 2) The index of the element
|
|
157
|
+
* 3) The array(or Array-like object) being traversed
|
|
158
|
+
* @param {Array|Arguments|NodeList} arr The array(or Array-like object) that will be traversed
|
|
159
|
+
* @param {function} iteratee Callback function
|
|
160
|
+
* @param {Object} [context] Context(this) of callback function
|
|
161
|
+
* @memberof module:collection
|
|
162
|
+
* @example
|
|
163
|
+
* // ES6
|
|
164
|
+
* import forEachArray from 'tui-code-snippet/collection/forEachArray';
|
|
165
|
+
*
|
|
166
|
+
* // CommonJS
|
|
167
|
+
* const forEachArray = require('tui-code-snippet/collection/forEachArray');
|
|
168
|
+
*
|
|
169
|
+
* let sum = 0;
|
|
170
|
+
*
|
|
171
|
+
* forEachArray([1,2,3], function(value){
|
|
172
|
+
* sum += value;
|
|
173
|
+
* });
|
|
174
|
+
* alert(sum); // 6
|
|
175
|
+
*/
|
|
176
|
+
function forEachArray(arr, iteratee, context) {
|
|
177
|
+
var index = 0;
|
|
178
|
+
var len = arr.length;
|
|
179
|
+
|
|
180
|
+
context = context || null;
|
|
181
|
+
|
|
182
|
+
for (; index < len; index += 1) {
|
|
183
|
+
if (iteratee.call(context, arr[index], index, arr) === false) {
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = forEachArray;
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
/***/ }),
|
|
193
|
+
|
|
194
|
+
/***/ 956:
|
|
195
|
+
/***/ (function(module) {
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @fileoverview Execute the provided callback once for each property of object which actually exist.
|
|
199
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Execute the provided callback once for each property of object which actually exist.
|
|
206
|
+
* If the callback function returns false, the loop will be stopped.
|
|
207
|
+
* Callback function(iteratee) is invoked with three arguments:
|
|
208
|
+
* 1) The value of the property
|
|
209
|
+
* 2) The name of the property
|
|
210
|
+
* 3) The object being traversed
|
|
211
|
+
* @param {Object} obj The object that will be traversed
|
|
212
|
+
* @param {function} iteratee Callback function
|
|
213
|
+
* @param {Object} [context] Context(this) of callback function
|
|
214
|
+
* @memberof module:collection
|
|
215
|
+
* @example
|
|
216
|
+
* // ES6
|
|
217
|
+
* import forEachOwnProperties from 'tui-code-snippet/collection/forEachOwnProperties';
|
|
218
|
+
*
|
|
219
|
+
* // CommonJS
|
|
220
|
+
* const forEachOwnProperties = require('tui-code-snippet/collection/forEachOwnProperties');
|
|
221
|
+
*
|
|
222
|
+
* let sum = 0;
|
|
223
|
+
*
|
|
224
|
+
* forEachOwnProperties({a:1,b:2,c:3}, function(value){
|
|
225
|
+
* sum += value;
|
|
226
|
+
* });
|
|
227
|
+
* alert(sum); // 6
|
|
228
|
+
*/
|
|
229
|
+
function forEachOwnProperties(obj, iteratee, context) {
|
|
230
|
+
var key;
|
|
231
|
+
|
|
232
|
+
context = context || null;
|
|
233
|
+
|
|
234
|
+
for (key in obj) {
|
|
235
|
+
if (obj.hasOwnProperty(key)) {
|
|
236
|
+
if (iteratee.call(context, obj[key], key, obj) === false) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
module.exports = forEachOwnProperties;
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
/***/ }),
|
|
247
|
+
|
|
248
|
+
/***/ 990:
|
|
249
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @fileoverview Transform the Array-like object to Array.
|
|
253
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
var forEachArray = __webpack_require__(893);
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Transform the Array-like object to Array.
|
|
262
|
+
* In low IE (below 8), Array.prototype.slice.call is not perfect. So, try-catch statement is used.
|
|
263
|
+
* @param {*} arrayLike Array-like object
|
|
264
|
+
* @returns {Array} Array
|
|
265
|
+
* @memberof module:collection
|
|
266
|
+
* @example
|
|
267
|
+
* // ES6
|
|
268
|
+
* import toArray from 'tui-code-snippet/collection/toArray';
|
|
269
|
+
*
|
|
270
|
+
* // CommonJS
|
|
271
|
+
* const toArray = require('tui-code-snippet/collection/toArray');
|
|
272
|
+
*
|
|
273
|
+
* const arrayLike = {
|
|
274
|
+
* 0: 'one',
|
|
275
|
+
* 1: 'two',
|
|
276
|
+
* 2: 'three',
|
|
277
|
+
* 3: 'four',
|
|
278
|
+
* length: 4
|
|
279
|
+
* };
|
|
280
|
+
* const result = toArray(arrayLike);
|
|
281
|
+
*
|
|
282
|
+
* alert(result instanceof Array); // true
|
|
283
|
+
* alert(result); // one,two,three,four
|
|
284
|
+
*/
|
|
285
|
+
function toArray(arrayLike) {
|
|
286
|
+
var arr;
|
|
287
|
+
try {
|
|
288
|
+
arr = Array.prototype.slice.call(arrayLike);
|
|
289
|
+
} catch (e) {
|
|
290
|
+
arr = [];
|
|
291
|
+
forEachArray(arrayLike, function(value) {
|
|
292
|
+
arr.push(value);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return arr;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
module.exports = toArray;
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
/***/ }),
|
|
303
|
+
|
|
304
|
+
/***/ 24:
|
|
305
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* @fileoverview Set className value
|
|
309
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
var isArray = __webpack_require__(322);
|
|
315
|
+
var isUndefined = __webpack_require__(929);
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Set className value
|
|
319
|
+
* @param {(HTMLElement|SVGElement)} element - target element
|
|
320
|
+
* @param {(string|string[])} cssClass - class names
|
|
321
|
+
* @private
|
|
322
|
+
*/
|
|
323
|
+
function setClassName(element, cssClass) {
|
|
324
|
+
cssClass = isArray(cssClass) ? cssClass.join(' ') : cssClass;
|
|
325
|
+
|
|
326
|
+
cssClass = cssClass.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
|
327
|
+
|
|
328
|
+
if (isUndefined(element.className.baseVal)) {
|
|
329
|
+
element.className = cssClass;
|
|
330
|
+
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
element.className.baseVal = cssClass;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
module.exports = setClassName;
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
/***/ }),
|
|
341
|
+
|
|
342
|
+
/***/ 204:
|
|
343
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* @fileoverview Add css class to element
|
|
347
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
348
|
+
*/
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
var forEach = __webpack_require__(690);
|
|
353
|
+
var inArray = __webpack_require__(928);
|
|
354
|
+
var getClass = __webpack_require__(902);
|
|
355
|
+
var setClassName = __webpack_require__(24);
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* domUtil module
|
|
359
|
+
* @module domUtil
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Add css class to element
|
|
364
|
+
* @param {(HTMLElement|SVGElement)} element - target element
|
|
365
|
+
* @param {...string} cssClass - css classes to add
|
|
366
|
+
* @memberof module:domUtil
|
|
367
|
+
*/
|
|
368
|
+
function addClass(element) {
|
|
369
|
+
var cssClass = Array.prototype.slice.call(arguments, 1);
|
|
370
|
+
var classList = element.classList;
|
|
371
|
+
var newClass = [];
|
|
372
|
+
var origin;
|
|
373
|
+
|
|
374
|
+
if (classList) {
|
|
375
|
+
forEach(cssClass, function(name) {
|
|
376
|
+
element.classList.add(name);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
origin = getClass(element);
|
|
383
|
+
|
|
384
|
+
if (origin) {
|
|
385
|
+
cssClass = [].concat(origin.split(/\s+/), cssClass);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
forEach(cssClass, function(cls) {
|
|
389
|
+
if (inArray(cls, newClass) < 0) {
|
|
390
|
+
newClass.push(cls);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
setClassName(element, newClass);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
module.exports = addClass;
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
/***/ }),
|
|
401
|
+
|
|
402
|
+
/***/ 522:
|
|
403
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @fileoverview Setting element style
|
|
407
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
var isString = __webpack_require__(758);
|
|
413
|
+
var forEach = __webpack_require__(690);
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Setting element style
|
|
417
|
+
* @param {(HTMLElement|SVGElement)} element - element to setting style
|
|
418
|
+
* @param {(string|object)} key - style prop name or {prop: value} pair object
|
|
419
|
+
* @param {string} [value] - style value
|
|
420
|
+
* @memberof module:domUtil
|
|
421
|
+
*/
|
|
422
|
+
function css(element, key, value) {
|
|
423
|
+
var style = element.style;
|
|
424
|
+
|
|
425
|
+
if (isString(key)) {
|
|
426
|
+
style[key] = value;
|
|
427
|
+
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
forEach(key, function(v, k) {
|
|
432
|
+
style[k] = v;
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
module.exports = css;
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
/***/ }),
|
|
440
|
+
|
|
441
|
+
/***/ 902:
|
|
442
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* @fileoverview Get HTML element's design classes.
|
|
446
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
447
|
+
*/
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
var isUndefined = __webpack_require__(929);
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Get HTML element's design classes.
|
|
455
|
+
* @param {(HTMLElement|SVGElement)} element target element
|
|
456
|
+
* @returns {string} element css class name
|
|
457
|
+
* @memberof module:domUtil
|
|
458
|
+
*/
|
|
459
|
+
function getClass(element) {
|
|
460
|
+
if (!element || !element.className) {
|
|
461
|
+
return '';
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (isUndefined(element.className.baseVal)) {
|
|
465
|
+
return element.className;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return element.className.baseVal;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
module.exports = getClass;
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
/***/ }),
|
|
475
|
+
|
|
476
|
+
/***/ 714:
|
|
477
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* @fileoverview Check element has specific css class
|
|
481
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
var inArray = __webpack_require__(928);
|
|
487
|
+
var getClass = __webpack_require__(902);
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Check element has specific css class
|
|
491
|
+
* @param {(HTMLElement|SVGElement)} element - target element
|
|
492
|
+
* @param {string} cssClass - css class
|
|
493
|
+
* @returns {boolean}
|
|
494
|
+
* @memberof module:domUtil
|
|
495
|
+
*/
|
|
496
|
+
function hasClass(element, cssClass) {
|
|
497
|
+
var origin;
|
|
498
|
+
|
|
499
|
+
if (element.classList) {
|
|
500
|
+
return element.classList.contains(cssClass);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
origin = getClass(element).split(/\s+/);
|
|
504
|
+
|
|
505
|
+
return inArray(cssClass, origin) > -1;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
module.exports = hasClass;
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
/***/ }),
|
|
512
|
+
|
|
513
|
+
/***/ 462:
|
|
514
|
+
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* @fileoverview Remove css class from element
|
|
518
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
519
|
+
*/
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
var forEachArray = __webpack_require__(893);
|
|
524
|
+
var inArray = __webpack_require__(928);
|
|
525
|
+
var getClass = __webpack_require__(902);
|
|
526
|
+
var setClassName = __webpack_require__(24);
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Remove css class from element
|
|
530
|
+
* @param {(HTMLElement|SVGElement)} element - target element
|
|
531
|
+
* @param {...string} cssClass - css classes to remove
|
|
532
|
+
* @memberof module:domUtil
|
|
533
|
+
*/
|
|
534
|
+
function removeClass(element) {
|
|
535
|
+
var cssClass = Array.prototype.slice.call(arguments, 1);
|
|
536
|
+
var classList = element.classList;
|
|
537
|
+
var origin, newClass;
|
|
538
|
+
|
|
539
|
+
if (classList) {
|
|
540
|
+
forEachArray(cssClass, function(name) {
|
|
541
|
+
classList.remove(name);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
origin = getClass(element).split(/\s+/);
|
|
548
|
+
newClass = [];
|
|
549
|
+
forEachArray(origin, function(name) {
|
|
550
|
+
if (inArray(name, cssClass) < 0) {
|
|
551
|
+
newClass.push(name);
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
setClassName(element, newClass);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
module.exports = removeClass;
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
/***/ }),
|
|
562
|
+
|
|
563
|
+
/***/ 322:
|
|
564
|
+
/***/ (function(module) {
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* @fileoverview Check whether the given variable is an instance of Array or not.
|
|
568
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Check whether the given variable is an instance of Array or not.
|
|
575
|
+
* If the given variable is an instance of Array, return true.
|
|
576
|
+
* @param {*} obj - Target for checking
|
|
577
|
+
* @returns {boolean} Is array instance?
|
|
578
|
+
* @memberof module:type
|
|
579
|
+
*/
|
|
580
|
+
function isArray(obj) {
|
|
581
|
+
return obj instanceof Array;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
module.exports = isArray;
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
/***/ }),
|
|
588
|
+
|
|
589
|
+
/***/ 294:
|
|
590
|
+
/***/ (function(module) {
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* @fileoverview Check whether the given variable is a function or not.
|
|
594
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
595
|
+
*/
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Check whether the given variable is a function or not.
|
|
601
|
+
* If the given variable is a function, return true.
|
|
602
|
+
* @param {*} obj - Target for checking
|
|
603
|
+
* @returns {boolean} Is function?
|
|
604
|
+
* @memberof module:type
|
|
605
|
+
*/
|
|
606
|
+
function isFunction(obj) {
|
|
607
|
+
return obj instanceof Function;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
module.exports = isFunction;
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
/***/ }),
|
|
614
|
+
|
|
615
|
+
/***/ 758:
|
|
616
|
+
/***/ (function(module) {
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* @fileoverview Check whether the given variable is a string or not.
|
|
620
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
621
|
+
*/
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Check whether the given variable is a string or not.
|
|
627
|
+
* If the given variable is a string, return true.
|
|
628
|
+
* @param {*} obj - Target for checking
|
|
629
|
+
* @returns {boolean} Is string?
|
|
630
|
+
* @memberof module:type
|
|
631
|
+
*/
|
|
632
|
+
function isString(obj) {
|
|
633
|
+
return typeof obj === 'string' || obj instanceof String;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
module.exports = isString;
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
/***/ }),
|
|
640
|
+
|
|
641
|
+
/***/ 929:
|
|
642
|
+
/***/ (function(module) {
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* @fileoverview Check whether the given variable is undefined or not.
|
|
646
|
+
* @author NHN FE Development Lab <dl_javascript@nhn.com>
|
|
647
|
+
*/
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Check whether the given variable is undefined or not.
|
|
653
|
+
* If the given variable is undefined, returns true.
|
|
654
|
+
* @param {*} obj - Target for checking
|
|
655
|
+
* @returns {boolean} Is undefined?
|
|
656
|
+
* @memberof module:type
|
|
657
|
+
*/
|
|
658
|
+
function isUndefined(obj) {
|
|
659
|
+
return obj === undefined; // eslint-disable-line no-undefined
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
module.exports = isUndefined;
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
/***/ })
|
|
666
|
+
|
|
667
|
+
/******/ });
|
|
668
|
+
/************************************************************************/
|
|
669
|
+
/******/ // The module cache
|
|
670
|
+
/******/ var __webpack_module_cache__ = {};
|
|
671
|
+
/******/
|
|
672
|
+
/******/ // The require function
|
|
673
|
+
/******/ function __webpack_require__(moduleId) {
|
|
674
|
+
/******/ // Check if module is in cache
|
|
675
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
676
|
+
/******/ if (cachedModule !== undefined) {
|
|
677
|
+
/******/ return cachedModule.exports;
|
|
678
|
+
/******/ }
|
|
679
|
+
/******/ // Create a new module (and put it into the cache)
|
|
680
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
681
|
+
/******/ // no module.id needed
|
|
682
|
+
/******/ // no module.loaded needed
|
|
683
|
+
/******/ exports: {}
|
|
684
|
+
/******/ };
|
|
685
|
+
/******/
|
|
686
|
+
/******/ // Execute the module function
|
|
687
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
688
|
+
/******/
|
|
689
|
+
/******/ // Return the exports of the module
|
|
690
|
+
/******/ return module.exports;
|
|
691
|
+
/******/ }
|
|
692
|
+
/******/
|
|
693
|
+
/************************************************************************/
|
|
694
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
695
|
+
/******/ !function() {
|
|
696
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
697
|
+
/******/ __webpack_require__.n = function(module) {
|
|
698
|
+
/******/ var getter = module && module.__esModule ?
|
|
699
|
+
/******/ function() { return module['default']; } :
|
|
700
|
+
/******/ function() { return module; };
|
|
701
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
702
|
+
/******/ return getter;
|
|
703
|
+
/******/ };
|
|
704
|
+
/******/ }();
|
|
705
|
+
/******/
|
|
706
|
+
/******/ /* webpack/runtime/define property getters */
|
|
707
|
+
/******/ !function() {
|
|
708
|
+
/******/ // define getter functions for harmony exports
|
|
709
|
+
/******/ __webpack_require__.d = function(exports, definition) {
|
|
710
|
+
/******/ for(var key in definition) {
|
|
711
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
712
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
713
|
+
/******/ }
|
|
714
|
+
/******/ }
|
|
715
|
+
/******/ };
|
|
716
|
+
/******/ }();
|
|
717
|
+
/******/
|
|
718
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
719
|
+
/******/ !function() {
|
|
720
|
+
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
721
|
+
/******/ }();
|
|
722
|
+
/******/
|
|
723
|
+
/************************************************************************/
|
|
724
|
+
var __webpack_exports__ = {};
|
|
725
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
726
|
+
!function() {
|
|
727
|
+
|
|
728
|
+
// EXPORTS
|
|
729
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
730
|
+
"default": function() { return /* binding */ src; }
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/type/isFunction.js
|
|
734
|
+
var isFunction = __webpack_require__(294);
|
|
735
|
+
var isFunction_default = /*#__PURE__*/__webpack_require__.n(isFunction);
|
|
736
|
+
;// CONCATENATED MODULE: ./src/renderers/toHTMLRenderers.ts
|
|
737
|
+
var BACKTICK_COUNT = 3;
|
|
738
|
+
function getHTMLRenderers(prism) {
|
|
739
|
+
return {
|
|
740
|
+
codeBlock: function (node) {
|
|
741
|
+
var _a = node, fenceLength = _a.fenceLength, info = _a.info;
|
|
742
|
+
var infoWords = info ? info.split(/\s+/) : [];
|
|
743
|
+
var preClasses = [];
|
|
744
|
+
var codeAttrs = {};
|
|
745
|
+
if (fenceLength > BACKTICK_COUNT) {
|
|
746
|
+
codeAttrs['data-backticks'] = fenceLength;
|
|
747
|
+
}
|
|
748
|
+
var content = node.literal;
|
|
749
|
+
if (infoWords.length && infoWords[0].length) {
|
|
750
|
+
var lang = infoWords[0];
|
|
751
|
+
preClasses.push("lang-" + lang);
|
|
752
|
+
codeAttrs['data-language'] = lang;
|
|
753
|
+
var registeredLang = prism.languages[lang];
|
|
754
|
+
if (registeredLang) {
|
|
755
|
+
content = prism.highlight(node.literal, registeredLang, lang);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return [
|
|
759
|
+
{ type: 'openTag', tagName: 'pre', classNames: preClasses },
|
|
760
|
+
{ type: 'openTag', tagName: 'code', attributes: codeAttrs },
|
|
761
|
+
{ type: 'html', content: content },
|
|
762
|
+
{ type: 'closeTag', tagName: 'code' },
|
|
763
|
+
{ type: 'closeTag', tagName: 'pre' },
|
|
764
|
+
];
|
|
765
|
+
},
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/type/isString.js
|
|
770
|
+
var isString = __webpack_require__(758);
|
|
771
|
+
var isString_default = /*#__PURE__*/__webpack_require__.n(isString);
|
|
772
|
+
;// CONCATENATED MODULE: ./src/utils/common.ts
|
|
773
|
+
function flatten(arr) {
|
|
774
|
+
return arr.reduce(function (a, b) { return a.concat(Array.isArray(b) ? flatten(b) : b); }, []);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
;// CONCATENATED MODULE: ./src/plugins/codeSyntaxHighlighting.ts
|
|
778
|
+
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from) {
|
|
779
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
780
|
+
to[j] = from[i];
|
|
781
|
+
return to;
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
var NODE_TYPE = 'codeBlock';
|
|
786
|
+
function findCodeBlocks(doc) {
|
|
787
|
+
var descendants = [];
|
|
788
|
+
doc.descendants(function (node, pos) {
|
|
789
|
+
if (node.isBlock && node.type.name === NODE_TYPE) {
|
|
790
|
+
descendants.push({ node: node, pos: pos });
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
return descendants;
|
|
794
|
+
}
|
|
795
|
+
function parseTokens(tokens, classNames) {
|
|
796
|
+
if (classNames === void 0) { classNames = []; }
|
|
797
|
+
if (isString_default()(tokens)) {
|
|
798
|
+
return [{ text: tokens, classes: classNames }];
|
|
799
|
+
}
|
|
800
|
+
return tokens.map(function (token) {
|
|
801
|
+
var _a = token, type = _a.type, alias = _a.alias;
|
|
802
|
+
var typeClassNames = [];
|
|
803
|
+
var aliasClassNames = [];
|
|
804
|
+
if (type) {
|
|
805
|
+
typeClassNames = ['token', type];
|
|
806
|
+
}
|
|
807
|
+
if (alias) {
|
|
808
|
+
aliasClassNames = isString_default()(alias) ? [alias] : alias;
|
|
809
|
+
}
|
|
810
|
+
var classes = __spreadArray(__spreadArray(__spreadArray([], classNames), typeClassNames), aliasClassNames);
|
|
811
|
+
return isString_default()(token)
|
|
812
|
+
? {
|
|
813
|
+
text: token,
|
|
814
|
+
classes: classes,
|
|
815
|
+
}
|
|
816
|
+
: parseTokens(token.content, classes);
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
function getDecorations(doc, context, prism) {
|
|
820
|
+
var pmView = context.pmView;
|
|
821
|
+
var decorations = [];
|
|
822
|
+
var codeBlocks = findCodeBlocks(doc);
|
|
823
|
+
codeBlocks.forEach(function (_a) {
|
|
824
|
+
var pos = _a.pos, node = _a.node;
|
|
825
|
+
var language = node.attrs.language;
|
|
826
|
+
var registeredLang = prism.languages[language];
|
|
827
|
+
var prismTokens = registeredLang ? prism.tokenize(node.textContent, registeredLang) : [];
|
|
828
|
+
var nodeInfos = flatten(parseTokens(prismTokens));
|
|
829
|
+
var startPos = pos + 1;
|
|
830
|
+
nodeInfos.forEach(function (_a) {
|
|
831
|
+
var text = _a.text, classes = _a.classes;
|
|
832
|
+
var from = startPos;
|
|
833
|
+
var to = from + text.length;
|
|
834
|
+
startPos = to;
|
|
835
|
+
var classNames = classes.join(' ');
|
|
836
|
+
var decoration = pmView.Decoration.inline(from, to, {
|
|
837
|
+
class: classNames,
|
|
838
|
+
});
|
|
839
|
+
if (classNames.length) {
|
|
840
|
+
decorations.push(decoration);
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
return pmView.DecorationSet.create(doc, decorations);
|
|
845
|
+
}
|
|
846
|
+
function codeSyntaxHighlighting(context, prism) {
|
|
847
|
+
return new context.pmState.Plugin({
|
|
848
|
+
state: {
|
|
849
|
+
init: function (_, _a) {
|
|
850
|
+
var doc = _a.doc;
|
|
851
|
+
return getDecorations(doc, context, prism);
|
|
852
|
+
},
|
|
853
|
+
apply: function (tr, set) {
|
|
854
|
+
if (!tr.docChanged) {
|
|
855
|
+
return set.map(tr.mapping, tr.doc);
|
|
856
|
+
}
|
|
857
|
+
return getDecorations(tr.doc, context, prism);
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
props: {
|
|
861
|
+
decorations: function (state) {
|
|
862
|
+
return this.getState(state);
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/domUtil/addClass.js
|
|
869
|
+
var addClass = __webpack_require__(204);
|
|
870
|
+
var addClass_default = /*#__PURE__*/__webpack_require__.n(addClass);
|
|
871
|
+
;// CONCATENATED MODULE: ./src/utils/dom.ts
|
|
872
|
+
function stringToNumber(value) {
|
|
873
|
+
return parseInt(value, 10);
|
|
874
|
+
}
|
|
875
|
+
function isPositionInBox(style, offsetX, offsetY) {
|
|
876
|
+
var left = stringToNumber(style.left);
|
|
877
|
+
var top = stringToNumber(style.top);
|
|
878
|
+
var width = stringToNumber(style.width) +
|
|
879
|
+
stringToNumber(style.paddingLeft) +
|
|
880
|
+
stringToNumber(style.paddingRight);
|
|
881
|
+
var height = stringToNumber(style.height) +
|
|
882
|
+
stringToNumber(style.paddingTop) +
|
|
883
|
+
stringToNumber(style.paddingBottom);
|
|
884
|
+
return offsetX >= left && offsetX <= left + width && offsetY >= top && offsetY <= top + height;
|
|
885
|
+
}
|
|
886
|
+
function removeNode(node) {
|
|
887
|
+
if (node.parentNode) {
|
|
888
|
+
node.parentNode.removeChild(node);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
var CLS_PREFIX = 'toastui-editor-';
|
|
892
|
+
function cls() {
|
|
893
|
+
var names = [];
|
|
894
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
895
|
+
names[_i] = arguments[_i];
|
|
896
|
+
}
|
|
897
|
+
return names.map(function (className) { return "" + CLS_PREFIX + className; }).join(' ');
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/domUtil/css.js
|
|
901
|
+
var css = __webpack_require__(522);
|
|
902
|
+
var css_default = /*#__PURE__*/__webpack_require__.n(css);
|
|
903
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/domUtil/removeClass.js
|
|
904
|
+
var removeClass = __webpack_require__(462);
|
|
905
|
+
var removeClass_default = /*#__PURE__*/__webpack_require__.n(removeClass);
|
|
906
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/domUtil/hasClass.js
|
|
907
|
+
var hasClass = __webpack_require__(714);
|
|
908
|
+
var hasClass_default = /*#__PURE__*/__webpack_require__.n(hasClass);
|
|
909
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/collection/toArray.js
|
|
910
|
+
var toArray = __webpack_require__(990);
|
|
911
|
+
var toArray_default = /*#__PURE__*/__webpack_require__.n(toArray);
|
|
912
|
+
// EXTERNAL MODULE: ../../node_modules/tui-code-snippet/array/inArray.js
|
|
913
|
+
var inArray = __webpack_require__(928);
|
|
914
|
+
var inArray_default = /*#__PURE__*/__webpack_require__.n(inArray);
|
|
915
|
+
;// CONCATENATED MODULE: ./src/nodeViews/languageSelectBox.ts
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
var WRAPPER_CLASS_NAME = 'code-block-language';
|
|
924
|
+
var INPUT_CLASS_NANE = 'code-block-language-input';
|
|
925
|
+
var LIST_CLASS_NAME = 'code-block-language-list';
|
|
926
|
+
var LANG_ATTR = 'data-language';
|
|
927
|
+
var CODE_BLOCK_PADDING = 10;
|
|
928
|
+
function getButtonsHTML(languages) {
|
|
929
|
+
return languages
|
|
930
|
+
.map(function (language) { return "<button type=\"button\" data-language=\"" + language + "\">" + language + "</button>"; })
|
|
931
|
+
.join('');
|
|
932
|
+
}
|
|
933
|
+
var LanguageSelectBox = /** @class */ (function () {
|
|
934
|
+
function LanguageSelectBox(rootEl, eventEmitter, languages) {
|
|
935
|
+
var _this = this;
|
|
936
|
+
this.buttons = [];
|
|
937
|
+
this.prevStoredLanguage = '';
|
|
938
|
+
this.onSelectToggleButton = function (ev) {
|
|
939
|
+
var target = ev.target;
|
|
940
|
+
var style = getComputedStyle(target, ':after');
|
|
941
|
+
var offsetX = ev.offsetX, offsetY = ev.offsetY;
|
|
942
|
+
if (isPositionInBox(style, offsetX, offsetY)) {
|
|
943
|
+
ev.preventDefault();
|
|
944
|
+
_this.toggleFocus();
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
this.onSelectLanguageButtons = function (ev) {
|
|
948
|
+
var target = ev.target;
|
|
949
|
+
var language = target.getAttribute(LANG_ATTR);
|
|
950
|
+
if (language) {
|
|
951
|
+
_this.selectLanguage(language);
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
this.handleKeydown = function (ev) {
|
|
955
|
+
var key = ev.key;
|
|
956
|
+
if (key === 'ArrowUp') {
|
|
957
|
+
_this.selectPrevLanguage();
|
|
958
|
+
ev.preventDefault();
|
|
959
|
+
}
|
|
960
|
+
else if (key === 'ArrowDown') {
|
|
961
|
+
_this.selectNextLanguage();
|
|
962
|
+
ev.preventDefault();
|
|
963
|
+
}
|
|
964
|
+
else if (key === 'Enter' || key === 'Tab') {
|
|
965
|
+
_this.storeInputLanguage();
|
|
966
|
+
ev.preventDefault();
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
_this.hideList();
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
this.showLangugaeSelectBox = function (_a, language) {
|
|
973
|
+
var top = _a.top, right = _a.right;
|
|
974
|
+
if (language) {
|
|
975
|
+
_this.setLanguage(language);
|
|
976
|
+
}
|
|
977
|
+
_this.show();
|
|
978
|
+
var width = _this.input.parentElement.getBoundingClientRect().width;
|
|
979
|
+
css_default()(_this.wrapper, {
|
|
980
|
+
top: top + CODE_BLOCK_PADDING + "px",
|
|
981
|
+
left: right - width - CODE_BLOCK_PADDING + "px",
|
|
982
|
+
});
|
|
983
|
+
_this.toggleFocus();
|
|
984
|
+
};
|
|
985
|
+
this.rootEl = rootEl;
|
|
986
|
+
this.eventEmitter = eventEmitter;
|
|
987
|
+
this.languages = languages;
|
|
988
|
+
this.createElement();
|
|
989
|
+
this.bindDOMEvent();
|
|
990
|
+
this.bindEvent();
|
|
991
|
+
}
|
|
992
|
+
LanguageSelectBox.prototype.createElement = function () {
|
|
993
|
+
this.wrapper = document.createElement('div');
|
|
994
|
+
addClass_default()(this.wrapper, cls(WRAPPER_CLASS_NAME));
|
|
995
|
+
this.createInputElement();
|
|
996
|
+
this.createLanguageListElement();
|
|
997
|
+
this.rootEl.appendChild(this.wrapper);
|
|
998
|
+
this.hide();
|
|
999
|
+
};
|
|
1000
|
+
LanguageSelectBox.prototype.createInputElement = function () {
|
|
1001
|
+
var wrapper = document.createElement('span');
|
|
1002
|
+
addClass_default()(wrapper, cls(INPUT_CLASS_NANE));
|
|
1003
|
+
var input = document.createElement('input');
|
|
1004
|
+
input.type = 'text';
|
|
1005
|
+
input.setAttribute('maxlength', '20');
|
|
1006
|
+
this.input = input;
|
|
1007
|
+
wrapper.appendChild(this.input);
|
|
1008
|
+
this.wrapper.appendChild(wrapper);
|
|
1009
|
+
};
|
|
1010
|
+
LanguageSelectBox.prototype.createLanguageListElement = function () {
|
|
1011
|
+
this.list = document.createElement('div');
|
|
1012
|
+
addClass_default()(this.list, cls(LIST_CLASS_NAME));
|
|
1013
|
+
var buttonsContainer = document.createElement('div');
|
|
1014
|
+
addClass_default()(buttonsContainer, 'buttons');
|
|
1015
|
+
buttonsContainer.innerHTML = getButtonsHTML(this.languages);
|
|
1016
|
+
this.buttons = toArray_default()(buttonsContainer.children);
|
|
1017
|
+
this.list.appendChild(buttonsContainer);
|
|
1018
|
+
this.wrapper.appendChild(this.list);
|
|
1019
|
+
this.activateButtonByIndex(0);
|
|
1020
|
+
this.hideList();
|
|
1021
|
+
};
|
|
1022
|
+
LanguageSelectBox.prototype.bindDOMEvent = function () {
|
|
1023
|
+
var _this = this;
|
|
1024
|
+
this.wrapper.addEventListener('mousedown', this.onSelectToggleButton);
|
|
1025
|
+
this.input.addEventListener('keydown', this.handleKeydown);
|
|
1026
|
+
this.input.addEventListener('focus', function () { return _this.activateSelectBox(); });
|
|
1027
|
+
this.input.addEventListener('blur', function () { return _this.inactivateSelectBox(); });
|
|
1028
|
+
this.list.addEventListener('mousedown', this.onSelectLanguageButtons);
|
|
1029
|
+
};
|
|
1030
|
+
LanguageSelectBox.prototype.bindEvent = function () {
|
|
1031
|
+
this.eventEmitter.listen('showCodeBlockLanguages', this.showLangugaeSelectBox);
|
|
1032
|
+
};
|
|
1033
|
+
LanguageSelectBox.prototype.activateSelectBox = function () {
|
|
1034
|
+
addClass_default()(this.wrapper, 'active');
|
|
1035
|
+
css_default()(this.list, { display: 'block' });
|
|
1036
|
+
};
|
|
1037
|
+
LanguageSelectBox.prototype.inactivateSelectBox = function () {
|
|
1038
|
+
this.input.value = this.prevStoredLanguage;
|
|
1039
|
+
removeClass_default()(this.wrapper, 'active');
|
|
1040
|
+
this.hideList();
|
|
1041
|
+
};
|
|
1042
|
+
LanguageSelectBox.prototype.toggleFocus = function () {
|
|
1043
|
+
if (hasClass_default()(this.wrapper, 'active')) {
|
|
1044
|
+
this.input.blur();
|
|
1045
|
+
}
|
|
1046
|
+
else {
|
|
1047
|
+
this.input.focus();
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
LanguageSelectBox.prototype.storeInputLanguage = function () {
|
|
1051
|
+
var selectedLanguage = this.input.value;
|
|
1052
|
+
this.setLanguage(selectedLanguage);
|
|
1053
|
+
this.hideList();
|
|
1054
|
+
this.eventEmitter.emit('selectLanguage', selectedLanguage);
|
|
1055
|
+
};
|
|
1056
|
+
LanguageSelectBox.prototype.activateButtonByIndex = function (index) {
|
|
1057
|
+
if (this.currentButton) {
|
|
1058
|
+
removeClass_default()(this.currentButton, 'active');
|
|
1059
|
+
}
|
|
1060
|
+
if (this.buttons.length) {
|
|
1061
|
+
this.currentButton = this.buttons[index];
|
|
1062
|
+
this.input.value = this.currentButton.getAttribute(LANG_ATTR);
|
|
1063
|
+
addClass_default()(this.currentButton, 'active');
|
|
1064
|
+
this.currentButton.scrollIntoView();
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
LanguageSelectBox.prototype.selectLanguage = function (selectedLanguage) {
|
|
1068
|
+
this.input.value = selectedLanguage;
|
|
1069
|
+
this.storeInputLanguage();
|
|
1070
|
+
};
|
|
1071
|
+
LanguageSelectBox.prototype.selectPrevLanguage = function () {
|
|
1072
|
+
var index = inArray_default()(this.currentButton, this.buttons) - 1;
|
|
1073
|
+
if (index < 0) {
|
|
1074
|
+
index = this.buttons.length - 1;
|
|
1075
|
+
}
|
|
1076
|
+
this.activateButtonByIndex(index);
|
|
1077
|
+
};
|
|
1078
|
+
LanguageSelectBox.prototype.selectNextLanguage = function () {
|
|
1079
|
+
var index = inArray_default()(this.currentButton, this.buttons) + 1;
|
|
1080
|
+
if (index >= this.buttons.length) {
|
|
1081
|
+
index = 0;
|
|
1082
|
+
}
|
|
1083
|
+
this.activateButtonByIndex(index);
|
|
1084
|
+
};
|
|
1085
|
+
LanguageSelectBox.prototype.hideList = function () {
|
|
1086
|
+
css_default()(this.list, { display: 'none' });
|
|
1087
|
+
};
|
|
1088
|
+
LanguageSelectBox.prototype.show = function () {
|
|
1089
|
+
css_default()(this.wrapper, { display: 'inline-block' });
|
|
1090
|
+
};
|
|
1091
|
+
LanguageSelectBox.prototype.hide = function () {
|
|
1092
|
+
css_default()(this.wrapper, { display: 'none' });
|
|
1093
|
+
};
|
|
1094
|
+
LanguageSelectBox.prototype.setLanguage = function (language) {
|
|
1095
|
+
this.prevStoredLanguage = language;
|
|
1096
|
+
this.input.value = language;
|
|
1097
|
+
var item = this.buttons.filter(function (button) { return button.getAttribute(LANG_ATTR) === language; });
|
|
1098
|
+
if (item.length) {
|
|
1099
|
+
var index = inArray_default()(item[0], this.buttons);
|
|
1100
|
+
this.activateButtonByIndex(index);
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
LanguageSelectBox.prototype.destroy = function () {
|
|
1104
|
+
removeNode(this.wrapper);
|
|
1105
|
+
this.eventEmitter.removeEventHandler('showCodeBlockLanguages', this.showLangugaeSelectBox);
|
|
1106
|
+
};
|
|
1107
|
+
return LanguageSelectBox;
|
|
1108
|
+
}());
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
;// CONCATENATED MODULE: ./src/nodeViews/codeSyntaxHighlightView.ts
|
|
1112
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
1113
|
+
__assign = Object.assign || function(t) {
|
|
1114
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1115
|
+
s = arguments[i];
|
|
1116
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
1117
|
+
t[p] = s[p];
|
|
1118
|
+
}
|
|
1119
|
+
return t;
|
|
1120
|
+
};
|
|
1121
|
+
return __assign.apply(this, arguments);
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
var codeSyntaxHighlightView_WRAPPER_CLASS_NAME = 'ww-code-block-highlighting';
|
|
1128
|
+
function getCustomAttrs(attrs) {
|
|
1129
|
+
var htmlAttrs = attrs.htmlAttrs, classNames = attrs.classNames;
|
|
1130
|
+
return __assign(__assign({}, htmlAttrs), { class: classNames ? classNames.join(' ') : null });
|
|
1131
|
+
}
|
|
1132
|
+
var CodeSyntaxHighlightView = /** @class */ (function () {
|
|
1133
|
+
// eslint-disable-next-line max-params
|
|
1134
|
+
function CodeSyntaxHighlightView(node, view, getPos, eventEmitter, languages) {
|
|
1135
|
+
var _this = this;
|
|
1136
|
+
this.node = node;
|
|
1137
|
+
this.view = view;
|
|
1138
|
+
this.getPos = getPos;
|
|
1139
|
+
this.eventEmitter = eventEmitter;
|
|
1140
|
+
this.languages = languages;
|
|
1141
|
+
this.contentDOM = null;
|
|
1142
|
+
this.languageSelectBox = null;
|
|
1143
|
+
this.onSelectLanguage = function (language) {
|
|
1144
|
+
if (_this.languageEditing) {
|
|
1145
|
+
_this.changeLanguage(language);
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
this.onClickEditingButton = function (ev) {
|
|
1149
|
+
var target = ev.target;
|
|
1150
|
+
var style = getComputedStyle(target, ':after');
|
|
1151
|
+
// judge to click pseudo element with background image for IE11
|
|
1152
|
+
if (style.backgroundImage !== 'none' && isFunction_default()(_this.getPos)) {
|
|
1153
|
+
var pos = _this.view.coordsAtPos(_this.getPos());
|
|
1154
|
+
_this.openLanguageSelectBox(pos);
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
this.finishLanguageEditing = function () {
|
|
1158
|
+
if (_this.languageEditing) {
|
|
1159
|
+
_this.reset();
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
this.node = node;
|
|
1163
|
+
this.view = view;
|
|
1164
|
+
this.getPos = getPos;
|
|
1165
|
+
this.eventEmitter = eventEmitter;
|
|
1166
|
+
this.languageEditing = false;
|
|
1167
|
+
this.languages = languages;
|
|
1168
|
+
this.createElement();
|
|
1169
|
+
this.bindDOMEvent();
|
|
1170
|
+
this.bindEvent();
|
|
1171
|
+
}
|
|
1172
|
+
CodeSyntaxHighlightView.prototype.createElement = function () {
|
|
1173
|
+
var language = this.node.attrs.language;
|
|
1174
|
+
var wrapper = document.createElement('div');
|
|
1175
|
+
wrapper.setAttribute('data-language', language || 'text');
|
|
1176
|
+
addClass_default()(wrapper, cls(codeSyntaxHighlightView_WRAPPER_CLASS_NAME));
|
|
1177
|
+
var pre = this.createCodeBlockElement();
|
|
1178
|
+
var code = pre.firstChild;
|
|
1179
|
+
if (language) {
|
|
1180
|
+
addClass_default()(pre, "language-" + language);
|
|
1181
|
+
addClass_default()(code, "language-" + language);
|
|
1182
|
+
}
|
|
1183
|
+
wrapper.appendChild(pre);
|
|
1184
|
+
this.dom = wrapper;
|
|
1185
|
+
this.contentDOM = code;
|
|
1186
|
+
};
|
|
1187
|
+
CodeSyntaxHighlightView.prototype.createCodeBlockElement = function () {
|
|
1188
|
+
var pre = document.createElement('pre');
|
|
1189
|
+
var code = document.createElement('code');
|
|
1190
|
+
var language = this.node.attrs.language;
|
|
1191
|
+
var attrs = getCustomAttrs(this.node.attrs);
|
|
1192
|
+
if (language) {
|
|
1193
|
+
code.setAttribute('data-language', language);
|
|
1194
|
+
}
|
|
1195
|
+
Object.keys(attrs).forEach(function (attrName) {
|
|
1196
|
+
if (attrs[attrName]) {
|
|
1197
|
+
pre.setAttribute(attrName, attrs[attrName]);
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
pre.appendChild(code);
|
|
1201
|
+
return pre;
|
|
1202
|
+
};
|
|
1203
|
+
CodeSyntaxHighlightView.prototype.bindDOMEvent = function () {
|
|
1204
|
+
if (this.dom) {
|
|
1205
|
+
this.dom.addEventListener('click', this.onClickEditingButton);
|
|
1206
|
+
this.view.dom.addEventListener('mousedown', this.finishLanguageEditing);
|
|
1207
|
+
window.addEventListener('resize', this.finishLanguageEditing);
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
CodeSyntaxHighlightView.prototype.bindEvent = function () {
|
|
1211
|
+
this.eventEmitter.listen('selectLanguage', this.onSelectLanguage);
|
|
1212
|
+
this.eventEmitter.listen('scroll', this.finishLanguageEditing);
|
|
1213
|
+
this.eventEmitter.listen('finishLanguageEditing', this.finishLanguageEditing);
|
|
1214
|
+
};
|
|
1215
|
+
CodeSyntaxHighlightView.prototype.openLanguageSelectBox = function (pos) {
|
|
1216
|
+
this.languageSelectBox = new LanguageSelectBox(this.view.dom.parentElement, this.eventEmitter, this.languages);
|
|
1217
|
+
this.eventEmitter.emit('showCodeBlockLanguages', pos, this.node.attrs.language);
|
|
1218
|
+
this.languageEditing = true;
|
|
1219
|
+
};
|
|
1220
|
+
CodeSyntaxHighlightView.prototype.changeLanguage = function (language) {
|
|
1221
|
+
if (isFunction_default()(this.getPos)) {
|
|
1222
|
+
this.reset();
|
|
1223
|
+
var pos = this.getPos();
|
|
1224
|
+
var tr = this.view.state.tr;
|
|
1225
|
+
tr.setNodeMarkup(pos, null, { language: language });
|
|
1226
|
+
this.view.dispatch(tr);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
CodeSyntaxHighlightView.prototype.reset = function () {
|
|
1230
|
+
if (this.languageSelectBox) {
|
|
1231
|
+
this.languageSelectBox.destroy();
|
|
1232
|
+
this.languageSelectBox = null;
|
|
1233
|
+
}
|
|
1234
|
+
this.languageEditing = false;
|
|
1235
|
+
};
|
|
1236
|
+
CodeSyntaxHighlightView.prototype.stopEvent = function () {
|
|
1237
|
+
return true;
|
|
1238
|
+
};
|
|
1239
|
+
CodeSyntaxHighlightView.prototype.update = function (node) {
|
|
1240
|
+
if (!node.sameMarkup(this.node)) {
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
this.node = node;
|
|
1244
|
+
return true;
|
|
1245
|
+
};
|
|
1246
|
+
CodeSyntaxHighlightView.prototype.destroy = function () {
|
|
1247
|
+
this.reset();
|
|
1248
|
+
if (this.dom) {
|
|
1249
|
+
this.dom.removeEventListener('click', this.onClickEditingButton);
|
|
1250
|
+
this.view.dom.removeEventListener('mousedown', this.finishLanguageEditing);
|
|
1251
|
+
window.removeEventListener('resize', this.finishLanguageEditing);
|
|
1252
|
+
}
|
|
1253
|
+
this.eventEmitter.removeEventHandler('selectLanguage', this.onSelectLanguage);
|
|
1254
|
+
this.eventEmitter.removeEventHandler('scroll', this.finishLanguageEditing);
|
|
1255
|
+
this.eventEmitter.removeEventHandler('finishLanguageEditing', this.finishLanguageEditing);
|
|
1256
|
+
};
|
|
1257
|
+
return CodeSyntaxHighlightView;
|
|
1258
|
+
}());
|
|
1259
|
+
function createCodeSyntaxHighlightView(languages) {
|
|
1260
|
+
return function (node, view, getPos, emitter) {
|
|
1261
|
+
return new CodeSyntaxHighlightView(node, view, getPos, emitter, languages);
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
;// CONCATENATED MODULE: ./src/plugin.ts
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
function codeSyntaxHighlightPlugin(context, options) {
|
|
1271
|
+
if (options) {
|
|
1272
|
+
var eventEmitter = context.eventEmitter;
|
|
1273
|
+
var prism_1 = options.highlighter;
|
|
1274
|
+
eventEmitter.addEventType('showCodeBlockLanguages');
|
|
1275
|
+
eventEmitter.addEventType('selectLanguage');
|
|
1276
|
+
eventEmitter.addEventType('finishLanguageEditing');
|
|
1277
|
+
var languages_1 = prism_1.languages;
|
|
1278
|
+
var registerdlanguages = Object.keys(languages_1).filter(function (language) { return !isFunction_default()(languages_1[language]); });
|
|
1279
|
+
return {
|
|
1280
|
+
toHTMLRenderers: getHTMLRenderers(prism_1),
|
|
1281
|
+
wysiwygPlugins: [function () { return codeSyntaxHighlighting(context, prism_1); }],
|
|
1282
|
+
wysiwygNodeViews: {
|
|
1283
|
+
codeBlock: createCodeSyntaxHighlightView(registerdlanguages),
|
|
1284
|
+
},
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
return {};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
;// CONCATENATED MODULE: ./src/index.ts
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
// Prevent to highlight all code elements automatically.
|
|
1294
|
+
// @link https://prismjs.com/docs/Prism.html#.manual
|
|
1295
|
+
// eslint-disable-next-line no-undefined
|
|
1296
|
+
if (typeof window !== undefined) {
|
|
1297
|
+
window.Prism = window.Prism || {};
|
|
1298
|
+
window.Prism.manual = true;
|
|
1299
|
+
}
|
|
1300
|
+
/* harmony default export */ var src = (codeSyntaxHighlightPlugin);
|
|
1301
|
+
|
|
1302
|
+
}();
|
|
1303
|
+
module.exports = __webpack_exports__["default"];
|
|
1304
|
+
/******/ })()
|
|
1305
|
+
;
|