🌐 AI搜索 & 代理 主页
Skip to content

Commit adb32a0

Browse files
committed
doc: fix conversion of source only links from md to html
1 parent af2cd6e commit adb32a0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/main/build-site.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,16 @@ function build() {
184184
.readFileSync(readmePath, 'utf8')
185185
// Uncomment docdown HTML hints.
186186
.replace(/(<)!--\s*|\s*--(>)/g, '$1$2')
187-
// Convert source and npm package links to anchors.
188-
.replace(/\[source\]\(([^)]+)\) \[npm package\]\(([^)]+)\)/g, (match, href1, href2) =>
189-
`<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(/(<h3[^>]*>.*?<\/h3>)\n\[source\]\(([^)]+)\) \[npm package\]\(([^)]+)\)/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(/(<h3[^>]*>.*?<\/h3>)\n\[source\]\(([^)]+)\)(?! \[npm package\])/g, (match, h3, href) =>
196+
`${h3}\n<p><a href="${ href }">source</a></p>`
190197
);
191198

192199
const $ = cheerio.load(marky(markdown, {

0 commit comments

Comments
 (0)