From 34c3f1b85f7577bf63c9a8ff2830673382643eb4 Mon Sep 17 00:00:00 2001 From: d3m1d0v Date: Mon, 11 Nov 2024 16:17:20 +0300 Subject: [PATCH] feat(anchors): remove unsupported chars from heading ids Passed a stricter regexp to slugify, thats remove all unsupported symbols from ids Read more about the supported characters here: https://datatracker.ietf.org/doc/html/rfc3986#section-3.5 --- package-lock.json | 7 ++++--- package.json | 2 +- src/transform/plugins/anchors/index.ts | 5 ++--- test/__snapshots__/anchors.test.ts.snap | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2258ea64..b1dd2431 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "markdownlint": "^0.32.1", "markdownlint-rule-helpers": "0.17.2", "sanitize-html": "^2.11.0", - "slugify": "1.6.5", + "slugify": "1.6.6", "svgo": "^3.2.0" }, "devDependencies": { @@ -13094,8 +13094,9 @@ } }, "node_modules/slugify": { - "version": "1.6.5", - "license": "MIT", + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.6.tgz", + "integrity": "sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==", "engines": { "node": ">=8.0.0" } diff --git a/package.json b/package.json index e3a29032..fcb7150c 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "markdownlint": "^0.32.1", "markdownlint-rule-helpers": "0.17.2", "sanitize-html": "^2.11.0", - "slugify": "1.6.5", + "slugify": "1.6.6", "svgo": "^3.2.0" }, "devDependencies": { diff --git a/src/transform/plugins/anchors/index.ts b/src/transform/plugins/anchors/index.ts index 197a58e7..0fa2e248 100644 --- a/src/transform/plugins/anchors/index.ts +++ b/src/transform/plugins/anchors/index.ts @@ -3,14 +3,13 @@ import GithubSlugger from 'github-slugger'; import StateCore from 'markdown-it/lib/rules_core/state_core'; import Token from 'markdown-it/lib/token'; import {escapeHtml} from 'markdown-it/lib/common/utils'; +import slugify from 'slugify'; import {headingInfo} from '../../utils'; import {MarkdownItPluginCb} from '../typings'; import {CUSTOM_ID_EXCEPTION, CUSTOM_ID_REGEXP} from './constants'; -const slugify: (str: string, opts: {}) => string = require('slugify'); - function createLinkTokens( state: StateCore, id: string, @@ -127,7 +126,7 @@ const index: MarkdownItPluginCb = (md, options) => { } else { id = slugify(title, { lower: true, - remove: /[*+~.()'"!:@`ь?]/g, + remove: /[^\w\s$_\-,;=/]+/g, }); ghId = slugger.slug(title); } diff --git a/test/__snapshots__/anchors.test.ts.snap b/test/__snapshots__/anchors.test.ts.snap index d1e1fc5b..207fcfcc 100644 --- a/test/__snapshots__/anchors.test.ts.snap +++ b/test/__snapshots__/anchors.test.ts.snap @@ -254,8 +254,8 @@ exports[`Anchors should include content by anchor in sharped path file 1`] = ` `; exports[`Anchors should remove quotes from id 1`] = ` -

- +