diff --git a/aio/package.json b/aio/package.json index 4015a08465d..e07bd2521cb 100644 --- a/aio/package.json +++ b/aio/package.json @@ -83,10 +83,10 @@ "lodash": "^4.17.4", "protractor": "~5.1.0", "rehype": "^4.0.0", + "rehype-autolink-headings": "^2.0.0", + "rehype-slug": "^2.0.0", "remark": "^7.0.0", - "remark-autolink-headings": "^4.0.0", "remark-html": "^6.0.0", - "remark-slug": "^4.2.2", "rho": "https://github.com/petebacondarwin/rho#master", "rimraf": "^2.6.1", "shelljs": "^0.7.7", diff --git a/aio/tools/transforms/angular-api-package/index.js b/aio/tools/transforms/angular-api-package/index.js index b86b541a9ee..9dd26f5653e 100644 --- a/aio/tools/transforms/angular-api-package/index.js +++ b/aio/tools/transforms/angular-api-package/index.js @@ -107,9 +107,10 @@ module.exports = new Package('angular-api', [basePackage, typeScriptPackage]) }); }) - .config(function(convertToJsonProcessor, EXPORT_DOC_TYPES) { + .config(function(convertToJsonProcessor, postProcessHtml, EXPORT_DOC_TYPES) { const DOCS_TO_CONVERT = EXPORT_DOC_TYPES.concat([ 'decorator', 'directive', 'pipe', 'module' ]); convertToJsonProcessor.docTypes = convertToJsonProcessor.docTypes.concat(DOCS_TO_CONVERT); + postProcessHtml.docTypes = convertToJsonProcessor.docTypes.concat(DOCS_TO_CONVERT); }); diff --git a/aio/tools/transforms/angular-base-package/index.js b/aio/tools/transforms/angular-base-package/index.js index 0ee75eb0ee0..126ae0437b8 100644 --- a/aio/tools/transforms/angular-base-package/index.js +++ b/aio/tools/transforms/angular-base-package/index.js @@ -113,6 +113,13 @@ module.exports = new Package('angular-base', [ ]; }) + + .config(function(postProcessHtml) { + postProcessHtml.plugins = [ + require('./post-processors/autolink-headings') + ]; + }) + .config(function(convertToJsonProcessor) { convertToJsonProcessor.docTypes = []; }); diff --git a/aio/tools/transforms/angular-base-package/post-processors/autolink-headings.js b/aio/tools/transforms/angular-base-package/post-processors/autolink-headings.js new file mode 100644 index 00000000000..5b9c353f780 --- /dev/null +++ b/aio/tools/transforms/angular-base-package/post-processors/autolink-headings.js @@ -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' }] + } + }] +]; diff --git a/aio/tools/transforms/angular-base-package/post-processors/autolink-headings.spec.js b/aio/tools/transforms/angular-base-package/post-processors/autolink-headings.spec.js new file mode 100644 index 00000000000..aa40561d8e0 --- /dev/null +++ b/aio/tools/transforms/angular-base-package/post-processors/autolink-headings.spec.js @@ -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: ` +
A paragraph with bold and italic.
\n' + 'some text
\nindented text
\nother text
\n'); }); - - it('should add id slugs and links to headings', () => { - const content = '# heading 1\n\nSome text\n\n## heading 2\n\nMore text'; - const output = renderMarkdown(content); - expect(output).toEqual( - 'Some text
\n' + - 'More text
\n'); - }); }); diff --git a/aio/yarn.lock b/aio/yarn.lock index 02e08830e9d..14130e729db 100644 --- a/aio/yarn.lock +++ b/aio/yarn.lock @@ -2778,7 +2778,7 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" -github-slugger@^1.0.0: +github-slugger@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/github-slugger/-/github-slugger-1.1.1.tgz#5444671f65e5a5a424cfa8ba3255cc1f7baf07ea" dependencies: @@ -3024,6 +3024,10 @@ hast-util-from-parse5@^1.0.0: property-information "^3.1.0" vfile-location "^2.0.0" +hast-util-has-property@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/hast-util-has-property/-/hast-util-has-property-1.0.0.tgz#211f9d7f7640898244a33f5d16f5c5d1880c8e40" + hast-util-is-element@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/hast-util-is-element/-/hast-util-is-element-1.0.0.tgz#3f7216978b2ae14d98749878782675f33be3ce00" @@ -3056,6 +3060,10 @@ hast-util-to-html@^3.0.0: unist-util-is "^2.0.0" xtend "^4.0.1" +hast-util-to-string@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/hast-util-to-string/-/hast-util-to-string-1.0.0.tgz#16c07671f0f2ac7735e455cdae32c7c1b8963f2a" + hast-util-whitespace@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/hast-util-whitespace/-/hast-util-whitespace-1.0.0.tgz#bd096919625d2936e1ff17bc4df7fd727f17ece9" @@ -4327,10 +4335,6 @@ mdast-util-to-hast@^2.1.1: unist-util-visit "^1.1.0" xtend "^4.0.1" -mdast-util-to-string@^1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/mdast-util-to-string/-/mdast-util-to-string-1.0.2.tgz#dc996a24d2b521178d3fac3993680c03a683e1dd" - media-typer@0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" @@ -5651,6 +5655,15 @@ regjsparser@^0.1.4: dependencies: jsesc "~0.5.0" +rehype-autolink-headings@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/rehype-autolink-headings/-/rehype-autolink-headings-2.0.0.tgz#105ae3f44ee78f9cd618f16eb0aea3bc61582f00" + dependencies: + hast-util-has-property "^1.0.0" + hast-util-is-element "^1.0.0" + unist-util-visit "^1.1.0" + xtend "^4.0.1" + rehype-parse@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/rehype-parse/-/rehype-parse-3.1.0.tgz#7f5227a597a3f39fc4b938646161539c444ee728" @@ -5659,6 +5672,16 @@ rehype-parse@^3.0.0: parse5 "^2.1.5" xtend "^4.0.1" +rehype-slug@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/rehype-slug/-/rehype-slug-2.0.0.tgz#b52f6c69faefc61420cb9ea8ba268e48531c61b9" + dependencies: + github-slugger "^1.1.1" + hast-util-has-property "^1.0.0" + hast-util-is-element "^1.0.0" + hast-util-to-string "^1.0.0" + unist-util-visit "^1.1.0" + rehype-stringify@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/rehype-stringify/-/rehype-stringify-3.0.0.tgz#9fef0868213c2dce2f780b76f3d0488c85e819eb" @@ -5678,12 +5701,6 @@ relateurl@0.2.x: version "0.2.7" resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" -remark-autolink-headings@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/remark-autolink-headings/-/remark-autolink-headings-4.0.0.tgz#1edabab6636e8cb26a36bf4c06caaec28355d3fc" - dependencies: - unist-util-visit "^1.0.1" - remark-html@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/remark-html/-/remark-html-6.0.0.tgz#ade7d94b60e452158f28615218450682601dbfc1" @@ -5714,14 +5731,6 @@ remark-parse@^3.0.0: vfile-location "^2.0.0" xtend "^4.0.1" -remark-slug@^4.2.2: - version "4.2.2" - resolved "https://registry.yarnpkg.com/remark-slug/-/remark-slug-4.2.2.tgz#3cfaa02e2e24d98405b296072f2ebbdfad279eb6" - dependencies: - github-slugger "^1.0.0" - mdast-util-to-string "^1.0.0" - unist-util-visit "^1.0.0" - remark-stringify@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/remark-stringify/-/remark-stringify-3.0.0.tgz#f1720893a3e7c845824d95bb573d628d1346ba2a" @@ -7012,7 +7021,7 @@ unist-util-stringify-position@^1.0.0: dependencies: has "^1.0.1" -unist-util-visit@^1.0.0, unist-util-visit@^1.0.1, unist-util-visit@^1.1.0: +unist-util-visit@^1.0.0, unist-util-visit@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-1.1.1.tgz#e917a3b137658b335cb4420c7da2e74d928e4e94"