@@ -58,16 +58,15 @@ const fetchFilesystem = cache({
58
58
59
59
const text = await response . text ( ) ;
60
60
const filesystem = await parseOpenAPI ( { value : text , rootURL : url } ) ;
61
- const cache : Map < string , Promise < string > > = new Map ( ) ;
62
- const transformedFs = await traverse ( filesystem , async ( node ) => {
61
+ const parseMarkdownWithCache = createMarkdownParser ( ) ;
62
+ const transformedFs = await traverse ( filesystem , async ( node , path ) => {
63
63
if ( 'description' in node && typeof node . description === 'string' && node . description ) {
64
- if ( cache . has ( node . description ) ) {
65
- node [ 'x-description-html' ] = await cache . get ( node . description ) ;
66
- } else {
67
- const promise = parseMarkdown ( node . description ) ;
68
- cache . set ( node . description , promise ) ;
69
- node [ 'x-description-html' ] = await promise ;
64
+ const lastKey = path && path [ path . length - 1 ] ;
65
+ // Avoid parsing descriptions in examples.
66
+ if ( lastKey === 'example' ) {
67
+ return node ;
70
68
}
69
+ node [ 'x-description-html' ] = await parseMarkdownWithCache ( node . description ) ;
71
70
}
72
71
return node ;
73
72
} ) ;
@@ -80,3 +79,17 @@ const fetchFilesystem = cache({
80
79
} ;
81
80
} ,
82
81
} ) ;
82
+
83
+ /**
84
+ * Create a markdown parser that caches the results of parsing.
85
+ */
86
+ const createMarkdownParser = ( ) => async ( input : string ) => {
87
+ const cache = new Map < string , Promise < string > > ( ) ;
88
+ if ( cache . has ( input ) ) {
89
+ return cache . get ( input ) as Promise < string > ;
90
+ }
91
+
92
+ const promise = parseMarkdown ( input ) ;
93
+ cache . set ( input , promise ) ;
94
+ return promise ;
95
+ } ;
0 commit comments