list-like lines = lists in gfm. fixes #120.
This commit is contained in:
parent
81e2062cee
commit
37698ee7e0
@ -75,7 +75,9 @@ block.gfm = merge({}, block.normal, {
|
||||
});
|
||||
|
||||
block.gfm.paragraph = replace(block.paragraph)
|
||||
('(?!', '(?!' + block.gfm.fences.source.replace('\\1', '\\2') + '|')
|
||||
('(?!', '(?!'
|
||||
+ block.gfm.fences.source.replace('\\1', '\\2') + '|'
|
||||
+ block.list.source.replace('\\1', '\\3') + '|')
|
||||
();
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ app.get('/test.js', function(req, res, next) {
|
||||
, files = load();
|
||||
|
||||
test = test.replace('__TESTS__', JSON.stringify(files));
|
||||
test = test.replace('__MAIN__', test.replacePre + '\n\n' + runTests + '');
|
||||
test = test.replace('__MAIN__', runTests + '');
|
||||
|
||||
res.contentType('.js');
|
||||
res.send(test);
|
||||
|
@ -15,22 +15,34 @@ console.log = function(text) {
|
||||
document.body.innerHTML += '<pre>' + escape(text) + '</pre>';
|
||||
};
|
||||
|
||||
Object.keys = Object.keys || function(obj) {
|
||||
var out = []
|
||||
, key;
|
||||
if (!Object.keys) {
|
||||
Object.keys = function(obj) {
|
||||
var out = []
|
||||
, key;
|
||||
|
||||
for (key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
out.push(key);
|
||||
for (key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
out.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
return out;
|
||||
};
|
||||
}
|
||||
|
||||
String.prototype.trim = String.prototype.trim || function() {
|
||||
return this.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
if (!Array.prototype.forEach) {
|
||||
Array.prototype.forEach = function(callback, context) {
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
callback.call(context || null, this[i], i, obj);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.trim) {
|
||||
String.prototype.trim = function() {
|
||||
return this.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
}
|
||||
|
||||
function load() {
|
||||
return files;
|
||||
|
@ -51,37 +51,6 @@ function load() {
|
||||
return files;
|
||||
}
|
||||
|
||||
function stripPre() {
|
||||
var keys = Object.keys(files)
|
||||
, i = 0
|
||||
, key;
|
||||
|
||||
for (; i < keys.length; i++) {
|
||||
key = keys[i];
|
||||
files[key].text = replacePre(files[key].text, true);
|
||||
files[key].html = replacePre(files[key].html, true);
|
||||
}
|
||||
}
|
||||
|
||||
function replacePre(text, remove) {
|
||||
var o = /(?:^|\n)#if +([^\s]+)\n([\s\S]*?)(?:\n#else\n([\s\S]*?))?\n#endif/g;
|
||||
if (remove) {
|
||||
return text.replace(o, '');
|
||||
}
|
||||
return text.replace(o, function(str, option, content, els) {
|
||||
var set = true;
|
||||
option = option.toLowerCase();
|
||||
if (option[0] === '!') {
|
||||
option = option.substring(1);
|
||||
set = false;
|
||||
}
|
||||
if (!!marked.defaults[option] === set) {
|
||||
return '\n' + content;
|
||||
}
|
||||
return '\n' + (els || '');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Runner
|
||||
*/
|
||||
@ -97,12 +66,12 @@ function runTests(engine, options) {
|
||||
, files = options.files || load()
|
||||
, complete = 0
|
||||
, failed = 0
|
||||
, skipped = 0
|
||||
, keys = Object.keys(files)
|
||||
, i = 0
|
||||
, len = keys.length
|
||||
, filename
|
||||
, file
|
||||
, flags
|
||||
, text
|
||||
, html
|
||||
, j
|
||||
@ -117,24 +86,33 @@ main:
|
||||
filename = keys[i];
|
||||
file = files[filename];
|
||||
|
||||
if ((~filename.indexOf('.gfm.') && !marked.defaults.gfm)
|
||||
|| (~filename.indexOf('.tables.') && !marked.defaults.tables)
|
||||
|| (~filename.indexOf('.breaks.') && !marked.defaults.breaks)
|
||||
|| (~filename.indexOf('.pedantic.') && !marked.defaults.pedantic)
|
||||
|| (~filename.indexOf('.sanitize.') && !marked.defaults.sanitize)
|
||||
|| (~filename.indexOf('.smartlists.') && !marked.defaults.smartLists)
|
||||
|| (~filename.indexOf('.smartypants.') && !marked.defaults.smartypants)) {
|
||||
skipped++;
|
||||
console.log('#%d. %s skipped.', i + 1, filename);
|
||||
continue main;
|
||||
if (marked._original) {
|
||||
marked.defaults = marked._original;
|
||||
delete marked._original;
|
||||
}
|
||||
|
||||
text = replacePre(file.text);
|
||||
html = replacePre(file.html);
|
||||
flags = filename.split('.').slice(1, -1);
|
||||
if (flags.length) {
|
||||
marked._original = marked.defaults;
|
||||
marked.defaults = {};
|
||||
Object.keys(marked._original).forEach(function(key) {
|
||||
marked.defaults[key] = marked._original[key];
|
||||
});
|
||||
flags.forEach(function(key) {
|
||||
var val = true;
|
||||
if (key.indexOf('no') === 0) {
|
||||
key = key.substring(2);
|
||||
val = false;
|
||||
}
|
||||
if (marked.defaults.hasOwnProperty(key)) {
|
||||
marked.defaults[key] = val;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
text = engine(text).replace(/\s/g, '');
|
||||
html = html.replace(/\s/g, '');
|
||||
text = engine(file.text).replace(/\s/g, '');
|
||||
html = file.html.replace(/\s/g, '');
|
||||
} catch(e) {
|
||||
console.log('%s failed.', filename);
|
||||
throw e;
|
||||
@ -176,7 +154,6 @@ main:
|
||||
|
||||
console.log('%d/%d tests completed successfully.', complete, len);
|
||||
if (failed) console.log('%d/%d tests failed.', failed, len);
|
||||
if (skipped) console.log('%d/%d tests skipped.', skipped, len);
|
||||
|
||||
return !failed;
|
||||
}
|
||||
@ -206,8 +183,6 @@ function bench(name, func) {
|
||||
files['main.text'].text = files['main.text'].text.replace('* * *\n\n', '');
|
||||
}
|
||||
|
||||
stripPre();
|
||||
|
||||
var start = Date.now()
|
||||
, times = 1000
|
||||
, keys = Object.keys(files)
|
||||
@ -355,7 +330,11 @@ function fix(options) {
|
||||
|
||||
// cp -r original tests
|
||||
fs.readdirSync(path.resolve(__dirname, 'original')).forEach(function(file) {
|
||||
fs.writeFileSync(path.resolve(__dirname, 'tests', file),
|
||||
var nfile = file;
|
||||
if (file.indexOf('hard_wrapped_paragraphs_with_list_like_lines.') === 0) {
|
||||
nfile = file.replace(/\.(text|html)$/, '.nogfm.$1');
|
||||
}
|
||||
fs.writeFileSync(path.resolve(__dirname, 'tests', nfile),
|
||||
fs.readFileSync(path.resolve(__dirname, 'original', file)));
|
||||
});
|
||||
|
||||
@ -547,7 +526,6 @@ if (!module.parent) {
|
||||
} else {
|
||||
exports = main;
|
||||
exports.main = main;
|
||||
exports.replacePre = replacePre;
|
||||
exports.runTests = runTests;
|
||||
exports.runBench = runBench;
|
||||
exports.load = load;
|
||||
|
@ -2,4 +2,5 @@
|
||||
|
||||
<p>“It’s a more ‘challenging’ smartypants test…”</p>
|
||||
|
||||
<p>‘And,’ as a bonus — “one<br>multiline” test!</p>
|
||||
<p>‘And,’ as a bonus — “one
|
||||
multiline” test!</p>
|
||||
|
@ -17,8 +17,8 @@
|
||||
<p>hello world</p>
|
||||
<blockquote><p>how are you</p></blockquote>
|
||||
|
||||
<p>hello world
|
||||
* how are you</p>
|
||||
<p>hello world</p>
|
||||
<ul><li>how are you</li></ul>
|
||||
|
||||
<p>hello world</p>
|
||||
<div>how are you</div>
|
@ -2,4 +2,5 @@
|
||||
|
||||
<p>“It’s a more ‘challenging’ smartypants test…”</p>
|
||||
|
||||
<p>‘And,’ as a bonus — “one<br>multiline” test!</p>
|
||||
<p>‘And,’ as a bonus — “one
|
||||
multiline” test!</p>
|
||||
|
@ -17,8 +17,8 @@
|
||||
<p>hello world</p>
|
||||
<blockquote><p>how are you</p></blockquote>
|
||||
|
||||
<p>hello world
|
||||
* how are you</p>
|
||||
<p>hello world</p>
|
||||
<ul><li>how are you</li></ul>
|
||||
|
||||
<p>hello world</p>
|
||||
<div>how are you</div>
|
Loading…
x
Reference in New Issue
Block a user