|
@@ -67,6 +67,11 @@ function getDefaultOpts(simple) {
|
|
|
default: false,
|
|
|
describe: 'Turn on/off GFM tasklist support',
|
|
|
type: 'boolean'
|
|
|
+ },
|
|
|
+ smoothLivePreview: {
|
|
|
+ default: false,
|
|
|
+ describe: 'Prevents weird effects in live previews due to incomplete input',
|
|
|
+ type: 'boolean'
|
|
|
}
|
|
|
};
|
|
|
if (simple === false) {
|
|
@@ -1572,7 +1577,7 @@ showdown.subParser('headers', function (text, options, globals) {
|
|
|
'use strict';
|
|
|
|
|
|
var prefixHeader = options.prefixHeaderId,
|
|
|
- headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart);
|
|
|
+ headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
|
|
|
|
|
|
// Set text-style headers:
|
|
|
// Header 1
|
|
@@ -1581,7 +1586,10 @@ showdown.subParser('headers', function (text, options, globals) {
|
|
|
// Header 2
|
|
|
// --------
|
|
|
//
|
|
|
- text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm, function (wholeMatch, m1) {
|
|
|
+ setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm,
|
|
|
+ setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm;
|
|
|
+
|
|
|
+ text = text.replace(setextRegexH1, function (wholeMatch, m1) {
|
|
|
|
|
|
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
|
|
|
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
|
|
@@ -1590,7 +1598,7 @@ showdown.subParser('headers', function (text, options, globals) {
|
|
|
return showdown.subParser('hashBlock')(hashBlock, options, globals);
|
|
|
});
|
|
|
|
|
|
- text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm, function (matchFound, m1) {
|
|
|
+ text = text.replace(setextRegexH2, function (matchFound, m1) {
|
|
|
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
|
|
|
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
|
|
|
hLevel = headerLevelStart + 1,
|
|
@@ -1605,18 +1613,6 @@ showdown.subParser('headers', function (text, options, globals) {
|
|
|
// ...
|
|
|
// ###### Header 6
|
|
|
//
|
|
|
-
|
|
|
- /*
|
|
|
- text = text.replace(/
|
|
|
- ^(\#{1,6}) // $1 = string of #'s
|
|
|
- [ \t]*
|
|
|
- (.+?) // $2 = Header text
|
|
|
- [ \t]*
|
|
|
- \#* // optional closing #'s (not counted)
|
|
|
- \n+
|
|
|
- /gm, function() {...});
|
|
|
- */
|
|
|
-
|
|
|
text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
|
|
|
var span = showdown.subParser('spanGamut')(m2, options, globals),
|
|
|
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
|