@@ -220,166 +220,6 @@ export function getList(iterable, keys) {
220
220
return Im . List . isList ( val ) ? val : Im . List ( )
221
221
}
222
222
223
- /**
224
- * Adapted from http://github.com/asvd/microlight
225
- * @copyright 2016 asvd <[email protected] >
226
- */
227
- export function highlight ( el ) {
228
- const MAX_LENGTH = 5000
229
- var
230
- _document = document ,
231
- appendChild = "appendChild" ,
232
- test = "test"
233
-
234
- if ( ! el ) return ""
235
- if ( el . textContent . length > MAX_LENGTH ) { return el . textContent }
236
-
237
- var reset = function ( el ) {
238
- var text = el . textContent ,
239
- pos = 0 , // current position
240
- next1 = text [ 0 ] , // next character
241
- chr = 1 , // current character
242
- prev1 , // previous character
243
- prev2 , // the one before the previous
244
- token = // current token content
245
- el . innerHTML = "" , // (and cleaning the node)
246
-
247
- // current token type:
248
- // 0: anything else (whitespaces / newlines)
249
- // 1: operator or brace
250
- // 2: closing braces (after which '/' is division not regex)
251
- // 3: (key)word
252
- // 4: regex
253
- // 5: string starting with "
254
- // 6: string starting with '
255
- // 7: xml comment <!-- -->
256
- // 8: multiline comment /* */
257
- // 9: single-line comment starting with two slashes //
258
- // 10: single-line comment starting with hash #
259
- tokenType = 0 ,
260
-
261
- // kept to determine between regex and division
262
- lastTokenType ,
263
- // flag determining if token is multi-character
264
- multichar ,
265
- node
266
-
267
- // running through characters and highlighting
268
- while ( prev2 = prev1 ,
269
- // escaping if needed (with except for comments)
270
- // previous character will not be therefore
271
- // recognized as a token finalize condition
272
- prev1 = tokenType < 7 && prev1 == "\\" ? 1 : chr
273
- ) {
274
- chr = next1
275
- next1 = text [ ++ pos ]
276
- multichar = token . length > 1
277
-
278
- // checking if current token should be finalized
279
- if ( ! chr || // end of content
280
- // types 9-10 (single-line comments) end with a
281
- // newline
282
- ( tokenType > 8 && chr == "\n" ) ||
283
- [ // finalize conditions for other token types
284
- // 0: whitespaces
285
- / \S / [ test ] ( chr ) , // merged together
286
- // 1: operators
287
- 1 , // consist of a single character
288
- // 2: braces
289
- 1 , // consist of a single character
290
- // 3: (key)word
291
- ! / [ $ \w ] / [ test ] ( chr ) ,
292
- // 4: regex
293
- ( prev1 == "/" || prev1 == "\n" ) && multichar ,
294
- // 5: string with "
295
- prev1 == "\"" && multichar ,
296
- // 6: string with '
297
- prev1 == "'" && multichar ,
298
- // 7: xml comment
299
- text [ pos - 4 ] + prev2 + prev1 == "-->" ,
300
- // 8: multiline comment
301
- prev2 + prev1 == "*/"
302
- ] [ tokenType ]
303
- ) {
304
- // appending the token to the result
305
- if ( token ) {
306
- // remapping token type into style
307
- // (some types are highlighted similarly)
308
- el [ appendChild ] (
309
- node = _document . createElement ( "span" )
310
- ) . setAttribute ( "class" , [
311
- // 0: not formatted
312
- "token-not-formatted" ,
313
- // 1: keywords
314
- "" ,
315
- // 2: punctuation
316
- "" ,
317
- // 3: strings and regexps
318
- "token-string" ,
319
- // 4: comments
320
- ""
321
- ] [
322
- // not formatted
323
- ! tokenType ? 0 :
324
- // punctuation
325
- tokenType < 3 ? 2 :
326
- // comments
327
- tokenType > 6 ? 4 :
328
- // regex and strings
329
- tokenType > 3 ? 3 :
330
- // otherwise tokenType == 3, (key)word
331
- // (1 if regexp matches, 0 otherwise)
332
- + / ^ ( a ( b s t r a c t | l i a s | n d | r g u m e n t s | r r a y | s ( m | s e r t ) ? | u t o ) | b ( a s e | e g i n | o o l ( e a n ) ? | r e a k | y t e ) | c ( a s e | a t c h | h a r | h e c k e d | l a s s | l o n e | o m p l | o n s t | o n t i n u e ) | d e ( b u g g e r | c i m a l | c l a r e | f ( a u l t | e r ) ? | i n i t | l ( e g a t e | e t e ) ? ) | d o | d o u b l e | e ( c h o | l s ? i f | l s e ( i f ) ? | n d | n s u r e | n u m | v e n t | x ( c e p t | e c | p ( l i c i t | o r t ) | t e ( n d s | n s i o n | r n ) ) ) | f ( a l l t h r o u g h | a l s e | i n a l ( l y ) ? | i x e d | l o a t | o r ( e a c h ) ? | r i e n d | r o m | u n c ( t i o n ) ? ) | g l o b a l | g o t o | g u a r d | i ( f | m p ( l e m e n t s | l i c i t | o r t ) | n ( i t | c l u d e ( _ o n c e ) ? | l i n e | o u t | s t a n c e o f | t ( e r f a c e | e r n a l ) ? ) ? | s ) | l ( a m b d a | e t | o c k | o n g ) | m ( i c r o l i g h t | o d u l e | u t a b l e ) | N a N | n ( a m e s p a c e | a t i v e | e x t | e w | i l | o t | u l l ) | o ( b j e c t | p e r a t o r | r | u t | v e r r i d e ) | p ( a c k a g e | a r a m s | r i v a t e | r o t e c t e d | r o t o c o l | u b l i c ) | r ( a i s e | e ( a d o n l y | d o | f | g i s t e r | p e a t | q u i r e ( _ o n c e ) ? | s c u e | s t r i c t | t r y | t u r n ) ) | s ( b y t e | e a l e d | e l f | h o r t | i g n e d | i z e o f | t a t i c | t r i n g | t r u c t | u b s c r i p t | u p e r | y n c h r o n i z e d | w i t c h ) | t ( e m p l a t e | h e n | h i s | h r o w s ? | r a n s i e n t | r u e | r y | y p e ( a l i a s | d e f | i d | n a m e | o f ) ) | u ( n ( c h e c k e d | d e f ( i n e d ) ? | i o n | l e s s | s i g n e d | t i l ) | s e | s i n g ) | v ( a r | i r t u a l | o i d | o l a t i l e ) | w ( c h a r _ t | h e n | h e r e | h i l e | i t h ) | x o r | y i e l d ) $ / [ test ] ( token )
333
- ] )
334
-
335
- node [ appendChild ] ( _document . createTextNode ( token ) )
336
- }
337
-
338
- // saving the previous token type
339
- // (skipping whitespaces and comments)
340
- lastTokenType =
341
- ( tokenType && tokenType < 7 ) ?
342
- tokenType : lastTokenType
343
-
344
- // initializing a new token
345
- token = ""
346
-
347
- // determining the new token type (going up the
348
- // list until matching a token type start
349
- // condition)
350
- tokenType = 11
351
- while ( ! [
352
- 1 , // 0: whitespace
353
- // 1: operator or braces
354
- / [ \/ { } [ ( \- + * = < > : ; | \\ . , ? ! & @ ~ ] / [ test ] ( chr ) , // eslint-disable-line no-useless-escape
355
- / [ \] ) ] / [ test ] ( chr ) , // 2: closing brace
356
- / [ $ \w ] / [ test ] ( chr ) , // 3: (key)word
357
- chr == "/" && // 4: regex
358
- // previous token was an
359
- // opening brace or an
360
- // operator (otherwise
361
- // division, not a regex)
362
- ( lastTokenType < 2 ) &&
363
- // workaround for xml
364
- // closing tags
365
- prev1 != "<" ,
366
- chr == "\"" , // 5: string with "
367
- chr == "'" , // 6: string with '
368
- // 7: xml comment
369
- chr + next1 + text [ pos + 1 ] + text [ pos + 2 ] == "<!--" ,
370
- chr + next1 == "/*" , // 8: multiline comment
371
- chr + next1 == "//" , // 9: single-line comment
372
- chr == "#" // 10: hash-style comment
373
- ] [ -- tokenType ] ) ;
374
- }
375
-
376
- token += chr
377
- }
378
- }
379
-
380
- return reset ( el )
381
- }
382
-
383
223
/**
384
224
* Take an immutable map, and convert to a list.
385
225
* Where the keys are merged with the value objects
0 commit comments