From ec0be0bccbe7c2cc782bcba87cd5673a018e5cb2 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 11 May 2021 15:17:40 -0400 Subject: [PATCH] Fix non-alphanumeric start/end characters in TOC (#776) Fixes #775. --- src/lib/content.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/content.js b/src/lib/content.js index 3d5b02148..bc82e5b34 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -158,7 +158,8 @@ function generateToc(markdown) { // Note: character range in regex is roughly "word characters including accented" (eg: bublé) const id = text .toLowerCase() - .replace(/[\s-!()<>`'"&,]+/g, '-'); + .replace(/[\s-!()<>`'"&,]+/g, '-') + .replace(/(?:^-|-$)/g, ''); toc.push({ text, id, level }); } return toc;