From 1241b90a137e409b76ebfb035291c83a73a4940c Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Wed, 25 Apr 2018 23:44:38 +0300 Subject: [PATCH] tools: simplify HTML generation PR-URL: https://github.com/nodejs/node/pull/20307 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat --- Makefile | 2 +- test/doctool/test-doctool-html.js | 2 - tools/doc/generate.js | 5 +- tools/doc/html.js | 85 ++++++++----------------------- 4 files changed, 24 insertions(+), 70 deletions(-) diff --git a/Makefile b/Makefile index 93e1831421de07..fe7595bea70dee 100644 --- a/Makefile +++ b/Makefile @@ -603,7 +603,7 @@ tools/doc/node_modules/js-yaml/package.json: gen-json = tools/doc/generate.js --format=json $< > $@ gen-html = tools/doc/generate.js --node-version=$(FULLVERSION) --format=html \ - --template=doc/template.html --analytics=$(DOCS_ANALYTICS) $< > $@ + --analytics=$(DOCS_ANALYTICS) $< > $@ out/doc/api/%.json: doc/api/%.md $(call available-node, $(gen-json)) diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index 40d7b54f59320a..9c30219c647273 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -10,7 +10,6 @@ try { const assert = require('assert'); const fs = require('fs'); -const path = require('path'); const fixtures = require('../common/fixtures'); const processIncludes = require('../../tools/doc/preprocess.js'); const html = require('../../tools/doc/html.js'); @@ -107,7 +106,6 @@ testData.forEach((item) => { { input: preprocessed, filename: 'foo', - template: path.resolve(__dirname, '../../doc/template.html'), nodeVersion: process.version, analytics: item.analyticsId, }, diff --git a/tools/doc/generate.js b/tools/doc/generate.js index 0da9dba4e6558f..9f217b19c7225f 100644 --- a/tools/doc/generate.js +++ b/tools/doc/generate.js @@ -29,7 +29,6 @@ const fs = require('fs'); const args = process.argv.slice(2); let format = 'json'; -let template = null; let filename = null; let nodeVersion = null; let analytics = null; @@ -39,8 +38,6 @@ args.forEach(function(arg) { filename = arg; } else if (arg.startsWith('--format=')) { format = arg.replace(/^--format=/, ''); - } else if (arg.startsWith('--template=')) { - template = arg.replace(/^--template=/, ''); } else if (arg.startsWith('--node-version=')) { nodeVersion = arg.replace(/^--node-version=/, ''); } else if (arg.startsWith('--analytics=')) { @@ -71,7 +68,7 @@ function next(er, input) { break; case 'html': - require('./html')({ input, filename, template, nodeVersion, analytics }, + require('./html')({ input, filename, nodeVersion, analytics }, (err, html) => { if (err) throw err; console.log(html); diff --git a/tools/doc/html.js b/tools/doc/html.js index ff0230309ee99a..439fc057012ca7 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -25,7 +25,6 @@ const common = require('./common.js'); const fs = require('fs'); const marked = require('marked'); const path = require('path'); -const preprocess = require('./preprocess.js'); const typeParser = require('./type-parser.js'); module.exports = toHTML; @@ -42,76 +41,36 @@ marked.setOptions({ renderer: renderer }); -// TODO(chrisdickinson): never stop vomiting / fix this. -const gtocPath = path.resolve(path.join( - __dirname, - '..', - '..', - 'doc', - 'api', - '_toc.md' -)); -var gtocLoading = null; -var gtocData = null; +const docPath = path.resolve(__dirname, '..', '..', 'doc'); + +const gtocPath = path.join(docPath, 'api', '_toc.md'); +const gtocMD = fs.readFileSync(gtocPath, 'utf8').replace(/^@\/\/.*$/gm, ''); +const gtocHTML = marked(gtocMD).replace( + / `