diff --git a/tools/doc/html.js b/tools/doc/html.js
index c631afe534e103..9089ce7e443232 100644
--- a/tools/doc/html.js
+++ b/tools/doc/html.js
@@ -73,10 +73,8 @@ function processContent(content) {
if (content.includes('
')) {
throw new Error('Cannot increment a level 6 header');
}
- if (/]/.test(content) {
- throw new Error('Cannot parse header tag with attributes');
- }
- content.replace(/(?<=<\/?h)[1-5](?=>)/g, (level) => level + 1);
+ // `++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