@@ -55,20 +55,39 @@ export const parseApiDoc = ({ file, tree }, typeMap) => {
5555 // Get all Markdown Heading entries from the tree
5656 const headingNodes = selectAll ( 'heading' , tree ) ;
5757
58+ // visit(tree, node => {
59+ // let skip = false;
60+
61+ // // Update Markdown link references to be plain links
62+ // if (is(node, createQueries.UNIST.isLinkReference)) {
63+ // skip = true;
64+ // updateLinkReference(node, markdownDefinitions);
65+ // }
66+
67+ // // Normalizes URLs that reference API doc files with .md extensions to
68+ // // be .html instead, since the files will eventually get compiled as HTML
69+ // if (is(node, createQueries.UNIST.isMarkdownUrl)) {
70+ // skip = true;
71+ // updateMarkdownLink(node);
72+ // }
73+
74+ // return skip ? SKIP : undefined;
75+ // });
76+
5877 // Handles Markdown link references and updates them to be plain links
59- visit ( tree , createQueries . UNIST . isLinkReference , node =>
60- updateLinkReference ( node , markdownDefinitions )
61- ) ;
78+ visit ( tree , createQueries . UNIST . isLinkReference , node => {
79+ updateLinkReference ( node , markdownDefinitions ) ;
80+ return [ SKIP ] ;
81+ } ) ;
6282
6383 // Removes all the original definitions from the tree as they are not needed
6484 // anymore, since all link references got updated to be plain links
6585 remove ( tree , markdownDefinitions ) ;
6686
67- // Handles the normalisation URLs that reference to API doc files with .md extension
68- // to replace the .md into .html, since the API doc files get eventually compiled as HTML
69- visit ( tree , createQueries . UNIST . isMarkdownUrl , node =>
70- updateMarkdownLink ( node )
71- ) ;
87+ visit ( tree , createQueries . UNIST . isMarkdownUrl , node => {
88+ updateMarkdownLink ( node ) ;
89+ return [ SKIP ] ;
90+ } ) ;
7291
7392 // If the document has no headings but it has content, we add a fake heading to the top
7493 // so that our parsing logic can work correctly, and generate content for the whole file
@@ -113,33 +132,73 @@ export const parseApiDoc = ({ file, tree }, typeMap) => {
113132 // `index + 1` is used to skip the current Heading Node
114133 const subTree = createTree ( 'root' , tree . children . slice ( index , stop ) ) ;
115134
116- // Visits all Stability Index nodes from the current subtree if there's any
117- // and then apply the Stability Index metadata to the current metadata entry
118- visit ( subTree , createQueries . UNIST . isStabilityNode , node =>
119- addStabilityMetadata ( node , ignoreStability ? undefined : apiEntryMetadata )
120- ) ;
121-
122- // Visits all HTML nodes from the current subtree and if there's any that matches
123- // our YAML metadata structure, it transforms into YAML metadata
124- // and then apply the YAML Metadata to the current Metadata entry
125- visit ( subTree , createQueries . UNIST . isYamlNode , node => {
126- // TODO: Is there always only one YAML node?
127- apiEntryMetadata . setYamlPosition ( node . position ) ;
128- addYAMLMetadata ( node , apiEntryMetadata ) ;
135+ visit ( subTree , ( node , index , parent ) => {
136+ let skip = false ;
137+
138+ // Applies stability index metadata if present
139+ if ( createQueries . UNIST . isStabilityNode ( node ) ) {
140+ skip = true ;
141+
142+ addStabilityMetadata (
143+ node ,
144+ ignoreStability ? undefined : apiEntryMetadata
145+ ) ;
146+ }
147+
148+ // Transform any YAML metadata and then apply it to the current
149+ // metadata entry
150+ if ( createQueries . UNIST . isYamlNode ( node ) ) {
151+ // TODO: Is there always only one YAML node?
152+ apiEntryMetadata . setYamlPosition ( node . position ) ;
153+ addYAMLMetadata ( node , apiEntryMetadata ) ;
154+ }
155+
156+ let valueUpdated = false ;
157+
158+ if ( createQueries . UNIST . isTextWithType ( node ) ) {
159+ skip = true ;
160+
161+ valueUpdated = true ;
162+ node . value = updateTypeReference ( node ) ;
163+ }
164+
165+ if ( createQueries . UNIST . isTextWithUnixManual ( node ) ) {
166+ skip = true ;
167+
168+ valueUpdated = true ;
169+ node . value = updateUnixManualReference ( node ) ;
170+ }
171+
172+ if ( valueUpdated ) {
173+ // This changes the type into a link by splitting it up into several nodes,
174+ // and adding those nodes to the parent.
175+ const {
176+ children : [ newNode ] ,
177+ } = remarkProcessor . parse ( node . value ) ;
178+
179+ // Replace the original node with the new node(s)
180+ parent . children . splice ( index , 1 , ...newNode . children ) ;
181+ }
182+
183+ return skip ? SKIP : undefined ;
129184 } ) ;
130185
131186 // Visits all Text nodes from the current subtree and if there's any that matches
132187 // any API doc type reference and then updates the type reference to be a Markdown link
133- visit ( subTree , createQueries . UNIST . isTextWithType , ( node , _ , parent ) =>
134- updateTypeReference ( node , parent )
135- ) ;
188+ // visit(subTree, createQueries.UNIST.isTextWithType, (node, _, parent) => {
189+ // updateTypeReference(node, parent);
190+ // return SKIP;
191+ // });
136192
137193 // Visits all Unix manual references, and replaces them with links
138- visit (
139- subTree ,
140- createQueries . UNIST . isTextWithUnixManual ,
141- ( node , _ , parent ) => updateUnixManualReference ( node , parent )
142- ) ;
194+ // visit(
195+ // subTree,
196+ // createQueries.UNIST.isTextWithUnixManual,
197+ // (node, _, parent) => {
198+ // updateUnixManualReference(node, parent);
199+ // return SKIP;
200+ // }
201+ // );
143202
144203 // Removes already parsed items from the subtree so that they aren't included in the final content
145204 remove ( subTree , [ createQueries . UNIST . isYamlNode ] ) ;
0 commit comments