@@ -47,6 +47,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
4747 if ( modeCfg . strikethrough === undefined )
4848 modeCfg . strikethrough = false ;
4949
50+ if ( modeCfg . emoji === undefined )
51+ modeCfg . emoji = false ;
52+
5053 // Allow token types to be overridden by user-provided token types.
5154 if ( modeCfg . tokenTypeOverrides === undefined )
5255 modeCfg . tokenTypeOverrides = { } ;
@@ -69,7 +72,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
6972 linkHref : "string" ,
7073 em : "em" ,
7174 strong : "strong" ,
72- strikethrough : "strikethrough"
75+ strikethrough : "strikethrough" ,
76+ emoji : "emoji"
7377 } ;
7478
7579 for ( var tokenType in tokenTypes ) {
@@ -83,7 +87,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
8387 , taskListRE = / ^ \[ ( x | ) \] (? = \s ) / // Must follow listRE
8488 , atxHeaderRE = modeCfg . allowAtxHeaderWithoutSpace ? / ^ ( # + ) / : / ^ ( # + ) (?: | $ ) /
8589 , setextHeaderRE = / ^ * (?: \= { 1 , } | - { 1 , } ) \s * $ /
86- , textRE = / ^ [ ^ # ! \[ \] * _ \\ < > ` " ' ( ~ ] + /
90+ , textRE = / ^ [ ^ # ! \[ \] * _ \\ < > ` " ' ( ~ : ] + /
8791 , fencedCodeRE = new RegExp ( "^(" + ( modeCfg . fencedCodeBlocks === true ? "~~~+|```+" : modeCfg . fencedCodeBlocks ) +
8892 ")[ \\t]*([\\w+#\-]*)" )
8993 , punctuation = / [ ! \" # $ % & \' ( ) * + , \- \. \/ : ; < = > ? @ \[ \\ \] ^ _ ` { | } ~ — ] /
@@ -299,6 +303,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
299303 if ( state . strong ) { styles . push ( tokenTypes . strong ) ; }
300304 if ( state . em ) { styles . push ( tokenTypes . em ) ; }
301305 if ( state . strikethrough ) { styles . push ( tokenTypes . strikethrough ) ; }
306+ if ( state . emoji ) { styles . push ( tokenTypes . emoji ) ; }
302307 if ( state . linkText ) { styles . push ( tokenTypes . linkText ) ; }
303308 if ( state . code ) { styles . push ( tokenTypes . code ) ; }
304309 if ( state . image ) { styles . push ( tokenTypes . image ) ; }
@@ -556,6 +561,14 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
556561 }
557562 }
558563
564+ if ( modeCfg . emoji && ch === ":" && stream . match ( / ^ [ a - z _ \d + - ] + : / ) ) {
565+ state . emoji = true ;
566+ if ( modeCfg . highlightFormatting ) state . formatting = "emoji" ;
567+ var retType = getType ( state ) ;
568+ state . emoji = false ;
569+ return retType ;
570+ }
571+
559572 if ( ch === ' ' ) {
560573 if ( stream . match ( / + $ / , false ) ) {
561574 state . trailingSpace ++ ;
@@ -698,6 +711,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
698711 trailingSpace : 0 ,
699712 trailingSpaceNewLine : false ,
700713 strikethrough : false ,
714+ emoji : false ,
701715 fencedChars : null
702716 } ;
703717 } ,
@@ -725,6 +739,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
725739 em : s . em ,
726740 strong : s . strong ,
727741 strikethrough : s . strikethrough ,
742+ emoji : s . emoji ,
728743 header : s . header ,
729744 hr : s . hr ,
730745 taskList : s . taskList ,
0 commit comments