Skip to content

Commit c063836

Browse files
authored
docs: transform markdown links into html (#124)
1 parent ad71871 commit c063836

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

docs/gen/html.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ import { t } from './texts';
44
import { indent } from './util';
55

66
export function escapeHtml(text = ''): string {
7-
return text
8-
.replaceAll(/&/g, '&')
9-
.replaceAll(/</g, '&lt;')
10-
.replaceAll(/>/g, '&gt;')
11-
.replaceAll(/"/g, '&quot;')
12-
.replaceAll(/'/g, '&#39;')
13-
.replaceAll(/\n/g, '<br>')
14-
.replaceAll(/`([^`]+)`/g, '<code>$1</code>');
7+
return (
8+
text
9+
// change `[text](link)` into `<a href="link">{text}</a>`
10+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, text, url) => {
11+
return `<a href="${url}">${text}</a>`;
12+
})
13+
.replaceAll(/&/g, '&amp;')
14+
.replaceAll(/</g, '&lt;')
15+
.replaceAll(/>/g, '&gt;')
16+
.replaceAll(/"/g, '&quot;')
17+
.replaceAll(/'/g, '&#39;')
18+
.replaceAll(/\n/g, '<br>')
19+
.replaceAll(/`([^`]+)`/g, '<code>$1</code>')
20+
);
1521
}
1622

1723
export function paramULHtml(children: string | string[]): string {

0 commit comments

Comments
 (0)