Skip to content

Commit 4659f4b

Browse files
authored
fix: Fix markdown url links formatting (#2160)
The custom link handler was ignoring the link text (`node.children`) and only returning the URL. I have fixed this by adding a helper to extract the link text and returing the links as `[text](url)` correctly. ### Testing - npm run build - npx docusaurus serve Tested on following sites: - https://localhost:3000/platform/integrations/actors/integration-ready-actors.md - https://localhost:3000/platform/security.md - https://localhost:3000/platform/integrations.md <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Fixes markdown link serialization used by the LLMs export. > > - Adds `getNodeText` helper to recursively extract link text from nodes > - Updates `remarkStringify.handlers.link` in `docusaurus-plugin-llms-txt` config to output `[text](url)` using `title` or extracted text, falling back to raw URL > - Keeps existing internal URL normalization and skip logic intact > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 7afb909. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 8778c89 commit 4659f4b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

docusaurus.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const { collectSlugs } = require('./tools/utils/collectSlugs');
99
const { externalLinkProcessor, isInternal } = require('./tools/utils/externalLink');
1010
const { removeLlmButtons } = require('./tools/utils/removeLlmButtons');
1111

12+
/**
13+
* Helper to extract text from a node recursively.
14+
*/
15+
function getNodeText(node) {
16+
if (node.type === 'text' || node.type === 'code' || node.type === 'inlineCode') return node.value || '';
17+
if (node.children) return node.children.map(getNodeText).join('');
18+
return '';
19+
}
20+
1221
/** @type {Partial<import('@docusaurus/types').DocusaurusConfig>} */
1322
module.exports = {
1423
title: 'Apify Documentation',
@@ -301,7 +310,10 @@ module.exports = {
301310
const url = isUrlInternal ? `${config.absoluteUrl}${parsedUrl.pathname}.md` : node.url;
302311

303312
if (isUrlInternal && !parsedUrl.pathname) return '';
313+
304314
if (node.title) return `[${node.title}](${url})`;
315+
const linkText = getNodeText(node);
316+
if (linkText) return `[${linkText}](${url})`;
305317
return url;
306318
},
307319
code: (node) => {

0 commit comments

Comments
 (0)