File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -184,7 +184,8 @@ function slugify(text: string): string {
184184function resolveUrl ( url : string , packageName : string , repoInfo ?: RepositoryInfo ) : string {
185185 if ( ! url ) return url
186186 if ( url . startsWith ( '#' ) ) {
187- return url
187+ // Prefix anchor links to match heading IDs (avoids collision with page IDs)
188+ return `#user-content-${ url . slice ( 1 ) } `
188189 }
189190 if ( hasProtocol ( url , { acceptRelative : true } ) ) {
190191 try {
@@ -292,7 +293,11 @@ export async function renderReadmeHtml(
292293 // Handle duplicate slugs (GitHub-style: foo, foo-1, foo-2)
293294 const count = usedSlugs . get ( slug ) ?? 0
294295 usedSlugs . set ( slug , count + 1 )
295- const id = count === 0 ? slug : `${ slug } -${ count } `
296+ const uniqueSlug = count === 0 ? slug : `${ slug } -${ count } `
297+
298+ // Prefix with 'user-content-' to avoid collisions with page IDs
299+ // (e.g., #install, #dependencies, #versions are used by the package page)
300+ const id = `user-content-${ uniqueSlug } `
296301
297302 return `<h${ semanticLevel } id="${ id } " data-level="${ depth } ">${ text } </h${ semanticLevel } >\n`
298303 }
You can’t perform that action at this time.
0 commit comments