summaryrefslogtreecommitdiff
path: root/test/doctool/test-doctool-html.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2016-05-24 00:06:09 +0200
committerAnna Henningsen <anna@addaleax.net>2016-05-26 00:49:34 +0200
commitb140bad3912f35bf0c2536fae1e4b46103f2fb4d (patch)
treef43de201d368771ac269528e7739cfbd759f41fa /test/doctool/test-doctool-html.js
parent18fb4f9a912e775dde49e31bf749a9060b2c59e6 (diff)
downloadandroid-node-v8-b140bad3912f35bf0c2536fae1e4b46103f2fb4d.tar.gz
android-node-v8-b140bad3912f35bf0c2536fae1e4b46103f2fb4d.tar.bz2
android-node-v8-b140bad3912f35bf0c2536fae1e4b46103f2fb4d.zip
tools: make sure doctool anchors respect includes
Previously, output files which were created using includes (notably, the single-page all.html) had basically broken internal links all over the place because references like `errors.html#errors_class_error` are being used, yet `id` attributes were generated that looked like `all_class_error`. This PR adds generation of comments from the include preprocessor that indicate from which file the current markdown bits come and lets the HTML output generation take advantage of that so that more appropriate `id` attributes can be generated. PR-URL: https://github.com/nodejs/node/pull/6943 Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com> Reviewed-By: Daniel Wang <wangyang0123@gmail.com>
Diffstat (limited to 'test/doctool/test-doctool-html.js')
-rw-r--r--test/doctool/test-doctool-html.js46
1 files changed, 30 insertions, 16 deletions
diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js
index 8e16403901..91b9e0de6d 100644
--- a/test/doctool/test-doctool-html.js
+++ b/test/doctool/test-doctool-html.js
@@ -5,6 +5,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');
+const processIncludes = require('../../tools/doc/preprocess.js');
const html = require('../../tools/doc/html.js');
// Test data is a list of objects with two properties.
@@ -53,30 +54,43 @@ const testData = [
'<p>Describe <code>Something</code> in more detail here. ' +
'</p>'
},
+ {
+ file: path.join(common.fixturesDir, 'doc_with_includes.md'),
+ html: '<!-- [start-include:doc_inc_1.md] -->' +
+ '<p>Look <a href="doc_inc_2.html#doc_inc_2_foobar">here</a>!</p>' +
+ '<!-- [end-include:doc_inc_1.md] -->' +
+ '<!-- [start-include:doc_inc_2.md] -->' +
+ '<h1>foobar<span><a class="mark" href="#doc_inc_2_foobar" ' +
+ 'id="doc_inc_2_foobar">#</a></span></h1>' +
+ '<p>I exist and am being linked to.</p>' +
+ '<!-- [end-include:doc_inc_2.md] -->'
+ },
];
testData.forEach(function(item) {
// Normalize expected data by stripping whitespace
const expected = item.html.replace(/\s/g, '');
- fs.readFile(item.file, 'utf8', common.mustCall(function(err, input) {
+ fs.readFile(item.file, 'utf8', common.mustCall((err, input) => {
assert.ifError(err);
- html(
- {
- input: input,
- filename: 'foo',
- template: 'doc/template.html',
- nodeVersion: process.version,
- },
+ processIncludes(item.file, input, common.mustCall((err, preprocessed) => {
+ assert.ifError(err);
- common.mustCall(function(err, output) {
- assert.ifError(err);
+ html(
+ {
+ input: preprocessed,
+ filename: 'foo',
+ template: 'doc/template.html',
+ nodeVersion: process.version,
+ },
+ common.mustCall((err, output) => {
+ assert.ifError(err);
- const actual = output.replace(/\s/g, '');
- // Assert that the input stripped of all whitespace contains the
- // expected list
- assert.notEqual(actual.indexOf(expected), -1);
- })
- );
+ const actual = output.replace(/\s/g, '');
+ // Assert that the input stripped of all whitespace contains the
+ // expected list
+ assert.notEqual(actual.indexOf(expected), -1);
+ }));
+ }));
}));
});