diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js
index 30221a7fe18b1a..dd67507020a6d6 100644
--- a/test/doctool/test-doctool-html.js
+++ b/test/doctool/test-doctool-html.js
@@ -9,7 +9,7 @@ try {
}
const assert = require('assert');
-const { readFile } = require('fs');
+const { readFileSync } = require('fs');
const fixtures = require('../common/fixtures');
const { replaceLinks } = require('../../tools/doc/markdown.js');
const html = require('../../tools/doc/html.js');
@@ -58,11 +58,6 @@ function toHTML({ input, filename, nodeVersion, versions }) {
// 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: '
- fish
- fish
' +
- ''
- },
{
file: fixtures.path('order_of_end_tags_5873.md'),
html: 'ClassMethod: Buffer.from(array) ' +
@@ -126,6 +121,10 @@ const testData = [
'href="#foo_see_also" id="foo_see_also">#
Check' +
'out alsothis guide
'
},
+ {
+ file: fixtures.path('document_with_special_heading.md'),
+ html: 'Sample markdown with special heading |',
+ }
];
const spaces = /\s/g;
@@ -144,17 +143,16 @@ testData.forEach(({ file, html }) => {
// Normalize expected data by stripping whitespace.
const expected = html.replace(spaces, '');
- readFile(file, 'utf8', common.mustCall(async (err, input) => {
- assert.ifError(err);
- const output = toHTML({ input: input,
- filename: 'foo',
- nodeVersion: process.version,
- versions: versions });
+ const input = readFileSync(file, 'utf8');
+
+ const output = toHTML({ input,
+ filename: 'foo',
+ nodeVersion: process.version,
+ versions });
- const actual = output.replace(spaces, '');
- // Assert that the input stripped of all whitespace contains the
- // expected markup.
- assert(actual.includes(expected),
- `ACTUAL: ${actual}\nEXPECTED: ${expected}`);
- }));
+ const actual = output.replace(spaces, '');
+ // Assert that the input stripped of all whitespace contains the
+ // expected markup.
+ assert(actual.includes(expected),
+ `ACTUAL: ${actual}\nEXPECTED: ${expected}`);
});
diff --git a/test/fixtures/document_with_special_heading.md b/test/fixtures/document_with_special_heading.md
new file mode 100644
index 00000000000000..817ec936e9396d
--- /dev/null
+++ b/test/fixtures/document_with_special_heading.md
@@ -0,0 +1,4 @@
+# Sample `markdown` with _special_ **heading**
+
+Sometimes heading contains more than just one text child, the current file is
+there to test just that.
diff --git a/tools/doc/html.js b/tools/doc/html.js
index 5efce346b5a605..90c8287a1fca78 100644
--- a/tools/doc/html.js
+++ b/tools/doc/html.js
@@ -93,12 +93,14 @@ function toHTML({ input, content, filename, nodeVersion, versions }) {
// Set the section name based on the first header. Default to 'Index'.
function firstHeader() {
return (tree, file) => {
- file.section = 'Index';
-
const heading = find(tree, { type: 'heading' });
- if (heading) {
- const text = find(heading, { type: 'text' });
- if (text) file.section = text.value;
+
+ if (heading && heading.children.length) {
+ const recursiveTextContent = (node) =>
+ node.value || node.children.map(recursiveTextContent).join('');
+ file.section = recursiveTextContent(heading);
+ } else {
+ file.section = 'Index';
}
};
}