@@ -17,7 +17,7 @@ var block = {
17
17
fences : noop ,
18
18
hr : / ^ { 0 , 3 } ( (?: - * ) { 3 , } | (?: _ * ) { 3 , } | (?: \* * ) { 3 , } ) (?: \n + | $ ) / ,
19
19
// cap[2] might be ' HEADING # ' and must be trimmed appropriately.
20
- heading : / ^ * ( # { 1 , 6 } ) ( .* ) (?: \n + | $ ) / ,
20
+ heading : / ^ { 0 , 3 } ( # { 1 , 6 } ) (?: [ ^ \S \n ] ( .* ) ) ? (?: \n + | $ ) / ,
21
21
nptable : noop ,
22
22
blockquote : / ^ ( { 0 , 3 } > ? ( p a r a g r a p h | [ ^ \n ] * ) (?: \n | $ ) ) + / ,
23
23
list : / ^ ( * ) ( b u l l ) [ \s \S ] + ?(?: h r | d e f | \n { 2 , } (? ! ) (? ! \1b u l l ) \n * | \s * $ ) / ,
@@ -93,9 +93,7 @@ block.normal = merge({}, block);
93
93
94
94
block . gfm = merge ( { } , block . normal , {
95
95
fences : / ^ * ( ` { 3 , } | ~ { 3 , } ) [ \. ] * ( \S + ) ? * \n ( [ \s \S ] * ?) \n ? * \1 * (?: \n + | $ ) / ,
96
- paragraph : / ^ / ,
97
- // cap[2] might be ' HEADING # ' and must be trimmed appropriately.
98
- heading : / ^ * ( # { 1 , 6 } ) ( .+ ) (?: \n + | $ ) /
96
+ paragraph : / ^ /
99
97
} ) ;
100
98
101
99
block . gfm . paragraph = edit ( block . paragraph )
@@ -118,6 +116,7 @@ block.tables = merge({}, block.gfm, {
118
116
*/
119
117
120
118
block . pedantic = merge ( { } , block . normal , {
119
+ heading : / ^ * ( # { 1 , 6 } ) ( .* ) (?: \n + | $ ) / ,
121
120
html : edit (
122
121
'^ *(?:comment *(?:\\n|\\s*$)'
123
122
+ '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
@@ -238,13 +237,18 @@ Lexer.prototype.token = function(src, top) {
238
237
if ( cap = this . rules . heading . exec ( src ) ) {
239
238
src = src . substring ( cap [ 0 ] . length ) ;
240
239
// cap[2] might be ' HEADING # '
241
- item = cap [ 2 ] . trim ( ) ;
240
+ item = ( cap [ 2 ] || '' ) . trim ( ) ;
242
241
if ( item . slice ( - 1 ) === '#' ) {
243
242
// NB replace(/#+$/) is quadratic on mismatch because it's unanchored,
244
243
// so we protect with if-check to ensure it won't mismatch.
245
- item = item . replace ( / # + $ / , '' ) ;
244
+ if ( this . options . pedantic ) {
245
+ item = item . replace ( / # + $ / , '' ) ;
246
+ } else {
247
+ // CM requires a space before additional #s
248
+ item = item . replace ( / ( \s | ^ ) # + $ / , '' ) ;
249
+ }
246
250
}
247
- item = item . trim ( )
251
+ item = item . trim ( ) ;
248
252
this . tokens . push ( {
249
253
type : 'heading' ,
250
254
depth : cap [ 1 ] . length ,
0 commit comments