@@ -2,7 +2,7 @@ showdown.subParser('headers', function (text, options, globals) {
22 'use strict' ;
33
44 var prefixHeader = options . prefixHeaderId ,
5- headerLevelStart = ( isNaN ( parseInt ( options . headerLevelStart ) ) ) ? 1 : parseInt ( options . headerLevelStart ) ;
5+ headerLevelStart = ( isNaN ( parseInt ( options . headerLevelStart ) ) ) ? 1 : parseInt ( options . headerLevelStart ) ,
66
77 // Set text-style headers:
88 // Header 1
@@ -11,7 +11,10 @@ showdown.subParser('headers', function (text, options, globals) {
1111 // Header 2
1212 // --------
1313 //
14- text = text . replace ( / ^ ( .+ ) [ \t ] * \n = + [ \t ] * \n + / gm, function ( wholeMatch , m1 ) {
14+ setextRegexH1 = ( options . smoothLivePreview ) ? / ^ ( .+ ) [ \t ] * \n = { 2 , } [ \t ] * \n + / gm : / ^ ( .+ ) [ \t ] * \n = + [ \t ] * \n + / gm,
15+ setextRegexH2 = ( options . smoothLivePreview ) ? / ^ ( .+ ) [ \t ] * \n - { 2 , } [ \t ] * \n + / gm : / ^ ( .+ ) [ \t ] * \n - + [ \t ] * \n + / gm;
16+
17+ text = text . replace ( setextRegexH1 , function ( wholeMatch , m1 ) {
1518
1619 var spanGamut = showdown . subParser ( 'spanGamut' ) ( m1 , options , globals ) ,
1720 hID = ( options . noHeaderId ) ? '' : ' id="' + headerId ( m1 ) + '"' ,
@@ -20,7 +23,7 @@ showdown.subParser('headers', function (text, options, globals) {
2023 return showdown . subParser ( 'hashBlock' ) ( hashBlock , options , globals ) ;
2124 } ) ;
2225
23- text = text . replace ( / ^ ( . + ) [ \t ] * \n - + [ \t ] * \n + / gm , function ( matchFound , m1 ) {
26+ text = text . replace ( setextRegexH2 , function ( matchFound , m1 ) {
2427 var spanGamut = showdown . subParser ( 'spanGamut' ) ( m1 , options , globals ) ,
2528 hID = ( options . noHeaderId ) ? '' : ' id="' + headerId ( m1 ) + '"' ,
2629 hLevel = headerLevelStart + 1 ,
@@ -35,18 +38,6 @@ showdown.subParser('headers', function (text, options, globals) {
3538 // ...
3639 // ###### Header 6
3740 //
38-
39- /*
40- text = text.replace(/
41- ^(\#{1,6}) // $1 = string of #'s
42- [ \t]*
43- (.+?) // $2 = Header text
44- [ \t]*
45- \#* // optional closing #'s (not counted)
46- \n+
47- /gm, function() {...});
48- */
49-
5041 text = text . replace ( / ^ ( # { 1 , 6 } ) [ \t ] * ( .+ ?) [ \t ] * # * \n + / gm, function ( wholeMatch , m1 , m2 ) {
5142 var span = showdown . subParser ( 'spanGamut' ) ( m2 , options , globals ) ,
5243 hID = ( options . noHeaderId ) ? '' : ' id="' + headerId ( m2 ) + '"' ,
0 commit comments