From db44eccac3c3571bdcc07d956d3d76752c2a29d3 Mon Sep 17 00:00:00 2001 From: Parth Patel <3318934+parthpp@users.noreply.github.com> Date: Fri, 21 Jun 2019 20:40:04 -0400 Subject: [PATCH] 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. --- packages/docusaurus-1.x/lib/core/__tests__/toSlug.test.js | 2 ++ packages/docusaurus-1.x/lib/core/toSlug.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-1.x/lib/core/__tests__/toSlug.test.js b/packages/docusaurus-1.x/lib/core/__tests__/toSlug.test.js index 9baddc98c088..130b2e3b252c 100644 --- a/packages/docusaurus-1.x/lib/core/__tests__/toSlug.test.js +++ b/packages/docusaurus-1.x/lib/core/__tests__/toSlug.test.js @@ -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 awes’ome', 'this-is-awesome'], ].forEach(([input, output]) => { test(`toSlug('${input}') -> '${output}'`, () => { expect(toSlug(input)).toBe(output); diff --git a/packages/docusaurus-1.x/lib/core/toSlug.js b/packages/docusaurus-1.x/lib/core/toSlug.js index 27d37153467a..e81f7d73f2c2 100644 --- a/packages/docusaurus-1.x/lib/core/toSlug.js +++ b/packages/docusaurus-1.x/lib/core/toSlug.js @@ -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