summaryrefslogtreecommitdiffstats
path: root/packages/markdown/marked/test/specs/commonmark/getSpecs.js
blob: f22e00c0c5af16f83d8299b37557f0c3a6d27c11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const fetch = require('node-fetch');
const marked = require('../../../');
const htmlDiffer = require('../../helpers/html-differ.js');
const fs = require('fs');

fetch('https://raw.githubusercontent.com/commonmark/commonmark.js/master/package.json')
  .then(res => res.json())
  .then(pkg => pkg.version.replace(/^(\d+\.\d+).*$/, '$1'))
  .then(version =>
    fetch(`https://spec.commonmark.org/${version}/spec.json`)
      .then(res => res.json())
      .then(specs => {
        specs.forEach(spec => {
          const html = marked(spec.markdown, {headerIds: false});
          if (!htmlDiffer.isEqual(html, spec.html)) {
            spec.shouldFail = true;
          }
        });
        fs.writeFileSync(`commonmark.${version}.json`, JSON.stringify(specs, null, 2) + '\n');
      })
  )
  .catch((err) => {
    console.error(err);
  });