Skip to content

Commit

Permalink
fix: properly escape chars inside anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Sep 23, 2021
1 parent 64376e9 commit d4e5b1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
@@ -1,6 +1,7 @@
import * as Handlebars from 'handlebars';
import { PageEvent } from 'typedoc';
import { MarkdownTheme } from '../../theme';
import { escapeChars } from '../../utils';

export default function (theme: MarkdownTheme) {
Handlebars.registerHelper('breadcrumbs', function (this: PageEvent) {
Expand Down Expand Up @@ -36,8 +37,8 @@ function breadcrumb(page: PageEvent, model: any, md: string[]) {
if (model.url) {
md.push(
page.url === model.url
? `${escape(model.name)}`
: `[${escape(model.name)}](${Handlebars.helpers.relativeURL(
? `${escapeChars(model.name)}`
: `[${escapeChars(model.name)}](${Handlebars.helpers.relativeURL(
model.url,
)})`,
);
Expand Down
@@ -1,11 +1,8 @@
import * as Handlebars from 'handlebars';
import { escapeChars } from '../../utils';

export default function () {
Handlebars.registerHelper('escape', function (str: string) {
return str
.replace(/>/g, '\\>')
.replace(/_/g, '\\_')
.replace(/`/g, '\\`')
.replace(/\|/g, '\\|');
return escapeChars(str);
});
}
Expand Up @@ -5,6 +5,7 @@ import {
ReflectionGroup,
} from 'typedoc';
import { MarkdownTheme } from '../../theme';
import { escapeChars } from '../../utils';

export default function (theme: MarkdownTheme) {
Handlebars.registerHelper(
Expand All @@ -21,7 +22,7 @@ export default function (theme: MarkdownTheme) {
function pushGroup(group: ReflectionGroup, md: string[]) {
const children = group.children.map(
(child) =>
`- [${escape(child.name)}](${Handlebars.helpers.relativeURL(
`- [${escapeChars(child.name)}](${Handlebars.helpers.relativeURL(
child.url,
)})`,
);
Expand Down

0 comments on commit d4e5b1d

Please sign in to comment.