diff --git a/aio/tools/transforms/angular-base-package/post-processors/h1-checker.js b/aio/tools/transforms/angular-base-package/post-processors/h1-checker.js index 507332bf48..7b0200e104 100644 --- a/aio/tools/transforms/angular-base-package/post-processors/h1-checker.js +++ b/aio/tools/transforms/angular-base-package/post-processors/h1-checker.js @@ -1,22 +1,28 @@ const visit = require('unist-util-visit'); const is = require('hast-util-is-element'); -const source = require('unist-util-source'); const toString = require('hast-util-to-string'); const filter = require('unist-util-filter'); module.exports = function h1CheckerPostProcessor() { return (ast, file) => { - let h1s = []; + file.headings = { + h1: [], + h2: [], + h3: [], + h4: [], + h5: [], + h6: [], + hgroup: [] + }; visit(ast, node => { - if (is(node, 'h1')) { - h1s.push(node); - file.title = getText(node); + if (is(node, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hgroup'])) { + file.headings[node.tagName].push(getText(node)); } }); - if (h1s.length > 1) { - const h1Src = h1s.map(node => source(node, file)).join(', '); - file.fail(`More than one h1 found [${h1Src}]`); + file.title = file.headings.h1[0]; + if (file.headings.h1.length > 1) { + file.fail(`More than one h1 found in ${file}`); } }; }; diff --git a/aio/tools/transforms/angular-base-package/post-processors/h1-checker.spec.js b/aio/tools/transforms/angular-base-package/post-processors/h1-checker.spec.js index 4f8a2600c5..ff16a4b4ff 100644 --- a/aio/tools/transforms/angular-base-package/post-processors/h1-checker.spec.js +++ b/aio/tools/transforms/angular-base-package/post-processors/h1-checker.spec.js @@ -23,7 +23,7 @@ describe('h1Checker postprocessor', () => {

Heading 1a

` }; - expect(() => processor.$process([doc])).toThrowError(createDocMessage('More than one h1 found [

Heading 1,

Heading 1a

]', doc)); + expect(() => processor.$process([doc])).toThrowError(createDocMessage('More than one h1 found in ' + doc.renderedContent, doc)); }); it('should not complain if there is exactly one h1 in a document', () => {