Skip to content

Commit c528c0a

Browse files
committed
Anchor links are not relative links
Resolves #2604
1 parent 41f0040 commit c528c0a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Bug Fixes
88

99
- Added `@author` to the default list of recognized tags, #2603.
10+
- Anchor links are no longer incorrectly checked for relative paths, #2604
1011

1112
### Thanks!
1213

src/lib/converter/comments/textParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function checkAttribute(
256256
}
257257

258258
function isRelativeLink(link: string) {
259-
return !/^[a-z]+:\/\/|^\/|^[a-z]:\\/i.test(link);
259+
return !/^[a-z]+:\/\/|^\/|^[a-z]:\\|^#/i.test(link);
260260
}
261261

262262
function findLabelEnd(text: string, pos: number) {

src/test/comments.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ describe("Comment Parser", () => {
13561356
it("Recognizes markdown links", () => {
13571357
const comment = getComment(`/**
13581358
* [text](./relative.md) ![](image.png)
1359-
* Not relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com)
1359+
* Not relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com) [hash](#hash)
13601360
*/`);
13611361

13621362
equal(comment.summary, [
@@ -1366,7 +1366,7 @@ describe("Comment Parser", () => {
13661366
{ kind: "relative-link", text: "image.png", target: 2 },
13671367
{
13681368
kind: "text",
1369-
text: ")\nNot relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com)",
1369+
text: ")\nNot relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com) [hash](#hash)",
13701370
},
13711371
] satisfies CommentDisplayPart[]);
13721372
});
@@ -1376,6 +1376,7 @@ describe("Comment Parser", () => {
13761376
* [1]: ./example.md
13771377
* [2]:<./example with space>
13781378
* [3]: https://example.com
1379+
* [4]: #hash
13791380
*/`);
13801381

13811382
equal(comment.summary, [
@@ -1389,7 +1390,7 @@ describe("Comment Parser", () => {
13891390
},
13901391
{
13911392
kind: "text",
1392-
text: "\n[3]: https://example.com",
1393+
text: "\n[3]: https://example.com\n[4]: #hash",
13931394
},
13941395
] satisfies CommentDisplayPart[]);
13951396
});
@@ -1422,6 +1423,7 @@ describe("Comment Parser", () => {
14221423
* <a data-foo="./path.txt" href="./test.png" >
14231424
* <a href="./test space.png"/>
14241425
* <a href="https://example.com/favicon.ico">
1426+
* <a href="#hash">
14251427
*/`);
14261428

14271429
equal(comment.summary, [
@@ -1435,7 +1437,7 @@ describe("Comment Parser", () => {
14351437
},
14361438
{
14371439
kind: "text",
1438-
text: '"/>\n<a href="https://example.com/favicon.ico">',
1440+
text: '"/>\n<a href="https://example.com/favicon.ico">\n<a href="#hash">',
14391441
},
14401442
] satisfies CommentDisplayPart[]);
14411443
});

0 commit comments

Comments
 (0)