Skip to content

Commit

Permalink
fix(core): escape chars inside @link tags
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Dec 5, 2024
1 parent 11b5000 commit 65ddaff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-tips-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typedoc-plugin-markdown': patch
---

- Escape characters inside `@link` tags.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { link } from '@plugin/libs/markdown/index.js';
import { backTicks, link } from '@plugin/libs/markdown/index.js';
import { escapeChars } from '@plugin/libs/utils/escape-chars.js';
import { MarkdownThemeContext } from '@plugin/theme/index.js';
import * as fs from 'fs';
import { CommentDisplayPart, InlineTagDisplayPart } from 'typedoc';
Expand Down Expand Up @@ -26,14 +27,21 @@ export function getCommentParts(
case '@linkplain': {
if (part.target) {
const url = getUrl(part);
const wrap = part.tag === '@linkcode' ? '`' : '';
md.push(
url
? `${link(`${wrap}${part.text}${wrap}`, this.getRelativeUrl(url))}`
: part.text,
);
if (url) {
if (part.tag === '@linkcode') {
md.push(
`${link(backTicks(part.text), this.getRelativeUrl(url))}`,
);
} else {
md.push(
`${link(escapeChars(part.text), this.getRelativeUrl(url))}`,
);
}
} else {
md.push(escapeChars(part.text));
}
} else {
md.push(part.text);
md.push(escapeChars(part.text));
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
*
* - {@link CommentInterface} - Links to CommentInterface
* - {@link CommentInterface.prop | Links to CommentInterface.prop}
* - {@link CommentInterface.propb | Links to CommentInterface.propb}
* - {@linkcode CommentInterface.propb | Links to CommentInterface.propb}
* - {@link CommentInterface._prop_with_underscore_ | Links to CommentInterface._prop_with_underscore_}
* - {@link CommentEnum.MemberB}
* - {@link SameName:var}
* - {@link SameName:interface}
* - {@link SameName.prop}
* - {@link prop:var}
* - {@link _prop_with_underscore:var}
* - {@link TypeWithGenerics}
* - {@link NotFound}
*
* External links:
*
Expand Down Expand Up @@ -76,6 +78,7 @@
export interface CommentInterface {
prop: string;
propb: string;
_prop_with_underscore_: string;
}

export interface CommentInterfaceExtended extends CommentInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
exports[`Comments should compile @links with anchors: (Output File Strategy "modules") (Option Group "1") 1`] = `
"- [CommentInterface](README.md#commentinterface) - Links to CommentInterface
- [Links to CommentInterface.prop](README.md#prop)
- [Links to CommentInterface.propb](README.md#propb-1)
- [\`Links to CommentInterface.propb\`](README.md#propb-1)
- [Links to CommentInterface.\\_prop\\_with\\_underscore\\_](README.md#_prop_with_underscore_)
- [CommentEnum.MemberB](README.md#commentenum)
- [SameName:var](README.md#samename-1)
- [SameName:interface](README.md#samename)
- [SameName.prop](README.md#prop-2)
- [prop:var](README.md#prop-3)
- [_prop_with_underscore:var](README.md#_prop_with_underscore)
- [TypeWithGenerics](README.md#typewithgenericsc-d)"
- [\\_prop\\_with\\_underscore:var](README.md#_prop_with_underscore)"
`;

exports[`Comments should compile comments for module: (Output File Strategy "members") (Option Group "1") 1`] = `
Expand All @@ -24,14 +24,16 @@ Links using \`{@link}\` inline tags.
- [CommentInterface](interfaces/CommentInterface.md) - Links to CommentInterface
- [Links to CommentInterface.prop](interfaces/CommentInterface.md#prop)
- [Links to CommentInterface.propb](interfaces/CommentInterface.md#propb)
- [\`Links to CommentInterface.propb\`](interfaces/CommentInterface.md#propb)
- [Links to CommentInterface.\\_prop\\_with\\_underscore\\_](interfaces/CommentInterface.md#_prop_with_underscore_)
- [CommentEnum.MemberB](enumerations/CommentEnum.md)
- [SameName:var](variables/SameName.md)
- [SameName:interface](interfaces/SameName.md)
- [SameName.prop](interfaces/SameName.md#prop)
- [prop:var](variables/prop.md)
- [_prop_with_underscore:var](variables/prop_with_underscore.md)
- [\\_prop\\_with\\_underscore:var](variables/prop_with_underscore.md)
- [TypeWithGenerics](type-aliases/TypeWithGenerics.md)
- NotFound
External links:
Expand Down

0 comments on commit 65ddaff

Please sign in to comment.