build(docs-infra): Ensures that only member docs are linked (#36316)

This commit ensures that `member` docs are only linked if the linking
text contains `.`.

PR Close #36316
This commit is contained in:
Sonu Kapoor 2020-04-14 07:44:14 -04:00 committed by Matias Niemelä
parent 4fb034aeec
commit aebd5f9af6
2 changed files with 16 additions and 0 deletions

View File

@ -90,6 +90,12 @@ module.exports = function autoLinkCode(getDocFromAlias) {
}
var doc = docs[0];
const isInvalidDoc = doc.docType === 'member' && !keyword.includes('.');
if (isInvalidDoc) {
return false;
}
if (doc.path === '') {
var message = `
autoLinkCode: Doc path is empty for "${doc.id}" - link will not be generated for "${keyword}".

View File

@ -135,6 +135,16 @@ describe('autoLinkCode post-processor', () => {
expect(doc.renderedContent).toEqual('<code>MyClass</code>');
});
it('should ignore documents when the `docType` is set to `member` and the keyword doesn\'t include `.`',
() => {
aliasMap.addDoc({docType: 'class', id: 'MyClass', aliases: ['MyClass'], path: 'a/b/myclass'});
aliasMap.addDoc(
{docType: 'member', id: 'MyEnum', aliases: ['MyEnum'], path: 'a/b/c'});
const doc = {docType: 'test-doc', renderedContent: '<code>MyClass</code>'};
processor.$process([doc]);
expect(doc.renderedContent).toEqual('<code><a href="a/b/myclass" class="code-anchor">MyClass</a></code>');
});
it('should insert anchors for individual text nodes within a code block', () => {
aliasMap.addDoc({docType: 'class', id: 'MyClass', aliases: ['MyClass'], path: 'a/b/myclass'});
const doc = {