diff options
author | Sam Ruby <rubys@intertwingly.net> | 2018-07-07 04:46:38 +0300 |
---|---|---|
committer | Vse Mozhet Byt <vsemozhetbyt@gmail.com> | 2018-07-25 21:33:06 +0300 |
commit | f41dd5592ef4df3d200269e536a1693919d73b25 (patch) | |
tree | 3dab1cd7984ccc3ede8d5978695bda5106523edb /test/doctool | |
parent | b675fe360e60e4a21fd683e980066ca09adc1a03 (diff) |
tools: produce JSON documentation using unified/remark/rehype
PR-URL: https://github.com/nodejs/node/pull/21697
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test/doctool')
-rw-r--r-- | test/doctool/test-doctool-html.js | 30 | ||||
-rw-r--r-- | test/doctool/test-doctool-json.js | 44 |
2 files changed, 58 insertions, 16 deletions
diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index c895df087c4..8c05ea6a0b3 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -11,7 +11,34 @@ try { const assert = require('assert'); const { readFile } = require('fs'); const fixtures = require('../common/fixtures'); -const toHTML = require('../../tools/doc/html.js'); +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'); + +function toHTML({ input, filename, nodeVersion, analytics }, cb) { + const content = unified() + .use(markdown) + .use(html.firstHeader) + .use(html.preprocessText) + .use(html.preprocessElements, { filename }) + .use(html.buildToc, { filename }) + .use(remark2rehype, { allowDangerousHTML: true }) + .use(raw) + .use(htmlStringify) + .processSync(input); + + html.toHTML( + { input, content, filename, nodeVersion, analytics }, + cb + ); +} // Test data is a list of objects with two properties. // The file property is the file path. @@ -80,7 +107,6 @@ testData.forEach(({ file, html, analyticsId }) => { readFile(file, 'utf8', common.mustCall((err, input) => { assert.ifError(err); - toHTML( { input: input, diff --git a/test/doctool/test-doctool-json.js b/test/doctool/test-doctool-json.js index e295014071a..cdd3664cf1c 100644 --- a/test/doctool/test-doctool-json.js +++ b/test/doctool/test-doctool-json.js @@ -10,9 +10,27 @@ try { const assert = require('assert'); const fs = require('fs'); +const path = require('path'); const fixtures = require('../common/fixtures'); const json = require('../../tools/doc/json.js'); +module.paths.unshift( + path.join(__dirname, '..', '..', 'tools', 'doc', 'node_modules')); +const unified = require('unified'); +const markdown = require('remark-parse'); + +function toJSON(input, filename, cb) { + function nullCompiler() { + this.Compiler = (tree) => tree; + } + + unified() + .use(markdown) + .use(json.jsonAPI, { filename }) + .use(nullCompiler) + .process(input, cb); +} + // Outputs valid json with the expected fields when given simple markdown // Test data is a list of objects with two properties. // The file property is the file path. @@ -21,6 +39,7 @@ const testData = [ { file: fixtures.path('sample_document.md'), json: { + type: 'module', source: 'foo', modules: [{ textRaw: 'Sample Markdown', @@ -28,8 +47,8 @@ const testData = [ modules: [{ textRaw: 'Seussian Rhymes', name: 'seussian_rhymes', - desc: '<ol>\n<li>fish</li>\n<li><p>fish</p>\n</li>\n<li>' + - '<p>Red fish</p>\n</li>\n<li>Blue fish</li>\n</ol>\n', + desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' + + '<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>', type: 'module', displayName: 'Seussian Rhymes' }], @@ -41,6 +60,7 @@ const testData = [ { file: fixtures.path('order_of_end_tags_5873.md'), json: { + type: 'module', source: 'foo', modules: [{ textRaw: 'Title', @@ -55,15 +75,10 @@ const testData = [ signatures: [ { params: [{ - textRaw: '`array` {Array} ', + textRaw: '`array` {Array}', name: 'array', type: 'Array' }] - }, - { - params: [{ - name: 'array' - }] } ] }], @@ -78,6 +93,7 @@ const testData = [ { file: fixtures.path('doc_with_yaml.md'), json: { + type: 'module', source: 'foo', modules: [ { @@ -92,7 +108,7 @@ const testData = [ changes: [] }, desc: '<p>Describe <code>Foobar</code> in more detail ' + - 'here.</p>\n', + 'here.</p>', type: 'module', displayName: 'Foobar' }, @@ -110,7 +126,7 @@ const testData = [ ] }, desc: '<p>Describe <code>Foobar II</code> in more detail ' + - 'here. fg(1)</p>\n', + 'here. fg(1)</p>', type: 'module', displayName: 'Foobar II' }, @@ -123,7 +139,7 @@ const testData = [ changes: [] }, desc: '<p>Describe <code>Deprecated thingy</code> in more ' + - 'detail here. fg(1p)</p>\n', + 'detail here. fg(1p)</p>', type: 'module', displayName: 'Deprecated thingy' }, @@ -131,7 +147,7 @@ const testData = [ textRaw: 'Something', name: 'something', desc: '<!-- This is not a metadata comment -->\n<p>' + - 'Describe <code>Something</code> in more detail here.</p>\n', + 'Describe <code>Something</code> in more detail here.</p>', type: 'module', displayName: 'Something' } @@ -147,9 +163,9 @@ const testData = [ testData.forEach((item) => { fs.readFile(item.file, 'utf8', common.mustCall((err, input) => { assert.ifError(err); - json(input, 'foo', common.mustCall((err, output) => { + toJSON(input, 'foo', common.mustCall((err, output) => { assert.ifError(err); - assert.deepStrictEqual(output, item.json); + assert.deepStrictEqual(output.json, item.json); })); })); }); |