From cbd97072f48a98f0bdfdbfb2c274d9a574cae832 Mon Sep 17 00:00:00 2001 From: yamanerkam Date: Mon, 29 Jun 2026 11:39:07 +0300 Subject: [PATCH] fix(docs-infra): don't auto-link code symbols used as link text When an inline code symbol is used as the text of an explicit markdown link (e.g. [`httpResource`](/guide/http/http-resource)), the codespan renderer recognized it as an API symbol and wrapped it in a second anchor pointing at the API reference. This produced nested tags, so the explicit link was effectively replaced by the API symbol link. Disable auto-linking while rendering a link's inner tokens so the explicit href is preserved, matching the pattern already used by the heading and docs-card renderers. Fixes #69549 --- .../shared-docs/pipeline/shared/marked/test/link/link.md | 1 + .../pipeline/shared/marked/test/link/link.spec.mts | 4 ++++ .../pipeline/shared/marked/transformations/link.mts | 9 ++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/adev/shared-docs/pipeline/shared/marked/test/link/link.md b/adev/shared-docs/pipeline/shared/marked/test/link/link.md index e8a6b828796..4003d840c7e 100644 --- a/adev/shared-docs/pipeline/shared/marked/test/link/link.md +++ b/adev/shared-docs/pipeline/shared/marked/test/link/link.md @@ -2,3 +2,4 @@ [same page](#test) [same site](../other/page) [npm packages](https://docs.npmjs.com/getting-started/what-is-npm 'What is npm?') +[`CommonModule`](../other/page) diff --git a/adev/shared-docs/pipeline/shared/marked/test/link/link.spec.mts b/adev/shared-docs/pipeline/shared/marked/test/link/link.spec.mts index cc4f753f2b6..86849cf2c80 100644 --- a/adev/shared-docs/pipeline/shared/marked/test/link/link.spec.mts +++ b/adev/shared-docs/pipeline/shared/marked/test/link/link.spec.mts @@ -38,6 +38,10 @@ describe('markdown to html', () => { ); }); + it('should not auto-link a code symbol used as link text', () => { + expect(parsedMarkdown).toContain('CommonModule'); + }); + it('should throw if on absolute links to adev', async () => { try { parsedMarkdown = await parseMarkdown( diff --git a/adev/shared-docs/pipeline/shared/marked/transformations/link.mts b/adev/shared-docs/pipeline/shared/marked/transformations/link.mts index d01b65abf6c..393c369c1db 100644 --- a/adev/shared-docs/pipeline/shared/marked/transformations/link.mts +++ b/adev/shared-docs/pipeline/shared/marked/transformations/link.mts @@ -35,5 +35,12 @@ export function linkRender(this: AdevDocsRenderer, {href, title, tokens}: Tokens } const titleAttribute = title ? ` title="${title}"` : ''; - return `${this.parser.parseInline(tokens)}`; + // Disable auto-linking while rendering the link's content so that a code symbol used as the + // link text (e.g. [`httpResource`](/guide/http/http-resource)) isn't turned into a nested + // anchor pointing at the API reference, which would override the explicit link. + const previousDisableAutoLinking = this.context.disableAutoLinking; + this.context.disableAutoLinking = true; + const content = this.parser.parseInline(tokens); + this.context.disableAutoLinking = previousDisableAutoLinking; + return `${content}`; }