1
0
Fork 0
mirror of synced 2026-06-05 17:44:04 +00:00
test-reporter/src/utils/slugger.ts
2026-03-02 14:28:52 +01:00

17 lines
707 B
TypeScript

// Returns HTML element id and href link usable as manual anchor links
// This is needed because Github in check run summary doesn't automatically
// create links out of headings as it normally does for other markdown content
import {ReportOptions} from '../report/get-report.js'
export function slug(name: string, options: ReportOptions): {id: string; link: string} {
const slugId = name
.trim()
.replace(/_/g, '')
.replace(/[./\\]/g, '-')
.replace(/[^\w-]/g, '')
const id = `user-content-${slugId}`
// When using the Action Summary for display, links must include the "user-content-" prefix.
const link = options.useActionsSummary ? `#${id}` : `#${slugId}`
return {id, link}
}