Skip to content

Commit cacf8a7

Browse files
committed
fix slugs - closes #345
1 parent 33ffa0e commit cacf8a7

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/site-kit/src/lib/markdown/renderer.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,14 @@ export async function render_content_markdown(
274274

275275
return smart_quotes(token.text, true);
276276
},
277-
heading({ tokens, depth, raw }) {
278-
const text = this.parser!.parseInline(tokens);
277+
heading({ tokens, depth }) {
278+
const text = this.parser!.parseInline(tokens).replace(/<\/?code>/g, '');
279279

280-
headings[depth - 1] = slugify(raw);
280+
headings[depth - 1] = slugify(text);
281281
headings.length = depth;
282282
const slug = headings.filter(Boolean).join('-');
283-
return `<h${depth} id="${slug}"><span>${text.replace(
284-
/<\/?code>/g,
285-
''
286-
)}</span><a href="#${slug}" class="permalink"><span class="visually-hidden">permalink</span></a></h${depth}>`;
283+
284+
return `<h${depth} id="${slug}"><span>${text}</span><a href="#${slug}" class="permalink" aria-label="permalink"></a></h${depth}>`;
287285
},
288286
code({ text }) {
289287
return snippets.get(text);

packages/site-kit/src/lib/markdown/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ export function clean(markdown: string) {
3232

3333
export const slugify = (str: string) => {
3434
return clean(str)
35-
.replace(/&.+;/g, '')
36-
.replace(/[^a-zA-Z0-9-$(.):]/g, '-')
35+
.replace(/&.+?;/g, '')
36+
.replace(/[^a-zA-Z0-9-$(.):']/g, '-')
3737
.replace(/-{2,}/g, '-')
3838
.replace(/^-/, '')
39-
.replace(/-$/, '')
40-
.replace(/(<([^>]+)>)/gi, '');
39+
.replace(/-$/, '');
4140
};
4241

4342
export function smart_quotes(str: string, html: boolean = false) {

0 commit comments

Comments
 (0)