tools: update doc generator dependencies

PR-URL: https://github.com/nodejs/node/pull/40042
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Michaël Zasso 2021-09-08 21:49:55 +02:00
parent 6ef1d7c347
commit 2b080cb23f
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
10 changed files with 1626 additions and 1074 deletions

View File

@ -3,17 +3,16 @@ import * as fixtures from '../common/fixtures.mjs';
import assert from 'assert';
import { readFileSync } from 'fs';
import { createRequire } from 'module';
import * as html from '../../tools/doc/html.mjs';
import { replaceLinks } from '../../tools/doc/markdown.mjs';
const require = createRequire(new URL('../../tools/doc/', import.meta.url));
const unified = require('unified');
const markdown = require('remark-parse');
const remark2rehype = require('remark-rehype');
const raw = require('rehype-raw');
const htmlStringify = require('rehype-stringify');
import {
rehypeRaw,
rehypeStringify,
remarkParse,
remarkRehype,
unified,
} from '../../tools/doc/deps.mjs';
// Test links mapper is an object of the following structure:
// {
@ -31,14 +30,14 @@ const testLinksMapper = {
function toHTML({ input, filename, nodeVersion, versions }) {
const content = unified()
.use(replaceLinks, { filename, linksMapper: testLinksMapper })
.use(markdown)
.use(remarkParse)
.use(html.firstHeader)
.use(html.preprocessText, { nodeVersion })
.use(html.preprocessElements, { filename })
.use(html.buildToc, { filename, apilinks: {} })
.use(remark2rehype, { allowDangerousHtml: true })
.use(raw)
.use(htmlStringify)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(rehypeStringify)
.processSync(input);
return html.toHTML({ input, content, filename, nodeVersion, versions });

View File

@ -3,13 +3,12 @@ import * as fixtures from '../common/fixtures.mjs';
import assert from 'assert';
import fs from 'fs';
import { createRequire } from 'module';
import * as json from '../../tools/doc/json.mjs';
const require = createRequire(new URL('../../tools/doc/', import.meta.url));
const unified = require('unified');
const markdown = require('remark-parse');
import {
remarkParse,
unified,
} from '../../tools/doc/deps.mjs';
function toJSON(input, filename, cb) {
function nullCompiler() {
@ -17,7 +16,7 @@ function toJSON(input, filename, cb) {
}
unified()
.use(markdown)
.use(remarkParse)
.use(json.jsonAPI, { filename })
.use(nullCompiler)
.process(input, cb);

View File

@ -9,7 +9,7 @@ import { mkdir, writeFile } from 'fs/promises';
import gfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import { toVFile } from 'to-vfile';
import unified from 'unified';
import { unified } from 'unified';
const rootDir = new URL('../../', import.meta.url);
const doc = new URL('./doc/api/addons.md', rootDir);

7
tools/doc/deps.mjs Normal file
View File

@ -0,0 +1,7 @@
// Re-exporting dependencies for tests in test/doctool.
export { default as rehypeRaw } from 'rehype-raw';
export { default as rehypeStringify } from 'rehype-stringify';
export { default as remarkParse } from 'remark-parse';
export { default as remarkRehype } from 'remark-rehype';
export { unified } from 'unified';

View File

@ -28,7 +28,7 @@ import gfm from 'remark-gfm';
import markdown from 'remark-parse';
import remark2rehype from 'remark-rehype';
import frontmatter from 'remark-frontmatter';
import unified from 'unified';
import { unified } from 'unified';
import * as html from './html.mjs';
import * as json from './json.mjs';

View File

@ -28,7 +28,7 @@ import htmlStringify from 'rehype-stringify';
import gfm from 'remark-gfm';
import markdown from 'remark-parse';
import remark2rehype from 'remark-rehype';
import unified from 'unified';
import { unified } from 'unified';
import { visit } from 'unist-util-visit';
import * as common from './common.mjs';
@ -396,7 +396,7 @@ export function buildToc({ filename, apilinks }) {
depth = node.depth;
const realFilename = path.basename(filename, '.md');
const headingText = file.contents.slice(
const headingText = file.value.slice(
node.children[0].position.start.offset,
node.position.end.offset).trim();
const id = getId(headingText, idCounters);

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
import html from 'remark-html';
import unified from 'unified';
import { unified } from 'unified';
import { selectAll } from 'unist-util-select';
import * as common from './common.mjs';
@ -376,7 +376,7 @@ function parseListItem(item, file) {
current.textRaw = item.children.filter((node) => node.type !== 'list')
.map((node) => (
file.contents.slice(node.position.start.offset, node.position.end.offset))
file.value.slice(node.position.start.offset, node.position.end.offset))
)
.join('').replace(/\s+/g, ' ').replace(/<!--.*?-->/sg, '');
let text = current.textRaw;
@ -491,8 +491,8 @@ function newSection(header, file) {
function textJoin(nodes, file) {
return nodes.map((node) => {
if (node.type === 'linkReference') {
return file.contents.slice(node.position.start.offset,
node.position.end.offset);
return file.value.slice(node.position.start.offset,
node.position.end.offset);
} else if (node.type === 'inlineCode') {
return `\`${node.value}\``;
} else if (node.type === 'strong') {

File diff suppressed because it is too large Load Diff

View File

@ -7,19 +7,19 @@
"node": ">=14.8.0"
},
"devDependencies": {
"highlight.js": "11.0.1",
"js-yaml": "4.1.0",
"rehype-raw": "5.1.0",
"rehype-stringify": "8.0.0",
"remark-frontmatter": "^3.0.0",
"remark-gfm": "^1.0.0",
"remark-html": "13.0.2",
"remark-parse": "^9.0.0",
"remark-rehype": "8.1.0",
"to-vfile": "7.1.0",
"unified": "9.2.1",
"unist-util-select": "4.0.0",
"unist-util-visit": "3.1.0"
"highlight.js": "^11.2.0",
"js-yaml": "^4.1.0",
"rehype-raw": "^6.1.0",
"rehype-stringify": "^9.0.2",
"remark-frontmatter": "^4.0.0",
"remark-gfm": "^2.0.0",
"remark-html": "^14.0.1",
"remark-parse": "^10.0.0",
"remark-rehype": "^9.0.0",
"to-vfile": "^7.2.2",
"unified": "^10.1.0",
"unist-util-select": "^4.0.0",
"unist-util-visit": "^4.0.0"
},
"bin": {
"node-doc-generator": "generate.js"

View File

@ -7,7 +7,7 @@ import htmlStringify from 'rehype-stringify';
import gfm from 'remark-gfm';
import markdown from 'remark-parse';
import remark2rehype from 'remark-rehype';
import unified from 'unified';
import { unified } from 'unified';
import { visit } from 'unist-util-visit';
const source = new URL('../../out/doc/api/', import.meta.url);
@ -63,7 +63,7 @@ function createHTML(md) {
.use(processStability)
.processSync(md);
return file.contents.trim();
return file.value.trim();
}
function processStability() {