Skip to content

Commit f41f6c8

Browse files
committed
Do not emit warnings on urls within @link tags
Resolves #1980
1 parent 9ed9f01 commit f41f6c8

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
### Features
44

5+
- Added defined in links for classes, enums, #180.
56
- Added support for `*.ghe.com` and `*.github.us` GitHub enterprise domains for source links, #2001.
67
- Expose `Converter.parseRawComment` for plugins to parse additional markdown files, #2004.
7-
- Added defined in links for classes, enums #180.
88

99
### Bug Fixes
1010

11-
- Fixed missing `sources` property on signature reflections #1996.
11+
- TypeDoc will no longer emit a warning for `{@link}` containing a URL, #1980.
1212
- `excludeNotDocumented` will no longer remove functions/methods/accessors which are documented, #1994.
13+
- Fixed missing `sources` property on signature reflections #1996.
1314

1415
### Thanks!
1516

src/lib/converter/plugins/LinkResolverPlugin.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,26 +220,37 @@ function resolveLinkTag(
220220
) {
221221
let pos = 0;
222222
const end = part.text.length;
223+
while (pos < end && ts.isWhiteSpaceLike(part.text.charCodeAt(pos))) {
224+
pos++;
225+
}
226+
const origText = part.text;
223227

224228
// Try to parse one
225229
const declRef = parseDeclarationReference(part.text, pos, end);
226230

227-
let target: Reflection | undefined;
231+
let target: Reflection | string | undefined;
228232
if (declRef) {
229233
// Got one, great! Try to resolve the link
230234
target = resolveDeclarationReference(reflection, declRef[0]);
231235
pos = declRef[1];
232236
}
233237

238+
if (!target) {
239+
if (urlPrefix.test(part.text)) {
240+
const wsIndex = part.text.search(/\s/);
241+
target =
242+
wsIndex === -1 ? part.text : part.text.substring(0, wsIndex);
243+
pos = target.length;
244+
}
245+
}
246+
234247
// If resolution via a declaration reference failed, revert to the legacy "split and check"
235248
// method... this should go away in 0.24, once people have had a chance to migrate any failing links.
236249
if (!target) {
237250
const resolved = legacyResolveLinkTag(reflection, part);
238251
if (resolved) {
239252
warn(
240-
`Failed to resolve {@link ${
241-
part.text
242-
}} in ${reflection.getFriendlyFullName()} with declaration references. This link will break in v0.24.`
253+
`Failed to resolve {@link ${origText}} in ${reflection.getFriendlyFullName()} with declaration references. This link will break in v0.24.`
243254
);
244255
}
245256
return resolved;
@@ -255,7 +266,9 @@ function resolveLinkTag(
255266
}
256267

257268
part.target = target;
258-
part.text = part.text.substring(pos).trim() || target.name;
269+
part.text =
270+
part.text.substring(pos).trim() ||
271+
(typeof target === "string" ? target : target.name);
259272

260273
return part;
261274
}

src/test/converter2/issues/gh1980.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* {@link http://example.com }
3+
* {@link http://example.com | with text}
4+
* {@link http://example.com jsdoc support}
5+
*/
6+
export const link = 123;

src/test/issueTests.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,35 @@ export const issueTests: {
599599
equal(comments2, ["Comment for a", "Comment for b"]);
600600
},
601601

602+
gh1980(project, logger) {
603+
const link = query(project, "link");
604+
equal(
605+
link.comment?.summary.filter((t) => t.kind === "inline-tag"),
606+
[
607+
{
608+
kind: "inline-tag",
609+
tag: "@link",
610+
target: "http://example.com",
611+
text: "http://example.com",
612+
},
613+
{
614+
kind: "inline-tag",
615+
tag: "@link",
616+
target: "http://example.com",
617+
text: "with text",
618+
},
619+
{
620+
kind: "inline-tag",
621+
tag: "@link",
622+
target: "http://example.com",
623+
text: "jsdoc support",
624+
},
625+
]
626+
);
627+
logger.discardDebugMessages();
628+
logger.expectNoOtherMessages();
629+
},
630+
602631
gh1986(project, logger) {
603632
const a = query(project, "a");
604633
equal(

0 commit comments

Comments
 (0)