@@ -34,11 +34,19 @@ const exts = _.keys(highlights);
3434/**
3535 * Converts Lodash method references into documentation links.
3636 *
37+ * Searches for inline code references matching `_.word` (e.g., `_.map`, `_.filter`)
38+ * in documentation body text and wraps them in anchor links. Excludes code within
39+ * headers as those already have proper anchors.
40+ *
3741 * @private
3842 * @param {Object } $ The Cheerio object.
43+ *
44+ * @example
45+ * // Body text: <code>_.map</code> → <a href="#map"><code>_.map</code></a>
46+ * // Headers: <h3><code>_.VERSION</code></h3> → unchanged (excluded)
3947 */
4048function autoLink ( $ ) {
41- $ ( '.doc-container code' ) . each ( function ( ) {
49+ $ ( '.doc-container code:not(:header code) ' ) . each ( function ( ) {
4250 const $code = $ ( this ) ;
4351 const html = $code . html ( ) ;
4452 if ( / ^ _ \. \w + $ / . test ( html ) ) {
@@ -176,9 +184,16 @@ function build() {
176184 . readFileSync ( readmePath , 'utf8' )
177185 // Uncomment docdown HTML hints.
178186 . replace ( / ( < ) ! - - \s * | \s * - - ( > ) / g, '$1$2' )
179- // Convert source and npm package links to anchors.
180- . replace ( / \[ s o u r c e \] \( ( [ ^ ) ] + ) \) \[ n p m p a c k a g e \] \( ( [ ^ ) ] + ) \) / g, ( match , href1 , href2 ) =>
181- `<p><a href="${ href1 } ">source</a> <a href="${ href2 } ">npm package</a></p>`
187+ // Convert docdown-generated [source] and [npm package] links to HTML.
188+ // These appear as markdown immediately after h3 tags, which marky-markdown
189+ // doesn't process (it treats content after HTML blocks as plain text).
190+ // Pattern 1: Dual links for methods with npm packages.
191+ . replace ( / ( < h 3 [ ^ > ] * > .* ?< \/ h 3 > ) \n \[ s o u r c e \] \( ( [ ^ ) ] + ) \) \[ n p m p a c k a g e \] \( ( [ ^ ) ] + ) \) / g, ( match , h3 , href1 , href2 ) =>
192+ `${ h3 } \n<p><a href="${ href1 } ">source</a> <a href="${ href2 } ">npm package</a></p>`
193+ )
194+ // Pattern 2: Standalone [source] links for properties without npm packages.
195+ . replace ( / ( < h 3 [ ^ > ] * > .* ?< \/ h 3 > ) \n \[ s o u r c e \] \( ( [ ^ ) ] + ) \) (? ! \[ n p m p a c k a g e \] ) / g, ( match , h3 , href ) =>
196+ `${ h3 } \n<p><a href="${ href } ">source</a></p>`
182197 ) ;
183198
184199 const $ = cheerio . load ( marky ( markdown , {
0 commit comments