From 6fd46dc36cdf61ee12186661c1347fb02b32db12 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:56:54 +0530 Subject: [PATCH 1/2] fix: use default slugify from mdit-vue --- package.json | 2 -- pnpm-lock.yaml | 12 ------------ src/node/markdown/markdown.ts | 4 ---- src/node/markdown/plugins/slugify.ts | 24 ------------------------ 4 files changed, 42 deletions(-) delete mode 100644 src/node/markdown/plugins/slugify.ts 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..8d0b3650727 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -16,7 +16,6 @@ import { titlePlugin } from '@mdit-vue/plugin-title' import { tocPlugin, type TocPluginOptions } from '@mdit-vue/plugin-toc' 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' @@ -89,7 +88,6 @@ export const createMarkdownRenderer = async ( // mdit-vue plugins md.use(anchorPlugin, { - slugify, permalink: anchorPlugin.permalink.ariaHidden({}), ...options.anchor } as anchorPlugin.AnchorOptions) @@ -97,7 +95,6 @@ export const createMarkdownRenderer = async ( ...options.frontmatter } as FrontmatterPluginOptions) .use(headersPlugin, { - slugify, ...options.headers } as HeadersPluginOptions) .use(sfcPlugin, { @@ -105,7 +102,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() - ) -} From 0a6865df449d419a5c5585730cf30b7be3a8a94b Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sat, 29 Oct 2022 14:03:23 +0530 Subject: [PATCH 2/2] fix failing tests --- src/node/markdown/markdown.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 8d0b3650727..7cb4f5695c6 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -14,6 +14,7 @@ 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 { highlightLinePlugin } from './plugins/highlightLines' @@ -88,6 +89,7 @@ export const createMarkdownRenderer = async ( // mdit-vue plugins md.use(anchorPlugin, { + slugify, permalink: anchorPlugin.permalink.ariaHidden({}), ...options.anchor } as anchorPlugin.AnchorOptions)