@@ -79,8 +79,8 @@ return /******/ (function(modules) { // webpackBootstrap
79
79
80
80
var Logdown = __webpack_require__ ( 1 ) ( )
81
81
var markdown = __webpack_require__ ( 3 )
82
- var isColorSupported = __webpack_require__ ( 6 )
83
- var globalObject = __webpack_require__ ( 9 ) ( )
82
+ var isColorSupported = __webpack_require__ ( 5 )
83
+ var globalObject = __webpack_require__ ( 8 ) ( )
84
84
85
85
//
86
86
// Static
@@ -346,30 +346,42 @@ module.exports = function toArray (arg) {
346
346
/* 3 */
347
347
/***/ ( function ( module , exports , __webpack_require__ ) {
348
348
349
- var rules = __webpack_require__ ( 4 )
350
- var getNextMatch = __webpack_require__ ( 5 )
349
+ var Markdown = __webpack_require__ ( 4 )
351
350
352
- function parse ( text ) {
353
- var styles = [ ]
354
- var match = getNextMatch ( text , rules )
351
+ var styles = [ ]
355
352
356
- while ( match ) {
357
- styles . push ( match . rule . style )
353
+ function createStyledRenderer ( style ) {
354
+ return function ( input ) {
355
+ styles . push ( style )
358
356
styles . push ( '' ) // Empty string resets style.
359
357
360
- text = text . replace ( match . rule . regexp , match . rule . replacer )
361
- match = getNextMatch ( text , rules )
358
+ return '%c' + input + '%c'
359
+ }
360
+ }
361
+
362
+ var markdown = new Markdown ( {
363
+ renderer : {
364
+ '*' : createStyledRenderer ( 'font-weight:bold;' ) ,
365
+ '_' : createStyledRenderer ( 'font-style:italic;' ) ,
366
+ '`' : createStyledRenderer (
367
+ 'background-color:rgba(255,204,102, 0.1);' +
368
+ 'color:#FFCC66;' +
369
+ 'padding:2px 5px;' +
370
+ 'border-radius:2px;'
371
+ )
362
372
}
373
+ } )
363
374
364
- return {
365
- text : text ,
366
- styles : styles
375
+ function parse ( text ) {
376
+ var result = {
377
+ text : markdown . parse ( text ) ,
378
+ styles : [ ] . concat ( styles )
367
379
}
368
- }
369
380
370
- //
371
- // API
372
- //
381
+ styles . length = 0
382
+
383
+ return result
384
+ }
373
385
374
386
module . exports = {
375
387
parse : parse
@@ -380,79 +392,131 @@ module.exports = {
380
392
/* 4 */
381
393
/***/ ( function ( module , exports ) {
382
394
383
- module . exports = [
384
- {
385
- regexp : / \* ( [ ^ * ] + ) \* / ,
386
- replacer : function ( match , submatch1 ) {
387
- return '%c' + submatch1 + '%c'
388
- } ,
389
- style : 'font-weight:bold;'
390
- } ,
391
- {
392
- regexp : / _ ( [ ^ _ ] + ) _ / ,
393
- replacer : function ( match , submatch1 ) {
394
- return '%c' + submatch1 + '%c'
395
- } ,
396
- style : 'font-style:italic;'
397
- } ,
398
- {
399
- regexp : / ` ( [ ^ ` ] + ) ` / ,
400
- replacer : function ( match , submatch1 ) {
401
- return '%c' + submatch1 + '%c'
402
- } ,
403
- style :
404
- 'background-color:rgba(255,204,102, 0.1);' +
405
- 'color:#FFCC66;' +
406
- 'padding:2px 5px;' +
407
- 'border-radius:2px;'
395
+ var lexemeRe = / ( [ _ * ` \\ ] | [ ^ _ * ` \\ ] + ) / g
396
+ var mdTagRe = / [ _ * ` ] /
397
+
398
+ function Markdown ( options ) {
399
+ this . renderer = options . renderer
400
+ }
401
+
402
+ function isMdTag ( lexeme ) {
403
+ return mdTagRe . test ( lexeme )
404
+ }
405
+
406
+ Markdown . prototype . parse = function ( text ) {
407
+ var lexemes = text . match ( lexemeRe )
408
+ var render = this . renderer
409
+
410
+ var formattedText = ''
411
+ var currentScope
412
+ var scopesStack = [ ]
413
+ var activeScopes = { }
414
+ var buffer
415
+ var lexeme
416
+ var cursor = 0
417
+
418
+ function drainTillLexeme ( lexeme ) {
419
+ var buffer = ''
420
+
421
+ while ( currentScope && currentScope . tag !== lexeme ) {
422
+ buffer = currentScope . tag + currentScope . text + buffer
423
+ activeScopes [ currentScope . tag ] = false
424
+ currentScope = scopesStack . pop ( )
425
+ }
426
+
427
+ return buffer
408
428
}
409
- ]
410
429
430
+ while ( lexeme = lexemes [ cursor ] ) { // eslint-disable-line
431
+ buffer = ''
432
+ cursor ++
433
+
434
+ if ( isMdTag ( lexeme ) ) {
435
+ if ( activeScopes [ lexeme ] ) {
436
+ // we've found matching closing tag
437
+ // if we have some other unclosed tags in-between - treat them as a plain text
438
+ buffer = drainTillLexeme ( lexeme )
439
+
440
+ // now currentScope holds the scope for the tag (`lexeme`) we are trying to close
441
+ buffer = render [ currentScope . tag ] ( currentScope . text + buffer )
442
+ activeScopes [ lexeme ] = false
443
+ currentScope = scopesStack . pop ( )
444
+ } else {
445
+ var initialText = ''
446
+
447
+ if ( lexeme === '`' ) {
448
+ // `code` according to spec has the highest priority
449
+ // and does not allow nesting
450
+ // looking if we can find the closing delimiter
451
+
452
+ // NOTE: we have already incremented cursor, so we do not need to add 1
453
+ var newCursor = lexemes . indexOf ( lexeme , cursor )
454
+
455
+ if ( newCursor !== - 1 ) {
456
+ formattedText += drainTillLexeme ( ) // if we already have activeScopes, treat them as plain text
457
+ initialText = lexemes . slice ( cursor , newCursor ) . join ( '' )
458
+ cursor = newCursor // set cursor to the closing backticks
459
+ }
460
+ }
411
461
412
- /***/ } ) ,
413
- /* 5 */
414
- /***/ ( function ( module , exports ) {
462
+ if ( currentScope ) {
463
+ scopesStack . push ( currentScope )
464
+ }
415
465
416
- module . exports = function getNextMatch ( text , rules ) {
417
- var matches = [ ]
466
+ activeScopes [ lexeme ] = true
467
+ currentScope = {
468
+ tag : lexeme ,
469
+ text : initialText
470
+ }
471
+ }
472
+ } else {
473
+ buffer = lexeme
418
474
419
- rules . forEach ( function ( rule ) {
420
- var match = text . match ( rule . regexp )
475
+ if ( lexeme === '\\' ) { // process escaping
476
+ var nextLexeme = lexemes [ cursor ]
421
477
422
- if ( match ) {
423
- matches . push ( {
424
- rule : rule ,
425
- match : match
426
- } )
478
+ if ( isMdTag ( nextLexeme ) || nextLexeme === '\\' ) {
479
+ // ignore next md tag, because it is escaped
480
+ buffer = nextLexeme
481
+ cursor ++
482
+ }
483
+ }
427
484
}
428
- } )
429
485
430
- if ( matches . length === 0 ) {
431
- return null
486
+ if ( buffer ) {
487
+ if ( currentScope ) {
488
+ currentScope . text += buffer
489
+ } else {
490
+ formattedText += buffer
491
+ }
492
+
493
+ buffer = ''
494
+ }
432
495
}
433
496
434
- matches . sort ( function ( a , b ) {
435
- return a . match . index - b . match . index
436
- } )
497
+ // get the rest of the unclosed tags
498
+ formattedText += drainTillLexeme ( )
437
499
438
- return matches [ 0 ]
500
+ return formattedText
439
501
}
440
502
503
+ module . exports = Markdown
504
+
441
505
442
506
/***/ } ) ,
443
- /* 6 */
507
+ /* 5 */
444
508
/***/ ( function ( module , exports , __webpack_require__ ) {
445
509
446
- var isWebkit = __webpack_require__ ( 7 )
447
- var isFirefox = __webpack_require__ ( 8 )
510
+ var isWebkit = __webpack_require__ ( 6 )
511
+ var isFirefox = __webpack_require__ ( 7 )
448
512
449
513
module . exports = function isColorSupported ( ) {
450
514
return ( isWebkit ( ) || isFirefox ( ) )
451
515
}
452
516
453
517
454
518
/***/ } ) ,
455
- /* 7 */
519
+ /* 6 */
456
520
/***/ ( function ( module , exports ) {
457
521
458
522
// Is webkit? http://stackoverflow.com/a/16459606/376773
@@ -466,7 +530,7 @@ module.exports = function isWebkit () {
466
530
467
531
468
532
/***/ } ) ,
469
- /* 8 */
533
+ /* 7 */
470
534
/***/ ( function ( module , exports ) {
471
535
472
536
module . exports = function isFirefox ( ) {
@@ -479,7 +543,7 @@ module.exports = function isFirefox () {
479
543
480
544
481
545
/***/ } ) ,
482
- /* 9 */
546
+ /* 8 */
483
547
/***/ ( function ( module , exports , __webpack_require__ ) {
484
548
485
549
/* WEBPACK VAR INJECTION */ ( function ( global ) { /* eslint-disable no-new-func */
@@ -499,10 +563,10 @@ function getGlobal (slf, glb) {
499
563
module . exports = getGlobal . bind ( this , self , global )
500
564
module . exports . getGlobal = getGlobal
501
565
502
- /* WEBPACK VAR INJECTION */ } . call ( exports , __webpack_require__ ( 10 ) ) )
566
+ /* WEBPACK VAR INJECTION */ } . call ( exports , __webpack_require__ ( 9 ) ) )
503
567
504
568
/***/ } ) ,
505
- /* 10 */
569
+ /* 9 */
506
570
/***/ ( function ( module , exports ) {
507
571
508
572
var g ;
0 commit comments