Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export interface LinkEntryRenderable {
label: string;
url: string;
title?: string;
target?: string;
}

export type CliOptionRenderable = CliOption & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function DocsPillRow(props: {links: LinkEntryRenderable[]}) {
class="docs-pill"
href={link.url}
title={link.title}
target={link.target}
dangerouslySetInnerHTML={{__html: link.label}}
></a>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ describe('jsdoc transforms', () => {
label: 'Angular',
url: 'https://angular.io',
title: undefined,
target: '_blank',
});

expect(entry.additionalLinks[1]).toEqual({
label: 'Angular',
url: 'https://angular.io',
title: 'Angular',
target: '_blank',
});

expect(entry.additionalLinks[2]).toEqual({
Expand Down Expand Up @@ -127,10 +129,12 @@ describe('jsdoc transforms', () => {
expect(entry.additionalLinks[8]).toEqual({
label: 'ApplicationRef',
url: 'https://angular.dev/api/core/ApplicationRef',
target: '_blank',
});
expect(entry.additionalLinks[9]).toEqual({
label: 'angular.dev',
url: 'https://angular.dev',
target: '_blank',
});

expect(entry.additionalLinks[10]).toEqual({
Expand Down Expand Up @@ -182,6 +186,7 @@ describe('jsdoc transforms', () => {
label: 'Method with <code>backticks</code> in title',
url: 'https://example.com',
title: 'Title with `code`',
target: '_blank',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
unknownSymbolMessage,
} from '../symbol-context.mjs';
import {addApiLinksToHtml} from './code-transforms.mjs';
import {isExternalLink} from '../../../shared/marked/helpers.mjs';

const JS_DOC_USAGE_NOTE_TAGS: Set<string> = new Set(['remarks', 'usageNotes', 'example']);
export const JS_DOC_SEE_TAG = 'see';
Expand Down Expand Up @@ -144,17 +145,19 @@ function getHtmlAdditionalLinks<T extends HasJsDocTags>(entry: T): LinkEntryRend
const seeAlsoLinks = entry.jsdocTags
.filter((tag) => tag.name === JS_DOC_SEE_TAG)
.map((tag) => tag.comment)
.map((comment) => {
.map((comment): LinkEntryRenderable | undefined => {
// TODO: Throw when the comment is an absolute link.
// With TS 5.9 this is not possible as the ts api that extracts comments from tags strips the "http" part of links.

const markdownLinkMatch = comment.match(markdownLinkRule);

if (markdownLinkMatch) {
const url = markdownLinkMatch[2];
return {
label: convertBackticksToCodeTags(markdownLinkMatch[1]),
url: markdownLinkMatch[2],
url,
title: markdownLinkMatch[3],
...(isExternalLink(url) ? {target: '_blank'} : {}),
};
}

Expand All @@ -163,11 +166,9 @@ function getHtmlAdditionalLinks<T extends HasJsDocTags>(entry: T): LinkEntryRend
if (linkMatch) {
const link = linkMatch[1];
const parsed = parseAtLink(link);
if (!parsed) {
return undefined;
}
if (!parsed) return undefined;
const {url, label} = parsed;
return {label, url};
return {label, url, ...(isExternalLink(url) ? {target: '_blank'} : {})};
}

return undefined;
Expand Down
Loading