'
},
@@ -111,19 +111,19 @@ const testData = [
},
{
file: fixtures.path('document_with_links.md'),
- html: '
Usage#
node \\[options\\] index.js' +
+ 'An example of a' +
+ '#
An example of a' +
'webserverwritten with Node.js which responds with' +
'\'Hello, World!\'
:
' +
- 'See also#
Check' +
+ '
See also#
Check' +
'out alsothis guide
'
},
{
diff --git a/tools/doc/html.js b/tools/doc/html.js
index b519fd9c5a805b..39062840641e94 100644
--- a/tools/doc/html.js
+++ b/tools/doc/html.js
@@ -66,10 +66,19 @@ const gtocHTML = unified()
const templatePath = path.join(docPath, 'template.html');
const template = fs.readFileSync(templatePath, 'utf8');
-function wrapSections(content) {
+function processContent(content) {
+ content = content.toString();
+ // Increment header tag levels to avoid multiple h1 tags in a doc.
+ // This means we can't already have an .
+ if (content.includes('')) {
+ throw new Error('Cannot increment a level 6 header');
+ }
+ // `++level` to convert the string to a number and increment it.
+ content = content.replace(/(?<=<\/?h)[1-5](?=[^<>]*>)/g, (level) => ++level);
+ // Wrap h3 tags in section tags.
let firstTime = true;
- return content.toString()
- .replace(/ {
+ return content
+ .replace(/ {
if (firstTime) {
firstTime = false;
return '' + heading;
@@ -91,7 +100,7 @@ function toHTML({ input, content, filename, nodeVersion, versions }) {
.replace('__GTOC__', gtocHTML.replace(
`class="nav-${id}"`, `class="nav-${id} active"`))
.replace('__EDIT_ON_GITHUB__', editOnGitHub(filename))
- .replace('__CONTENT__', wrapSections(content));
+ .replace('__CONTENT__', processContent(content));
const docCreated = input.match(
//);