mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
feat(smoothLivePreview): fix weird effects due to parsing incomplete input
This commit is contained in:
parent
7ee2017c56
commit
62ba3733cd
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -65,6 +65,11 @@ function getDefaultOpts(simple) {
|
||||||
default: false,
|
default: false,
|
||||||
describe: 'Turn on/off GFM tasklist support',
|
describe: 'Turn on/off GFM tasklist support',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
|
},
|
||||||
|
smoothLivePreview: {
|
||||||
|
default: false,
|
||||||
|
describe: 'Prevents weird effects in live previews due to incomplete input',
|
||||||
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (simple === false) {
|
if (simple === false) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ showdown.subParser('headers', function (text, options, globals) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var prefixHeader = options.prefixHeaderId,
|
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:
|
// Set text-style headers:
|
||||||
// Header 1
|
// Header 1
|
||||||
|
@ -11,7 +11,10 @@ showdown.subParser('headers', function (text, options, globals) {
|
||||||
// Header 2
|
// 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),
|
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
|
||||||
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
|
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
|
||||||
|
@ -20,7 +23,7 @@ showdown.subParser('headers', function (text, options, globals) {
|
||||||
return showdown.subParser('hashBlock')(hashBlock, 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),
|
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
|
||||||
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
|
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
|
||||||
hLevel = headerLevelStart + 1,
|
hLevel = headerLevelStart + 1,
|
||||||
|
@ -35,18 +38,6 @@ showdown.subParser('headers', function (text, options, globals) {
|
||||||
// ...
|
// ...
|
||||||
// ###### Header 6
|
// ###### 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) {
|
text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
|
||||||
var span = showdown.subParser('spanGamut')(m2, options, globals),
|
var span = showdown.subParser('spanGamut')(m2, options, globals),
|
||||||
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
|
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user