@@ -23,7 +23,7 @@ function buildCrossRefIndex(): Map<string, CrossRefTarget> {
2323 const index = new Map < string , CrossRefTarget > ( ) ;
2424
2525 for ( const [ packageId , pkg ] of Object . entries ( apiData ) ) {
26- const basePath = `/ ${ packageId } /api` ;
26+ const basePath = `${ packageId } /api` ;
2727
2828 for ( const [ moduleName , module ] of Object . entries ( pkg . modules ) ) {
2929 // Add module
@@ -118,17 +118,20 @@ export function lookupRef(name: string): CrossRefTarget | undefined {
118118 * - Title tag references from docutils: <cite>ClassName</cite>
119119 * - Single-quoted class names in text: 'ClassName'
120120 */
121- export function processCrossRefs ( html : string , currentPackageId ?: string ) : string {
121+ export function processCrossRefs ( html : string , basePath : string = '' , currentPackageId ?: string ) : string {
122122 const index = getCrossRefIndex ( ) ;
123123
124+ // Helper to build full path with base
125+ const fullPath = ( path : string ) => `${ basePath } /${ path } ` ;
126+
124127 // 1. Handle RST role syntax: :class:`Name`, :func:`Name`, :meth:`Name`, :mod:`Name`
125128 // These often get converted to various forms by docutils
126129 html = html . replace (
127130 / < c o d e c l a s s = " x r e f [ ^ " ] * " > ( [ ^ < ] + ) < \/ c o d e > / g,
128131 ( match , name ) => {
129132 const target = index . get ( name . trim ( ) ) ;
130133 if ( target ) {
131- return `<a href="${ target . path } " class="crossref crossref-${ target . type } ">${ name } </a>` ;
134+ return `<a href="${ fullPath ( target . path ) } " class="crossref crossref-${ target . type } ">${ name } </a>` ;
132135 }
133136 return match ;
134137 }
@@ -141,7 +144,7 @@ export function processCrossRefs(html: string, currentPackageId?: string): strin
141144 const trimmed = name . trim ( ) ;
142145 const target = index . get ( trimmed ) ;
143146 if ( target ) {
144- return `<a href="${ target . path } " class="crossref crossref-${ target . type } ">${ name } </a>` ;
147+ return `<a href="${ fullPath ( target . path ) } " class="crossref crossref-${ target . type } ">${ name } </a>` ;
145148 }
146149 return match ;
147150 }
@@ -155,7 +158,7 @@ export function processCrossRefs(html: string, currentPackageId?: string): strin
155158 // Skip if it looks like it's already part of a link
156159 const target = index . get ( name ) ;
157160 if ( target && target . type === 'class' ) {
158- return `<a href="${ target . path } " class="crossref crossref-class"><code>${ name } </code></a>` ;
161+ return `<a href="${ fullPath ( target . path ) } " class="crossref crossref-class"><code>${ name } </code></a>` ;
159162 }
160163 return match ;
161164 }
@@ -167,7 +170,7 @@ export function processCrossRefs(html: string, currentPackageId?: string): strin
167170 ( match , title , text ) => {
168171 const target = index . get ( title ) || index . get ( text ) ;
169172 if ( target ) {
170- return `<a href="${ target . path } " class="crossref crossref-${ target . type } ">${ text } </a>` ;
173+ return `<a href="${ fullPath ( target . path ) } " class="crossref crossref-${ target . type } ">${ text } </a>` ;
171174 }
172175 return match ;
173176 }
@@ -180,7 +183,7 @@ export function processCrossRefs(html: string, currentPackageId?: string): strin
180183 ( match , name ) => {
181184 const target = index . get ( name ) ;
182185 if ( target && target . type === 'class' ) {
183- return `<a href="${ target . path } " class="crossref crossref-class">'${ name } '</a>` ;
186+ return `<a href="${ fullPath ( target . path ) } " class="crossref crossref-class">'${ name } '</a>` ;
184187 }
185188 return match ;
186189 }
0 commit comments