forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(aio): move autolink-headings to post-processing (angular#16336)
The autolinking is now done on the `renderedContent` which means it also captures and autolinks headings that were generated outside of markdown. PR Close angular#16336
- Loading branch information
1 parent
de36a9b
commit de25cfc
Showing
9 changed files
with
95 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
aio/tools/transforms/angular-base-package/post-processors/autolink-headings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const slug = require('rehype-slug'); | ||
const link = require('rehype-autolink-headings'); | ||
|
||
/** | ||
* Get remark to inject anchors into headings | ||
*/ | ||
module.exports = [ | ||
slug, | ||
[link, { | ||
properties: { | ||
title: 'Link to this heading', | ||
className: ['header-link'], | ||
'aria-hidden': 'true' | ||
}, | ||
content: { | ||
type: 'element', | ||
tagName: 'i', | ||
properties: {className: ['material-icons']}, | ||
children: [{ type: 'text', value: 'link' }] | ||
} | ||
}] | ||
]; |
30 changes: 30 additions & 0 deletions
30
aio/tools/transforms/angular-base-package/post-processors/autolink-headings.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const processorFactory = require('../../post-process-package/processors/post-process-html'); | ||
const plugin = require('./autolink-headings'); | ||
|
||
describe('autolink-headings postprocessor', () => { | ||
let processor; | ||
|
||
beforeEach(() => { | ||
processor = processorFactory(); | ||
processor.docTypes = ['a']; | ||
processor.plugins = [plugin]; | ||
}); | ||
|
||
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> | ||
` | ||
}]; | ||
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> | ||
`); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters