99 parseHeadingIntoMetadata ,
1010 parseYAMLIntoMetadata ,
1111 transformTypeToReferenceLink ,
12+ transformUnixManualToLink ,
1213} from '../parser/index.mjs' ;
1314import { getRemark } from '../remark.mjs' ;
1415import { transformNodesToString } from '../unist.mjs' ;
@@ -64,18 +65,17 @@ const createQueries = () => {
6465 } ;
6566
6667 /**
67- * Updates a Markdown text containing an API type reference
68- * into a Markdown link referencing to the correct API docs
68+ * Updates a reference
6969 *
70- * @param {import('@types/mdast').Text } node A Markdown link node
70+ * @param {import('@types/mdast').Text } node The current node
7171 * @param {import('@types/mdast').Parent } parent The parent node
72+ * @param {string|RegExp } query The search query
73+ * @param {Function } transformer The function to transform the reference
74+ *
7275 */
73- const updateTypeReference = ( node , parent ) => {
76+ const updateReferences = ( query , transformer , node , parent ) => {
7477 const replacedTypes = node . value
75- . replace (
76- createQueries . QUERIES . normalizeTypes ,
77- transformTypeToReferenceLink
78- )
78+ . replace ( query , transformer )
7979 // Remark doesn't handle leading / trailing spaces, so replace them with
8080 // HTML entities.
8181 . replace ( / ^ \s / , ' ' )
@@ -172,7 +172,20 @@ const createQueries = () => {
172172 addYAMLMetadata,
173173 setHeadingMetadata,
174174 updateMarkdownLink,
175- updateTypeReference,
175+ /** @param {Array<import('@types/mdast').Node> } args */
176+ updateTypeReference : ( ...args ) =>
177+ updateReferences (
178+ createQueries . QUERIES . normalizeTypes ,
179+ transformTypeToReferenceLink ,
180+ ...args
181+ ) ,
182+ /** @param {Array<import('@types/mdast').Node> } args */
183+ updateUnixManualReference : ( ...args ) =>
184+ updateReferences (
185+ createQueries . QUERIES . unixManualPage ,
186+ transformUnixManualToLink ,
187+ ...args
188+ ) ,
176189 updateLinkReference,
177190 addStabilityMetadata,
178191 updateStabilityPrefixToLink,
@@ -195,6 +208,8 @@ createQueries.QUERIES = {
195208 stabilityIndexPrefix : / S t a b i l i t y : ( [ 0 - 5 ] ) / ,
196209 // ReGeX for retrieving the inner content from a YAML block
197210 yamlInnerContent : / ^ < ! - - [ ] ? (?: Y A M L ( [ \s \S ] * ?) | ( [ \S ] * ?) ) ? [ ] ? - - > / ,
211+ // ReGeX for finding references to Unix manuals
212+ unixManualPage : / \b ( [ a - z . ] + ) \( ( \d ) ( [ a - z ] ? ) \) / g,
198213} ;
199214
200215createQueries . UNIST = {
@@ -217,6 +232,12 @@ createQueries.UNIST = {
217232 */
218233 isTextWithType : ( { type, value } ) =>
219234 type === 'text' && createQueries . QUERIES . normalizeTypes . test ( value ) ,
235+ /**
236+ * @param {import('@types/mdast').Text } text
237+ * @returns {boolean }
238+ */
239+ isTextWithUnixManual : ( { type, value } ) =>
240+ type === 'text' && createQueries . QUERIES . unixManualPage . test ( value ) ,
220241 /**
221242 * @param {import('@types/mdast').Html } html
222243 * @returns {boolean }
0 commit comments