@@ -54,6 +54,7 @@ async function htmlToMarkdown(options = {}) {
5454 document : false ,
5555 handlers : {
5656 table ( state , node ) {
57+ // This fixes nested tables that happen in the conversion from html to markdown
5758 let html = toHtml ( node ) ;
5859 const parsedHTML = new JSDOM ( html ) . window . document . getElementsByClassName ( "params" ) [ 1 ] ;
5960 if ( parsedHTML !== undefined ) {
@@ -62,6 +63,19 @@ async function htmlToMarkdown(options = {}) {
6263 const result = { type : "html" , value : html } ;
6364 state . patch ( node , result ) ;
6465 return result ;
66+ } ,
67+ a ( state , node ) {
68+ // This fixes internal linking e.g. from #~myawesomemethod to #myawesomemethod
69+ const regex = / < a .* ?h r e f = " ( .* ?) " .* ?> ( [ ^ < ] * ) < \/ a > / ;
70+ const result = { type : "html" , value : toHtml ( node ) . replaceAll ( "~" , "" ) } ;
71+ let href = result . value . match ( regex ) ;
72+ if ( href !== null && href [ 1 ] . split ( "#" ) [ 1 ] != null ) {
73+ let text = href [ 2 ] ;
74+ href = href [ 1 ] ;
75+ result . value = result . value . replace ( href , "#" + href . split ( "#" ) [ 1 ] . toLowerCase ( ) ) . replace ( text , text . replace ( href . split ( "#" ) [ 1 ] , "" ) + "#" + href . split ( "#" ) [ 1 ] ) ;
76+ }
77+ state . patch ( node , result ) ;
78+ return result ;
6579 }
6680 }
6781 } )
@@ -96,13 +110,19 @@ if (!fs.existsSync(outputDirectory)) {
96110
97111// 3. Iterate through every .html generated by jsdoc
98112for ( const file of fs . readdirSync ( path . join ( "dist" , "api" ) ) ) {
99- // Skip js files
113+ // Skip some files
100114 if ( excludedFiles [ file ] !== undefined ) continue ;
101115
116+ // Skip js files
117+ if ( file . endsWith ( ".js.html" ) ) continue ;
118+
102119 const filePath = path . join ( inputDirectory , file ) ;
120+ const mardownPath = path . join ( outputDirectory , file . replace ( ".html" , ".md" ) ) ;
103121 // Skip directories
104122 if ( fs . statSync ( filePath ) . isDirectory ( ) ) continue ;
105123
124+ //console.log("HTML -> Markdown", "|", filePath, "->", mardownPath);
125+
106126 // Read the html file
107127 const htmlString = fs . readFileSync ( filePath ) ;
108128
@@ -126,7 +146,9 @@ for (const file of fs.readdirSync(path.join("dist", "api"))) {
126146
127147 // Save markdown file
128148 fs . writeFileSync (
129- path . join ( outputDirectory , file . replace ( ".html" , ".md" ) ) ,
149+ mardownPath ,
130150 markdown
131151 ) ;
132152}
153+
154+ console . log ( "Conversion done" ) ;
0 commit comments