Skip to content

Commit

Permalink
Support non-alphanumeric characters in ToC (#756)
Browse files Browse the repository at this point in the history
* Support non-alphanumeric characters in ToC

```js
// Note: character range in regex is roughly "word characters including accented" (eg: bublé)
const id = text
  // korean, Japanese (hiragana)
  .replace(/[^가-힣\u3041-\u3096]/g, '');
```

If want to keep existing intent, the above code might be more suitable.

But i haven't opinion yet, so I remove the one line that erased non-alphanumeric characters.

Reference issue comment: #754 (comment)

* Filter out programming/markdown characters only

Co-authored-by: Jason Miller <developit@users.noreply.github.com>
  • Loading branch information
mu-hun and developit authored Mar 18, 2021
1 parent 0657736 commit f660325
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ function generateToc(markdown) {
// Note: character range in regex is roughly "word characters including accented" (eg: bublé)
const id = text
.toLowerCase()
.replace(/[\s-]+/g, '-')
.replace(/[^a-z0-9\u00C0-\u024F-]/g, '');
.replace(/[\s-!()<>`'"&,]+/g, '-')
toc.push({ text, id, level });
}
return toc;
Expand Down

0 comments on commit f660325

Please sign in to comment.