@@ -33,7 +33,9 @@ var block = {
33
33
nptable : noop ,
34
34
table : noop ,
35
35
lheading : / ^ ( [ ^ \n ] + ) \n { 0 , 3 } ( = + | - + ) * (?: \n + | $ ) / ,
36
- paragraph : / ^ ( [ ^ \n ] + (?: \n (? ! h r | h e a d i n g | l h e a d i n g | { 0 , 3 } > | < \/ ? (?: t a g ) (?: + | \n | \/ ? > ) | < (?: s c r i p t | p r e | s t y l e | ! - - ) ) [ ^ \n ] + ) * ) / ,
36
+ // regex template, placeholders will be replaced according to different paragraph
37
+ // interruption rules of commonmark and the original markdown spec:
38
+ _paragraph : / ^ ( [ ^ \n ] + (?: \n (? ! h r | h e a d i n g | l h e a d i n g | b l o c k q u o t e | f e n c e s | l i s t | h t m l ) [ ^ \n ] + ) * ) / ,
37
39
text : / ^ [ ^ \n ] + /
38
40
} ;
39
41
@@ -69,10 +71,14 @@ block.html = edit(block.html, 'i')
69
71
. replace ( 'attribute' , / + [ a - z A - Z : _ ] [ \w . : - ] * (?: * = * " [ ^ " \n ] * " | * = * ' [ ^ ' \n ] * ' | * = * [ ^ \s " ' = < > ` ] + ) ? / )
70
72
. getRegex ( ) ;
71
73
72
- block . paragraph = edit ( block . paragraph )
74
+ block . paragraph = edit ( block . _paragraph )
73
75
. replace ( 'hr' , block . hr )
74
- . replace ( 'heading' , block . heading )
75
- . replace ( 'lheading' , block . lheading )
76
+ . replace ( 'heading' , ' {0,3}#{1,6} +' )
77
+ . replace ( '|lheading' , '' ) // setex headings don't interrupt commonmark paragraphs
78
+ . replace ( 'blockquote' , ' {0,3}>' )
79
+ . replace ( 'fences' , ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n' )
80
+ . replace ( 'list' , ' {0,3}(?:[*+-]|1[.)]) ' ) // only lists starting from 1 can interrupt
81
+ . replace ( 'html' , '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)' )
76
82
. replace ( 'tag' , block . _tag ) // pars can be interrupted by type (6) html blocks
77
83
. getRegex ( ) ;
78
84
@@ -91,16 +97,8 @@ block.normal = merge({}, block);
91
97
*/
92
98
93
99
block . gfm = merge ( { } , block . normal , {
94
- paragraph : / ^ / ,
95
- heading : / ^ * ( # { 1 , 6 } ) + ( [ ^ \n ] + ?) * # * * (?: \n + | $ ) /
96
100
} ) ;
97
101
98
- block . gfm . paragraph = edit ( block . paragraph )
99
- . replace ( '(?!' , '(?!'
100
- + block . fences . source . replace ( '\\1' , '\\2' ) + '|'
101
- + block . list . source . replace ( '\\1' , '\\3' ) + '|' )
102
- . getRegex ( ) ;
103
-
104
102
/**
105
103
* GFM + Tables Block Grammar
106
104
*/
@@ -127,7 +125,16 @@ block.pedantic = merge({}, block.normal, {
127
125
. getRegex ( ) ,
128
126
def : / ^ * \[ ( [ ^ \] ] + ) \] : * < ? ( [ ^ \s > ] + ) > ? (?: + ( [ " ( ] [ ^ \n ] + [ " ) ] ) ) ? * (?: \n + | $ ) / ,
129
127
heading : / ^ * ( # { 1 , 6 } ) * ( [ ^ \n ] + ?) * (?: # + * ) ? (?: \n + | $ ) / ,
130
- fences : noop // fences not supported
128
+ fences : noop , // fences not supported
129
+ paragraph : edit ( block . normal . _paragraph )
130
+ . replace ( 'hr' , block . hr )
131
+ . replace ( 'heading' , ' *#{1,6} *[^\n]' )
132
+ . replace ( 'lheading' , block . lheading )
133
+ . replace ( 'blockquote' , ' {0,3}>' )
134
+ . replace ( '|fences' , '' )
135
+ . replace ( '|list' , '' )
136
+ . replace ( '|html' , '' )
137
+ . getRegex ( )
131
138
} ) ;
132
139
133
140
/**
0 commit comments