Skip to content

Commit d3899e0

Browse files
committed
Handle relative links within <source src>
1 parent 8df8262 commit d3899e0

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ title: Changelog
88

99
- Permit `-` within tag names to support `typescript-json-schema`'s `@TJS-type` tag, #2972.
1010

11+
### Bug Fixes
12+
13+
- Relative links in `<source src=x>` and `<source srcset=x>` elements will now be discovered by TypeDoc, #2975.
14+
1115
### Thanks!
1216

1317
- @jonathanhefner
18+
- @laymonage
1419

1520
## v0.28.7 (2025-06-30)
1621

src/lib/converter/comments/textParser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,13 @@ function checkTagLink(data: TextParserData): RelativeLink | undefined {
314314

315315
if (token.text.startsWith("<source ", pos)) {
316316
data.pos += 8;
317-
return checkAttribute(data, "srcset");
317+
const saveData = { ...data };
318+
const attr = checkAttribute(data, "srcset");
319+
if (!attr) {
320+
Object.assign(data, saveData);
321+
return checkAttribute(data, "src");
322+
}
323+
return attr;
318324
}
319325
}
320326

src/test/comments.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,38 @@ describe("Comment Parser", () => {
16681668
);
16691669
});
16701670

1671+
it("Recognizes HTML picture source src links", () => {
1672+
const comment = getComment(`/**
1673+
* <source src="./test.wav" >
1674+
* <source media="(prefers-color-scheme: dark)" src="./test_dark.mp4"/>
1675+
* <source src="https://example.com/favicon.ico">
1676+
*/`);
1677+
1678+
equal(
1679+
comment.summary,
1680+
[
1681+
{ kind: "text", text: '<source src="' },
1682+
{
1683+
kind: "relative-link",
1684+
text: "./test.wav",
1685+
target: 1 as FileId,
1686+
targetAnchor: undefined,
1687+
},
1688+
{ kind: "text", text: '" >\n<source media="(prefers-color-scheme: dark)" src="' },
1689+
{
1690+
kind: "relative-link",
1691+
text: "./test_dark.mp4",
1692+
target: 2 as FileId,
1693+
targetAnchor: undefined,
1694+
},
1695+
{
1696+
kind: "text",
1697+
text: '"/>\n<source src="https://example.com/favicon.ico">',
1698+
},
1699+
] satisfies CommentDisplayPart[],
1700+
);
1701+
});
1702+
16711703
it("Recognizes HTML anchor links", () => {
16721704
const comment = getComment(`/**
16731705
* <a data-foo="./path.txt" href="./test.png" >

0 commit comments

Comments
 (0)