diff --git a/lib/main/build-site.js b/lib/main/build-site.js index ab35da817..ae4354635 100644 --- a/lib/main/build-site.js +++ b/lib/main/build-site.js @@ -34,11 +34,19 @@ const exts = _.keys(highlights); /** * Converts Lodash method references into documentation links. * + * Searches for inline code references matching `_.word` (e.g., `_.map`, `_.filter`) + * in documentation body text and wraps them in anchor links. Excludes code within + * headers as those already have proper anchors. + * * @private * @param {Object} $ The Cheerio object. + * + * @example + * // Body text: _.map_.map + * // Headers:

_.VERSION

→ unchanged (excluded) */ function autoLink($) { - $('.doc-container code').each(function() { + $('.doc-container code:not(:header code)').each(function() { const $code = $(this); const html = $code.html(); if (/^_\.\w+$/.test(html)) { @@ -176,9 +184,16 @@ function build() { .readFileSync(readmePath, 'utf8') // Uncomment docdown HTML hints. .replace(/(<)!--\s*|\s*--(>)/g, '$1$2') - // Convert source and npm package links to anchors. - .replace(/\[source\]\(([^)]+)\) \[npm package\]\(([^)]+)\)/g, (match, href1, href2) => - `

source npm package

` + // Convert docdown-generated [source] and [npm package] links to HTML. + // These appear as markdown immediately after h3 tags, which marky-markdown + // doesn't process (it treats content after HTML blocks as plain text). + // Pattern 1: Dual links for methods with npm packages. + .replace(/(]*>.*?<\/h3>)\n\[source\]\(([^)]+)\) \[npm package\]\(([^)]+)\)/g, (match, h3, href1, href2) => + `${h3}\n

source npm package

` + ) + // Pattern 2: Standalone [source] links for properties without npm packages. + .replace(/(]*>.*?<\/h3>)\n\[source\]\(([^)]+)\)(?! \[npm package\])/g, (match, h3, href) => + `${h3}\n

source

` ); const $ = cheerio.load(marky(markdown, {