File tree Expand file tree Collapse file tree
src/generators/metadata/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -220,6 +220,34 @@ describe('parseApiDoc', () => {
220220
221221 assert . strictEqual ( findLink ( entry ) ?. url , 'events.html#some-section' ) ;
222222 } ) ;
223+
224+ it ( 'strips subdirectory prefix from nested .md links' , ( ) => {
225+ const tree = u ( 'root' , [
226+ h ( 'fs' ) ,
227+ u ( 'paragraph' , [
228+ u ( 'link' , { url : 'namespaces/comparators.md' } , [
229+ u ( 'text' , 'comparators' ) ,
230+ ] ) ,
231+ ] ) ,
232+ ] ) ;
233+ const [ entry ] = parseApiDoc ( { path, tree } , typeMap ) ;
234+
235+ assert . strictEqual ( findLink ( entry ) ?. url , 'comparators.html' ) ;
236+ } ) ;
237+
238+ it ( 'strips subdirectory prefix and preserves hash fragments' , ( ) => {
239+ const tree = u ( 'root' , [
240+ h ( 'fs' ) ,
241+ u ( 'paragraph' , [
242+ u ( 'link' , { url : 'namespaces/comparators.md#some-section' } , [
243+ u ( 'text' , 'comparators' ) ,
244+ ] ) ,
245+ ] ) ,
246+ ] ) ;
247+ const [ entry ] = parseApiDoc ( { path, tree } , typeMap ) ;
248+
249+ assert . strictEqual ( findLink ( entry ) ?. url , 'comparators.html#some-section' ) ;
250+ } ) ;
223251 } ) ;
224252
225253 describe ( 'document without headings' , ( ) => {
Original file line number Diff line number Diff line change 11'use strict' ;
2+ import { basename } from 'node:path/posix' ;
23
34import { SKIP } from 'unist-util-visit' ;
45
@@ -18,7 +19,7 @@ import { transformNodesToString } from '../../../utils/unist.mjs';
1819export const visitMarkdownLink = node => {
1920 node . url = node . url . replace (
2021 QUERIES . markdownUrl ,
21- ( _ , filename , hash = '' ) => `${ filename } .html${ hash } `
22+ ( _ , filename , hash = '' ) => `${ basename ( filename ) } .html${ hash } `
2223 ) ;
2324
2425 return [ SKIP ] ;
You can’t perform that action at this time.
0 commit comments