'use strict'; const common = require('../common'); // The doctool currently uses js-yaml from the tool/node_modules/eslint/ tree. try { require('../../tools/node_modules/eslint/node_modules/js-yaml'); } catch { common.skip('missing js-yaml (eslint not present)'); } const assert = require('assert'); const { readFile } = require('fs'); const fixtures = require('../common/fixtures'); const html = require('../../tools/doc/html.js'); const path = require('path'); module.paths.unshift( path.join(__dirname, '..', '..', 'tools', 'doc', 'node_modules')); const unified = require('unified'); const markdown = require('remark-parse'); const remark2rehype = require('remark-rehype'); const raw = require('rehype-raw'); const htmlStringify = require('rehype-stringify'); async function toHTML({ input, filename, nodeVersion }) { const content = unified() .use(markdown) .use(html.firstHeader) .use(html.preprocessText) .use(html.preprocessElements, { filename }) .use(html.buildToc, { filename, apilinks: {} }) .use(remark2rehype, { allowDangerousHTML: true }) .use(raw) .use(htmlStringify) .processSync(input); return html.toHTML({ input, content, filename, nodeVersion }); } // Test data is a list of objects with two properties. // The file property is the file path. // The html property is some HTML which will be generated by the doctool. // This HTML will be stripped of all whitespace because we don't currently // have an HTML parser. const testData = [ { file: fixtures.path('sample_document.md'), html: '
array
<Array>Describe Foobar
in more detail here.
Describe Foobar II
in more detail here.' +
'fg(1)' +
'
Describe ' +
'Deprecated thingy
in more detail here.' +
'fg(1p)' +
'
Describe Something
in more detail here.