From 9ff8155cd95d58fd223bb69496a265c816d1e58c Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 23 Oct 2018 11:02:29 +0100 Subject: [PATCH] build(docs-infra): mark code blocks to disable auto-linking (#26675) You can now mark `` blocks with a `no-auto-link` css class to tell the code auto-linker to ignore this code block. PR Close #26675 --- .../angular-base-package/post-processors/auto-link-code.js | 4 +++- .../post-processors/auto-link-code.spec.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.js b/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.js index 92f5cf06ee..5285de6e62 100644 --- a/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.js +++ b/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.js @@ -30,7 +30,9 @@ module.exports = function autoLinkCode(getDocFromAlias) { return (ast) => { visit(ast, 'element', (node, ancestors) => { // Only interested in code elements that are not inside links - if (autoLinkCodeImpl.codeElements.some(elementType => is(node, elementType)) && + if (autoLinkCodeImpl.codeElements.some(elementType => + is(node, elementType)) && + (!node.properties.className || node.properties.className.indexOf('no-auto-link') === -1) && ancestors.every(ancestor => !is(ancestor, 'a'))) { visit(node, 'text', (node, ancestors) => { // Only interested in text nodes that are not inside links diff --git a/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.spec.js b/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.spec.js index c5fabf43d3..414bac60fd 100644 --- a/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.spec.js +++ b/aio/tools/transforms/angular-base-package/post-processors/auto-link-code.spec.js @@ -109,4 +109,11 @@ describe('autoLinkCode post-processor', () => { processor.$process([doc]); expect(doc.renderedContent).toEqual('MyClass'); }); + + it('should ignore code blocks that are marked with a `no-auto-link` class', () => { + aliasMap.addDoc({ docType: 'class', id: 'MyClass', aliases: ['MyClass'], path: 'a/b/myclass' }); + const doc = { docType: 'test-doc', renderedContent: 'MyClass' }; + processor.$process([doc]); + expect(doc.renderedContent).toEqual('MyClass'); + }); });