Skip to content

Commit

Permalink
add script to import commonmark tests into md/html fixtures.
Browse files Browse the repository at this point in the history
Place http://spec.commonmark.org/0.28/spec.json in test/ folder first. Then `cd test` and `node import.js <section_name`, and move the generated fixtures into the new/ folder
  • Loading branch information
Feder1co5oave committed Mar 3, 2018
1 parent 56d1bcf commit ec2e873
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var fs = require('fs');
var marked = require('../');

//var nested = [349, 353, 369, 387, 388, 389, 392, 395, 396, 402, 403, 404, 409, 438, 440, 441, 442, 443, 445];

if (process.argv.length !== 3) {
console.warn(`Usage: node ${__filename} '<test_section>'`);
console.warn('<test_section> must match one in spec.json');
process.exit(1);
}

var name = process.argv[2];

var all = JSON.parse(fs.readFileSync('spec.json', 'utf8'));
var md = `${name}\n===================\n\n`;
var html = marked(md) + '\n';

for (var test of all.filter(t => t.section == name )) {
var heading = `### Example ${test.example}\n`;
md += heading + '\n' + test.markdown + '\n';
html += marked(heading) + '\n' + test.html + '\n';
}

var slug = name.toLowerCase().replace(/\s+/, '_');
fs.writeFileSync(`cm_${slug}.md`, md);
fs.writeFileSync(`cm_${slug}.html`, html);

console.log(`Saved in cm_${slug}.md and cm_${slug}.html`);

0 comments on commit ec2e873

Please sign in to comment.