diff --git a/package.json b/package.json index 8258c22be13..ee29c3d8ad3 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,6 @@ "@types/compression": "^1.7.2", "@types/cross-spawn": "^6.0.2", "@types/debug": "^4.1.7", - "@types/diacritics": "^1.3.1", "@types/escape-html": "^1.0.2", "@types/fs-extra": "^9.0.13", "@types/koa": "^2.13.5", @@ -127,7 +126,6 @@ "conventional-changelog-cli": "^2.2.2", "cross-spawn": "^7.0.3", "debug": "^4.3.4", - "diacritics": "^1.3.0", "enquirer": "^2.3.6", "esbuild": "^0.15.12", "escape-html": "^1.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5dcf7287ae1..0140c221e56 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,7 +22,6 @@ importers: '@types/compression': ^1.7.2 '@types/cross-spawn': ^6.0.2 '@types/debug': ^4.1.7 - '@types/diacritics': ^1.3.1 '@types/escape-html': ^1.0.2 '@types/fs-extra': ^9.0.13 '@types/koa': ^2.13.5 @@ -44,7 +43,6 @@ importers: conventional-changelog-cli: ^2.2.2 cross-spawn: ^7.0.3 debug: ^4.3.4 - diacritics: ^1.3.0 enquirer: ^2.3.6 esbuild: ^0.15.12 escape-html: ^1.0.3 @@ -113,7 +111,6 @@ importers: '@types/compression': 1.7.2 '@types/cross-spawn': 6.0.2 '@types/debug': 4.1.7 - '@types/diacritics': 1.3.1 '@types/escape-html': 1.0.2 '@types/fs-extra': 9.0.13 '@types/koa': 2.13.5 @@ -131,7 +128,6 @@ importers: conventional-changelog-cli: 2.2.2 cross-spawn: 7.0.3 debug: 4.3.4_supports-color@9.2.3 - diacritics: 1.3.0 enquirer: 2.3.6 esbuild: 0.15.12 escape-html: 1.0.3 @@ -685,10 +681,6 @@ packages: '@types/ms': 0.7.31 dev: true - /@types/diacritics/1.3.1: - resolution: {integrity: sha512-tAH+RY51Zbz7ZSzN7yxQBKEue78U6weZ1UUBNjFoitoLbJGFJCKI7KVHwGsnYo4s2xSFr9KGEkjst2FolpYqyA==} - dev: true - /@types/escape-html/1.0.2: resolution: {integrity: sha512-gaBLT8pdcexFztLSPRtriHeXY/Kn4907uOCZ4Q3lncFBkheAWOuNt53ypsF8szgxbEJ513UeBzcf4utN0EzEwA==} dev: true @@ -1654,10 +1646,6 @@ packages: object-keys: 1.1.1 dev: true - /diacritics/1.3.0: - resolution: {integrity: sha512-wlwEkqcsaxvPJML+rDh/2iS824jbREk6DUMUKkEaSlxdYHeS43cClJtsWglvw2RfeXGm6ohKDqsXteJ5sP5enA==} - dev: true - /dot-prop/5.3.0: resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==} engines: {node: '>=8'} diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index bd9c3aef299..7cb4f5695c6 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -14,9 +14,9 @@ import { import { sfcPlugin, type SfcPluginOptions } from '@mdit-vue/plugin-sfc' import { titlePlugin } from '@mdit-vue/plugin-title' import { tocPlugin, type TocPluginOptions } from '@mdit-vue/plugin-toc' +import { slugify } from '@mdit-vue/shared' import { IThemeRegistration } from 'shiki' import { highlight } from './plugins/highlight' -import { slugify } from './plugins/slugify' import { highlightLinePlugin } from './plugins/highlightLines' import { lineNumberPlugin } from './plugins/lineNumbers' import { containerPlugin } from './plugins/containers' @@ -97,7 +97,6 @@ export const createMarkdownRenderer = async ( ...options.frontmatter } as FrontmatterPluginOptions) .use(headersPlugin, { - slugify, ...options.headers } as HeadersPluginOptions) .use(sfcPlugin, { @@ -105,7 +104,6 @@ export const createMarkdownRenderer = async ( } as SfcPluginOptions) .use(titlePlugin) .use(tocPlugin, { - slugify, ...options.toc } as TocPluginOptions) diff --git a/src/node/markdown/plugins/slugify.ts b/src/node/markdown/plugins/slugify.ts deleted file mode 100644 index 5039c209fa0..00000000000 --- a/src/node/markdown/plugins/slugify.ts +++ /dev/null @@ -1,24 +0,0 @@ -// string.js slugify drops non ascii chars so we have to -// use a custom implementation here -import { remove as removeDiacritics } from 'diacritics' -// eslint-disable-next-line no-control-regex -const rControl = /[\u0000-\u001f]/g -const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g - -export const slugify = (str: string): string => { - return ( - removeDiacritics(str) - // Remove control characters - .replace(rControl, '') - // Replace special characters - .replace(rSpecial, '-') - // Remove continuous separators - .replace(/\-{2,}/g, '-') - // Remove prefixing and trailing separators - .replace(/^\-+|\-+$/g, '') - // ensure it doesn't start with a number (#121) - .replace(/^(\d)/, '_$1') - // lowercase - .toLowerCase() - ) -}