11import { beginRules , inlineRules } from './rules'
22import { isLengthEven , union } from '../utils'
33import { punctuation } from '../config'
4+ // import { validEmoji } from '../emojis'
45
56const CAN_NEST_RULES = [ 'strong' , 'em' , 'link' , 'del' , 'image' , 'a_link' ] // image can not nest but it has children
67
@@ -21,6 +22,20 @@ const getSrcAlt = text => {
2122 return { src, alt }
2223}
2324
25+ const lowerPriority = ( src , offset ) => {
26+ let i
27+ for ( i = 0 ; i < offset ; i ++ ) {
28+ const text = src . substring ( i )
29+ for ( const rule of Object . keys ( validateRules ) ) {
30+ const to = validateRules [ rule ] . exec ( text )
31+ if ( to && to [ 0 ] . length > offset - i ) {
32+ return false
33+ }
34+ }
35+ }
36+ return true
37+ }
38+
2439const validateEmphasize = ( src , offset , marker , pending ) => {
2540 /**
2641 * Intraword emphasis is disallowed for _
@@ -62,17 +77,7 @@ const validateEmphasize = (src, offset, marker, pending) => {
6277 * and one that does not, the former always wins. Thus, for example, *[foo*](bar) is parsed
6378 * as *<a href="bar">foo*</a> rather than as <em>[foo</em>](bar).
6479 */
65- let i
66- for ( i = 0 ; i < offset ; i ++ ) {
67- const text = src . substring ( i )
68- for ( const rule of Object . keys ( validateRules ) ) {
69- const to = validateRules [ rule ] . exec ( text )
70- if ( to && to [ 0 ] . length > offset - i ) {
71- return false
72- }
73- }
74- }
75- return true
80+ return lowerPriority ( src , offset )
7681}
7782
7883const tokenizerFac = ( src , beginRules , inlineRules , pos = 0 , top ) => {
@@ -180,6 +185,7 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
180185 for ( const rule of chunks ) {
181186 const to = inlineRules [ rule ] . exec ( src )
182187 if ( to && isLengthEven ( to [ 3 ] ) ) {
188+ if ( rule === 'emoji' && ! lowerPriority ( src , to [ 0 ] . length ) ) break
183189 inChunk = true
184190 pushPending ( )
185191 const range = {
0 commit comments