1+ import { unified } from 'unified' ;
2+ import html from 'remark-html' ;
13import {
24 DEFAULT_EXPRESSION ,
35 LEADING_HYPHEN ,
@@ -160,7 +162,6 @@ function parseSignature(textRaw, values) {
160162 // We have a default value, save it and then cut it off of the signature
161163 defaultValue = declaredParameter . substring ( equalSignPos , 1 ) . trim ( ) ;
162164 declaredParameter = declaredParameter . substring ( 0 , equalSignPos ) ;
163- console . log ( 'eq' , declaredParameter ) ;
164165 }
165166
166167 let parameter = rawParameters [ i ] ;
@@ -188,7 +189,7 @@ function parseSignature(textRaw, values) {
188189 }
189190
190191 if ( ! parameter ) {
191- // Couldn't find the shared one, I have no idea what this case is but we'll see
192+ // Couldn't find the shared one
192193 if ( declaredParameter . startsWith ( '...' ) ) {
193194 parameter = { name : declaredParameter } ;
194195 } else {
@@ -221,10 +222,13 @@ function textJoin(nodes) {
221222 return nodes
222223 . map ( node => {
223224 switch ( node . type ) {
224- case ` strong` :
225+ case ' strong' :
225226 return `**${ textJoin ( node . children ) } **` ;
226- case ` emphasis` :
227+ case ' emphasis' :
227228 return `_${ textJoin ( node . children ) } _` ;
229+ case 'link' : {
230+ return `[${ node . label } ][]` ;
231+ }
228232 default :
229233 if ( node . children ) {
230234 return textJoin ( node . children ) ;
@@ -249,7 +253,9 @@ function parseListItem(child) {
249253
250254 current . textRaw = textJoin (
251255 child . children . filter ( node => node . type !== 'list' )
252- ) ;
256+ )
257+ . replace ( / \s + / g, ' ' )
258+ . replace ( / < ! - - .* ?- - > / gs, '' ) ;
253259
254260 if ( ! current . textRaw ) {
255261 throw new Error ( `empty list item: ${ JSON . stringify ( child ) } ` ) ;
@@ -260,20 +266,25 @@ function parseListItem(child) {
260266 // Extract name
261267 if ( RETURN_EXPRESSION . test ( text ) ) {
262268 current . name = 'return' ;
269+
270+ let [ , returnType ] = text . match ( / ` ( .* ?) ` / ) ;
271+ returnType = returnType . substring ( 1 , returnType . length - 1 ) ;
272+ current . type = returnType ;
273+
263274 text = text . replace ( RETURN_EXPRESSION , '' ) ;
264275 } else {
265276 const [ , name ] = text . match ( NAME_EXPRESSION ) || [ ] ;
266277 if ( name ) {
267278 current . name = name ;
268279 text = text . replace ( NAME_EXPRESSION , '' ) ;
269280 }
270- }
271281
272- // Extract type (if provided)
273- const [ , type ] = text . match ( TYPE_EXPRESSION ) || [ ] ;
274- if ( type ) {
275- current . type = type ;
276- text = text . replace ( TYPE_EXPRESSION , '' ) ;
282+ // Extract type (if provided)
283+ const [ , type ] = text . match ( TYPE_EXPRESSION ) || [ ] ;
284+ if ( type ) {
285+ current . type = type ;
286+ text = text . replace ( TYPE_EXPRESSION , '' ) ;
287+ }
277288 }
278289
279290 // Remove leading hyphens
@@ -350,6 +361,7 @@ function handleEntry(entry, parentSection) {
350361 if ( stability ) {
351362 section . stability = parseInt ( stability [ 1 ] , 10 ) ;
352363 section . stabilityText = stability [ 2 ] . replaceAll ( '\n' , ' ' ) . trim ( ) ;
364+
353365 delete nodes [ i ] ;
354366 needsCompressing = true ;
355367 }
@@ -433,7 +445,20 @@ function handleEntry(entry, parentSection) {
433445 section . shortDesc = section . desc ;
434446 }
435447
436- // TODO parse definitoons
448+ // Render the description as if it was html
449+ section . desc = unified ( )
450+ . use ( function ( ) {
451+ this . Parser = ( ) => ( { type : 'root' , children : nodes } ) ;
452+ } )
453+ . use ( html , { sanitize : false } )
454+ . processSync ( '' )
455+ . toString ( )
456+ . trim ( ) ;
457+
458+ if ( ! section . desc ) {
459+ // Rendering returned nothing
460+ delete section . desc ;
461+ }
437462 } ;
438463
439464 /**
0 commit comments