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=", "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=",
"dev": true "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": { "arr-diff": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz",
@ -308,6 +317,12 @@
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true "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": { "execa": {
"version": "0.7.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz",
@ -472,6 +487,15 @@
"for-in": "1.0.2" "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": { "fs-exists-sync": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz", "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": { "kind-of": {
"version": "3.2.2", "version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
@ -1816,6 +1850,12 @@
"integrity": "sha1-Gsu/tZJDbRC76PeFt8xvgoFQEsM=", "integrity": "sha1-Gsu/tZJDbRC76PeFt8xvgoFQEsM=",
"dev": true "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": { "stream-consume": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/stream-consume/-/stream-consume-0.1.0.tgz", "resolved": "https://registry.npmjs.org/stream-consume/-/stream-consume-0.1.0.tgz",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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