use front-matter for test options

This commit is contained in:
Tony Brix 2018-01-06 01:11:16 -06:00
parent 951f2c3916
commit 52bfc9c4db
21 changed files with 87 additions and 20 deletions

40
package-lock.json generated
View File

@ -39,6 +39,15 @@
"integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=",
"dev": true
},
"argparse": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz",
"integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=",
"dev": true,
"requires": {
"sprintf-js": "1.0.3"
}
},
"arr-diff": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz",
@ -308,6 +317,12 @@
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true
},
"esprima": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz",
"integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==",
"dev": true
},
"execa": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz",
@ -472,6 +487,15 @@
"for-in": "1.0.2"
}
},
"front-matter": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/front-matter/-/front-matter-2.3.0.tgz",
"integrity": "sha1-cgOviWzjV+4E4qpFFp6pHtf2dQQ=",
"dev": true,
"requires": {
"js-yaml": "3.10.0"
}
},
"fs-exists-sync": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz",
@ -1014,6 +1038,16 @@
}
}
},
"js-yaml": {
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz",
"integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==",
"dev": true,
"requires": {
"argparse": "1.0.9",
"esprima": "4.0.0"
}
},
"kind-of": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
@ -1816,6 +1850,12 @@
"integrity": "sha1-Gsu/tZJDbRC76PeFt8xvgoFQEsM=",
"dev": true
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
"stream-consume": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/stream-consume/-/stream-consume-0.1.0.tgz",

View File

@ -25,6 +25,7 @@
"devDependencies": {
"markdown": "*",
"showdown": "*",
"front-matter": "^2.3.0",
"gulp": "^3.8.11",
"gulp-uglify": "^1.1.0",
"gulp-concat": "^2.5.2"

View File

@ -12,6 +12,7 @@
var fs = require('fs')
, path = require('path')
, fm = require('front-matter')
, marked = require('../');
/**
@ -23,6 +24,7 @@ function load() {
, files = {}
, list
, file
, content
, i
, l;
@ -42,8 +44,12 @@ function load() {
for (; i < l; i++) {
file = path.join(dir, list[i]);
content = fm(fs.readFileSync(file, 'utf8'));
files[path.basename(file)] = {
text: fs.readFileSync(file, 'utf8'),
options: content.attributes,
text: content.body,
html: fs.readFileSync(file.replace(/[^.]+$/, 'html'), 'utf8')
};
}
@ -72,7 +78,7 @@ function runTests(engine, options) {
, len = keys.length
, filename
, file
, flags
, opts
, text
, html
, j
@ -86,30 +92,22 @@ main:
for (; i < len; i++) {
filename = keys[i];
file = files[filename];
opts = Object.keys(file.options);
if (marked._original) {
marked.defaults = marked._original;
delete marked._original;
}
flags = filename.split('.').slice(1, -1);
if (flags.length) {
if (opts.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('=') !== -1) {
val = decodeURIComponent(key.substring(key.indexOf('=') + 1));
key = key.substring(0, key.indexOf('='));
} else if (key.indexOf('no') === 0) {
key = key.substring(2);
val = false;
}
opts.forEach(function(key) {
if (marked.defaults.hasOwnProperty(key)) {
marked.defaults[key] = val;
marked.defaults[key] = file.options[key];
}
});
}
@ -335,12 +333,12 @@ function fix() {
// cp -r original tests
fs.readdirSync(path.resolve(__dirname, 'original')).forEach(function(file) {
var nfile = file;
if (file.indexOf('hard_wrapped_paragraphs_with_list_like_lines.') === 0) {
nfile = file.replace(/([^.]+)$/, 'nogfm.$1');
var text = fs.readFileSync(path.resolve(__dirname, 'original', file));
if (file.indexOf('hard_wrapped_paragraphs_with_list_like_lines.md') === 0) {
text = "---\ngfm: false\n---\n" + text;
}
fs.writeFileSync(path.resolve(__dirname, 'compiled_tests', nfile),
fs.readFileSync(path.resolve(__dirname, 'original', file)));
fs.writeFileSync(path.resolve(__dirname, 'compiled_tests', file), text);
});
// node fix.js

View File

@ -1,3 +1,6 @@
---
breaks: true
---
Look at the
pretty line
breaks.

View File

@ -1,3 +1,6 @@
---
gfm: true
---
#header
# header1

View File

@ -1,3 +1,6 @@
---
sanitize: true
---
[URL](javascript:alert)
[URL](vbscript:alert)

View File

@ -1,3 +1,7 @@
---
sanatize: true
mangle: false
---
<<svg/onload="alert(1)"//@x>
<bar"onclick="alert('XSS')"@foo>

View File

@ -1,3 +1,6 @@
---
gfm: false
---
#header
# header1

View File

@ -1,3 +1,6 @@
---
baseUrl: "http://example.com/base/"
---
# Absolutization of RFC 3986 URIs
## Absolute URI

View File

@ -1,3 +1,6 @@
---
smartypants: true
---
Hello world 'how' "are" you -- today...
"It's a more 'challenging' smartypants test..."

View File

@ -1,3 +1,6 @@
---
gfm: true
---
hello world
text after spaces
text after spaces

View File

@ -1,2 +1,5 @@
---
sanitize: true
---
lower[click me](javascript&#x3a;...)lower
upper[click me](javascript&#X3a;...)upper