Skip to content

Commit da8907d

Browse files
committed
fix(typedoc,transformer): sanitize text
1 parent 5e8ab8a commit da8907d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

typedoc/transformer.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function getAnchor(data: ProjectReflection, id: number) {
7474
}
7575

7676
function link(data, arg, text) {
77-
return `[${text}](#${getAnchor(data, arg.target)})`;
77+
return `[${sanitize(text)}](#${getAnchor(data, arg.target)})`;
7878
}
7979

8080
function stringifyObject(type: ReflectionType) {
@@ -97,6 +97,15 @@ function getPriority(item: Reflection) {
9797
return +(tags.find((item) => item.tag === '@priority')?.content[0].text || 0);
9898
}
9999

100+
function sanitize(text: string) {
101+
return text
102+
.replace(/&/g, '&')
103+
.replace(/</g, '&lt;')
104+
.replace(/>/g, '&gt;')
105+
.replace(/"/g, '&quot;')
106+
.replace(/'/g, '&#039;');
107+
}
108+
100109
async function typedocToMarkdown(
101110
data: ProjectReflection,
102111
children: DeclarationReflection[] | undefined = [],
@@ -109,7 +118,7 @@ async function typedocToMarkdown(
109118
if (parameters && parameters.length) {
110119
markdown.push('| Parameter | Extends | Description |');
111120
markdown.push('| ---- | ---- | ----------- |');
112-
parameters.forEach(({ name, type, comment }) => markdown.push(`| ${name} | \`${type || 'any'}\` | ${comment} |`));
121+
parameters.forEach(({ name, type, comment }) => markdown.push(`| ${name} | \`${sanitize(type) || 'any'}\` | ${comment} |`));
113122
}
114123
}
115124
function throws(ref: Reflection) {

0 commit comments

Comments
 (0)