Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fed08a8

Browse filesBrowse files
aduh95addaleax
authored andcommitted
tools,doc: allow page titles to contain inline code
Previously the HTML title would be cut to the first text node only. PR-URL: #35003 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
1 parent 8cc7a73 commit fed08a8
Copy full SHA for fed08a8

File tree

Expand file treeCollapse file tree

3 files changed

+27
-23
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-23
lines changed
Open diff view settings
Collapse file

‎test/doctool/test-doctool-html.js‎

Copy file name to clipboardExpand all lines: test/doctool/test-doctool-html.js
+16-18Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ try {
99
}
1010

1111
const assert = require('assert');
12-
const { readFile } = require('fs');
12+
const { readFileSync } = require('fs');
1313
const fixtures = require('../common/fixtures');
1414
const { replaceLinks } = require('../../tools/doc/markdown.js');
1515
const html = require('../../tools/doc/html.js');
@@ -58,11 +58,6 @@ function toHTML({ input, filename, nodeVersion, versions }) {
5858
// This HTML will be stripped of all whitespace because we don't currently
5959
// have an HTML parser.
6060
const testData = [
61-
{
62-
file: fixtures.path('sample_document.md'),
63-
html: '<ol><li>fish</li><li>fish</li></ol>' +
64-
'<ul><li>Redfish</li><li>Bluefish</li></ul>'
65-
},
6661
{
6762
file: fixtures.path('order_of_end_tags_5873.md'),
6863
html: '<h3>ClassMethod: Buffer.from(array) <span> ' +
@@ -126,6 +121,10 @@ const testData = [
126121
'href="#foo_see_also" id="foo_see_also">#</a></span></h2><p>Check' +
127122
'out also<a href="https://nodejs.org/">this guide</a></p>'
128123
},
124+
{
125+
file: fixtures.path('document_with_special_heading.md'),
126+
html: '<title>Sample markdown with special heading |',
127+
}
129128
];
130129

131130
const spaces = /\s/g;
@@ -144,17 +143,16 @@ testData.forEach(({ file, html }) => {
144143
// Normalize expected data by stripping whitespace.
145144
const expected = html.replace(spaces, '');
146145

147-
readFile(file, 'utf8', common.mustCall(async (err, input) => {
148-
assert.ifError(err);
149-
const output = toHTML({ input: input,
150-
filename: 'foo',
151-
nodeVersion: process.version,
152-
versions: versions });
146+
const input = readFileSync(file, 'utf8');
147+
148+
const output = toHTML({ input,
149+
filename: 'foo',
150+
nodeVersion: process.version,
151+
versions });
153152

154-
const actual = output.replace(spaces, '');
155-
// Assert that the input stripped of all whitespace contains the
156-
// expected markup.
157-
assert(actual.includes(expected),
158-
`ACTUAL: ${actual}\nEXPECTED: ${expected}`);
159-
}));
153+
const actual = output.replace(spaces, '');
154+
// Assert that the input stripped of all whitespace contains the
155+
// expected markup.
156+
assert(actual.includes(expected),
157+
`ACTUAL: ${actual}\nEXPECTED: ${expected}`);
160158
});
Collapse file
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sample `markdown` with _special_ **heading**
2+
3+
Sometimes heading contains more than just one text child, the current file is
4+
there to test just that.
Collapse file

‎tools/doc/html.js‎

Copy file name to clipboardExpand all lines: tools/doc/html.js
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ function toHTML({ input, content, filename, nodeVersion, versions }) {
9393
// Set the section name based on the first header. Default to 'Index'.
9494
function firstHeader() {
9595
return (tree, file) => {
96-
file.section = 'Index';
97-
9896
const heading = find(tree, { type: 'heading' });
99-
if (heading) {
100-
const text = find(heading, { type: 'text' });
101-
if (text) file.section = text.value;
97+
98+
if (heading && heading.children.length) {
99+
const recursiveTextContent = (node) =>
100+
node.value || node.children.map(recursiveTextContent).join('');
101+
file.section = recursiveTextContent(heading);
102+
} else {
103+
file.section = 'Index';
102104
}
103105
};
104106
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.