Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion nuxt/server/utils/integrations-enrich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ const GITHUB_HEADERS = {

// Mirrors GitHub's own heading slugger so anchors written against a README's
// GitHub-rendered preview (e.g. `#egm-optional` for "## EGM (optional)") keep resolving here.
//
// One space per hyphen, not one per run of them. GitHub strips the punctuation first and
// hyphenates whatever spaces are left, each on its own, so a heading with punctuation
// between two words keeps the space on both sides of it and lands a double hyphen:
// "Bugs / Feature request" is `#bugs--feature-request` there. Collapsing runs with \s+
// gave `#bugs-feature-request` and every table-of-contents link a README author wrote
// against GitHub for such a heading pointed at an id that did not exist. Headings whose
// words are separated by a single space are identical either way, which is why only the
// punctuated ones broke.
function githubSlugify (heading: string): string {
return encodeURIComponent(
heading
.trim()
.toLowerCase()
.replace(/[^\w一-龥\- ]/g, '')
.replace(/\s+/g, '-')
.replace(/\s/g, '-')
)
}

Expand Down