fix: replace apostrophe with empty string in header slugification (#1618)

* Replace apostrophe with empty string in header

This change is to replicate the github behviour with respect to apostrophe in
headers. When there is an apostrophe in a header, github replaces it with empty string
when creating an anchor link to that header. Docusaurus should follow the same convention.
This commit is contained in:
Parth Patel 2019-06-21 20:40:04 -04:00 committed by Yangshun Tay
parent 9e84525bcf
commit db44eccac3
2 changed files with 4 additions and 2 deletions

View file

@ -16,6 +16,8 @@ const toSlug = require('../toSlug');
['Someting long ...', 'someting-long-'],
['foo_bar', 'foo_bar'],
['some _ heading', 'some-_-heading'],
["I'm good", 'im-good'],
['This is awesome', 'this-is-awesome'],
].forEach(([input, output]) => {
test(`toSlug('${input}') -> '${output}'`, () => {
expect(toSlug(input)).toBe(output);

View file

@ -45,8 +45,8 @@ module.exports = (string, context = {}) => {
.replace(new RegExp(`[${accents}]`, 'g'), c =>
without.charAt(accents.indexOf(c)),
)
// Replace `.`, `(` and `?` with blank string like Github does
.replace(/\.|\(|\?/g, '')
// Replace `'`, ``, `.`, `(` and `?` with blank string like GitHub does
.replace(/'||\.|\(|\?/g, '')
// Dash special characters except '_' (underscore)
.replace(exceptAlphanumAndUnderscore, '-')
// Compress multiple dash