@@ -3,7 +3,7 @@ import sanitizeHtml from 'sanitize-html'
33import { hasProtocol } from 'ufo'
44import type { ReadmeResponse , TocItem } from '#shared/types/readme'
55import { convertBlobOrFileToRawUrl , type RepositoryInfo } from '#shared/utils/git-providers'
6- import { decodeHtmlEntities , stripHtmlTags } from '#shared/utils/html'
6+ import { decodeHtmlEntities , stripHtmlTags , slugify } from '#shared/utils/html'
77import { convertToEmoji } from '#shared/utils/emoji'
88import { toProxiedImageUrl } from '#server/utils/image-proxy'
99import { highlightCodeSync } from './shiki'
@@ -200,25 +200,6 @@ export const ALLOWED_ATTR: Record<string, string[]> = {
200200 'p' : [ 'align' ] ,
201201}
202202
203- /**
204- * Generate a GitHub-style slug from heading text.
205- * - Convert to lowercase
206- * - Remove HTML tags
207- * - Replace spaces with hyphens
208- * - Remove special characters (keep alphanumeric, hyphens, underscores)
209- * - Collapse multiple hyphens
210- */
211- export function slugify ( text : string ) : string {
212- return stripHtmlTags ( text )
213- . replace ( / & n b s p ; ? / g, '' ) // remove non breaking spaces
214- . toLowerCase ( )
215- . trim ( )
216- . replace ( / \s + / g, '-' ) // Spaces to hyphens
217- . replace ( / [ ^ \w \u4e00 - \u9fff \u3040 - \u309f \u30a0 - \u30ff - ] / g, '' ) // Keep alphanumeric, CJK, hyphens
218- . replace ( / - + / g, '-' ) // Collapse multiple hyphens
219- . replace ( / ^ - | - $ / g, '' ) // Trim leading/trailing hyphens
220- }
221-
222203/**
223204 * Lazy ATX heading extension for marked: allows headings without a space after `#`.
224205 *
0 commit comments