Skip to content

Commit

Permalink
add getSpecs.js for gfm
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Apr 12, 2019
1 parent 6d91c4f commit d78c66e
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 0 deletions.
127 changes: 127 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
],
"devDependencies": {
"@markedjs/html-differ": "^2.0.1",
"cheerio": "^1.0.0-rc.3",
"commonmark": "0.x",
"eslint": "^5.15.1",
"eslint-config-standard": "^12.0.0",
Expand Down
44 changes: 44 additions & 0 deletions test/specs/gfm/getSpecs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const marked = require('../../../');
const htmlDiffer = require('../../helpers/html-differ.js');
const fs = require('fs');

fetch('https://github.github.com/gfm/')
.then(res => res.text())
.then(html => cheerio.load(html))
.then($ => {
const version = $('.version').text().match(/\d+\.\d+/)[0];
if (!version) {
throw new Error('No version found');
}
const specs = [];
$('.extension').each((i, ext) => {
const section = $('.definition', ext).text().trim().replace(/^\d+\.\d+(.*?) \(extension\)[\s\S]*$/, '$1');
$('.example', ext).each((j, exa) => {
const example = $(exa).attr('id').replace(/\D/g, '');
const markdown = $('.language-markdown', exa).text().trim();
const html = $('.language-html', exa).text().trim();
specs.push({
section,
html,
markdown,
example
});
});
});

return [version, specs];
})
.then(([version, specs]) => {
specs.forEach(spec => {
const html = marked(spec.markdown, {gfm: true});
if (!htmlDiffer.isEqual(html, spec.html)) {
spec.shouldFail = true;
}
});
fs.writeFileSync(`gfm.${version}.json`, JSON.stringify(specs, null, 2) + '\n');
})
.catch((err) => {
console.error(err);
});

0 comments on commit d78c66e

Please sign in to comment.