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 4fe687ffd1..c0a370c294 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 @@ -55,7 +55,7 @@ module.exports = function autoLinkCode(getDocFromAlias) { const index = parent.children.indexOf(node); // Can we convert the whole text node into a doc link? - const docs = getDocFromAlias(node.value); + const docs = getFilteredDocsFromAlias([node.value], 0); if (foundValidDoc(docs, node.value, file)) { parent.children.splice(index, 1, createLinkNode(docs[0], node.value)); } else { @@ -89,14 +89,18 @@ module.exports = function autoLinkCode(getDocFromAlias) { return ancestors.some(ancestor => is(ancestor, 'a')); } + function getFilteredDocsFromAlias(words, index) { + // Remove docs that fail the custom filter tests. + return autoLinkCodeImpl.customFilters.reduce( + (docs, filter) => filter(docs, words, index), getDocFromAlias(words[index])); + } + function getNodes(node, file) { return textContent(node) .split(/([A-Za-z0-9_.-]+)/) .filter(word => word.length) .map((word, index, words) => { - // remove docs that fail the custom filter tests - const filteredDocs = autoLinkCodeImpl.customFilters.reduce( - (docs, filter) => filter(docs, words, index), getDocFromAlias(word)); + const filteredDocs = getFilteredDocsFromAlias(words, index); return foundValidDoc(filteredDocs, word, file) ? // Create a link wrapping the text node. 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 cfd58ca55c..f90572265c 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 @@ -89,7 +89,7 @@ describe('autoLinkCode post-processor', () => { expect(doc.renderedContent).toEqual('xyz-MyClass'); }); - it('should ignore code items that are filtered out by custom filters', () => { + it('should ignore code items that are filtered out by custom filters (multiple words)', () => { autoLinkCode.customFilters = [filterPipes]; aliasMap.addDoc({ docType: 'pipe', @@ -115,6 +115,27 @@ describe('autoLinkCode post-processor', () => { ''); }); + it('should ignore code items that are filtered out by custom filters (single word)', () => { + const filterAnchors = (docs, words, index) => (words[index].toLowerCase() === 'a') ? [] : docs; + autoLinkCode.customFilters = [filterAnchors]; + autoLinkCode.docTypes = ['directive']; + + aliasMap.addDoc({ + docType: 'directive', + id: 'MyAnchorDirective', + aliases: ['MyAnchorDirective', 'a'], + path: 'a/b/my-anchor-directive', + }); + const doc = { + docType: 'test-doc', + renderedContent: 'a', + }; + + processor.$process([doc]); + + expect(doc.renderedContent).toBe('a'); + }); + it('should ignore generated nodes', () => { const filterAnchors = (docs, words, index) => (words[index].toLowerCase() === 'a') ? [] : docs; autoLinkCode.customFilters = [filterAnchors]; diff --git a/aio/tools/transforms/angular-base-package/services/auto-link-filters/filterPipes.js b/aio/tools/transforms/angular-base-package/services/auto-link-filters/filterPipes.js index ebaf0c5764..3f3b6b738e 100644 --- a/aio/tools/transforms/angular-base-package/services/auto-link-filters/filterPipes.js +++ b/aio/tools/transforms/angular-base-package/services/auto-link-filters/filterPipes.js @@ -8,5 +8,6 @@ module.exports = function filterPipes() { docs.filter(doc => doc.docType !== 'pipe' || doc.pipeOptions.name !== '\'' + words[index] + '\'' || - index > 0 && words[index - 1].trim() === '|'); + index === 0 || + words[index - 1].trim() === '|'); };