fix(aio): fix window title on Home page (#20440)
Using `display: none` on the `<h1>` causes `innerText` to not work as expected and include the icon ligature (`link`) in the title. This caused the window title on the angular.io Home page to appear as "Angular - link". This commit fixes it by not generating anchors at all for headings with the `no-anchor` class. Fixes #20427 PR Close #20440
This commit is contained in:

committed by
Miško Hevery

parent
c28b52187a
commit
7e38f4fd1f
@ -14,20 +14,37 @@ describe('autolink-headings postprocessor', () => {
|
||||
});
|
||||
|
||||
it('should add anchors to headings', () => {
|
||||
const docs = [ {
|
||||
docType: 'a',
|
||||
renderedContent: `
|
||||
<h1>Heading 1</h2>
|
||||
<h2>Heading with <strong>bold</strong></h2>
|
||||
<h3>Heading with encoded chars &</h3>
|
||||
`
|
||||
}];
|
||||
const originalContent = `
|
||||
<h1>Heading 1</h2>
|
||||
<h2>Heading with <strong>bold</strong></h2>
|
||||
<h3>Heading with encoded chars &</h3>
|
||||
`;
|
||||
const processedContent = `
|
||||
<h1 id="heading-1"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-1"><i class="material-icons">link</i></a>Heading 1</h1>
|
||||
<h2 id="heading-with-bold"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-bold"><i class="material-icons">link</i></a>Heading with <strong>bold</strong></h2>
|
||||
<h3 id="heading-with-encoded-chars-"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-encoded-chars-"><i class="material-icons">link</i></a>Heading with encoded chars &</h3>
|
||||
`;
|
||||
|
||||
const docs = [{docType: 'a', renderedContent: originalContent}];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].renderedContent).toEqual(`
|
||||
<h1 id="heading-1"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-1"><i class="material-icons">link</i></a>Heading 1</h1>
|
||||
<h2 id="heading-with-bold"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-bold"><i class="material-icons">link</i></a>Heading with <strong>bold</strong></h2>
|
||||
<h3 id="heading-with-encoded-chars-"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-encoded-chars-"><i class="material-icons">link</i></a>Heading with encoded chars &</h3>
|
||||
`);
|
||||
expect(docs[0].renderedContent).toBe(processedContent);
|
||||
});
|
||||
|
||||
it('should ignore headings with the `no-anchor` class', () => {
|
||||
const originalContent = `
|
||||
<h1 class="no-anchor">Heading 1</h2>
|
||||
<h2 class="no-anchor">Heading with <strong>bold</strong></h2>
|
||||
<h3 class="no-anchor">Heading with encoded chars &</h3>
|
||||
`;
|
||||
const processedContent = `
|
||||
<h1 class="no-anchor" id="heading-1">Heading 1</h1>
|
||||
<h2 class="no-anchor" id="heading-with-bold">Heading with <strong>bold</strong></h2>
|
||||
<h3 class="no-anchor" id="heading-with-encoded-chars-">Heading with encoded chars &</h3>
|
||||
`;
|
||||
|
||||
const docs = [{docType: 'a', renderedContent: originalContent}];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].renderedContent).toBe(processedContent);
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user