Skip to content

Commit eba0d60

Browse files
committed
fix(core): escape chars inside @link tags
1 parent d45e436 commit eba0d60

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

.changeset/thin-tips-remember.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'typedoc-plugin-markdown': patch
3+
---
4+
5+
- Escape characters inside `@link` tags.

packages/typedoc-plugin-markdown/src/theme/context/helpers/get-comment-parts.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { link } from '@plugin/libs/markdown/index.js';
1+
import { backTicks, link } from '@plugin/libs/markdown/index.js';
2+
import { escapeChars } from '@plugin/libs/utils/escape-chars.js';
23
import { MarkdownThemeContext } from '@plugin/theme/index.js';
34
import * as fs from 'fs';
45
import { CommentDisplayPart, InlineTagDisplayPart } from 'typedoc';
@@ -26,14 +27,21 @@ export function getCommentParts(
2627
case '@linkplain': {
2728
if (part.target) {
2829
const url = getUrl(part);
29-
const wrap = part.tag === '@linkcode' ? '`' : '';
30-
md.push(
31-
url
32-
? `${link(`${wrap}${part.text}${wrap}`, this.getRelativeUrl(url))}`
33-
: part.text,
34-
);
30+
if (url) {
31+
if (part.tag === '@linkcode') {
32+
md.push(
33+
`${link(backTicks(part.text), this.getRelativeUrl(url))}`,
34+
);
35+
} else {
36+
md.push(
37+
`${link(escapeChars(part.text), this.getRelativeUrl(url))}`,
38+
);
39+
}
40+
} else {
41+
md.push(escapeChars(part.text));
42+
}
3543
} else {
36-
md.push(part.text);
44+
md.push(escapeChars(part.text));
3745
}
3846
break;
3947
}

packages/typedoc-plugin-markdown/test/fixtures/src/comments/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
*
99
* - {@link CommentInterface} - Links to CommentInterface
1010
* - {@link CommentInterface.prop | Links to CommentInterface.prop}
11-
* - {@link CommentInterface.propb | Links to CommentInterface.propb}
11+
* - {@linkcode CommentInterface.propb | Links to CommentInterface.propb}
12+
* - {@link CommentInterface._prop_with_underscore_ | Links to CommentInterface._prop_with_underscore_}
1213
* - {@link CommentEnum.MemberB}
1314
* - {@link SameName:var}
1415
* - {@link SameName:interface}
1516
* - {@link SameName.prop}
1617
* - {@link prop:var}
1718
* - {@link _prop_with_underscore:var}
1819
* - {@link TypeWithGenerics}
20+
* - {@link NotFound}
1921
*
2022
* External links:
2123
*
@@ -76,6 +78,7 @@
7678
export interface CommentInterface {
7779
prop: string;
7880
propb: string;
81+
_prop_with_underscore_: string;
7982
}
8083

8184
export interface CommentInterfaceExtended extends CommentInterface {

packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
exports[`Comments should compile @links with anchors: (Output File Strategy "modules") (Option Group "1") 1`] = `
44
"- [CommentInterface](README.md#commentinterface) - Links to CommentInterface
55
- [Links to CommentInterface.prop](README.md#prop)
6-
- [Links to CommentInterface.propb](README.md#propb-1)
6+
- [\`Links to CommentInterface.propb\`](README.md#propb-1)
7+
- [Links to CommentInterface.\\_prop\\_with\\_underscore\\_](README.md#_prop_with_underscore_)
78
- [CommentEnum.MemberB](README.md#commentenum)
89
- [SameName:var](README.md#samename-1)
910
- [SameName:interface](README.md#samename)
1011
- [SameName.prop](README.md#prop-2)
1112
- [prop:var](README.md#prop-3)
12-
- [_prop_with_underscore:var](README.md#_prop_with_underscore)
13-
- [TypeWithGenerics](README.md#typewithgenericsc-d)"
13+
- [\\_prop\\_with\\_underscore:var](README.md#_prop_with_underscore)"
1414
`;
1515

1616
exports[`Comments should compile comments for module: (Output File Strategy "members") (Option Group "1") 1`] = `
@@ -24,14 +24,16 @@ Links using \`{@link}\` inline tags.
2424
2525
- [CommentInterface](interfaces/CommentInterface.md) - Links to CommentInterface
2626
- [Links to CommentInterface.prop](interfaces/CommentInterface.md#prop)
27-
- [Links to CommentInterface.propb](interfaces/CommentInterface.md#propb)
27+
- [\`Links to CommentInterface.propb\`](interfaces/CommentInterface.md#propb)
28+
- [Links to CommentInterface.\\_prop\\_with\\_underscore\\_](interfaces/CommentInterface.md#_prop_with_underscore_)
2829
- [CommentEnum.MemberB](enumerations/CommentEnum.md)
2930
- [SameName:var](variables/SameName.md)
3031
- [SameName:interface](interfaces/SameName.md)
3132
- [SameName.prop](interfaces/SameName.md#prop)
3233
- [prop:var](variables/prop.md)
33-
- [_prop_with_underscore:var](variables/prop_with_underscore.md)
34+
- [\\_prop\\_with\\_underscore:var](variables/prop_with_underscore.md)
3435
- [TypeWithGenerics](type-aliases/TypeWithGenerics.md)
36+
- NotFound
3537
3638
External links:
3739

0 commit comments

Comments
 (0)