From 88a2cd60930108b28dc57c8dd7fac75994a3f7d8 Mon Sep 17 00:00:00 2001 From: kevin9327 <5299031+kevin9327@users.noreply.github.com> Date: Mon, 28 Sep 2026 20:11:07 +0900 Subject: [PATCH] Keep a link list whose title holds a bracketed word drizzle's llms.txt names a page `- [Joins [SQL]](.../pg/joins)`. The link list pattern read the title up to its first `]`, so that line did not match, and a paragraph with any line that is not a link stays verbatim: the section around it lost every link. On the live file that is 82 of its 454 entries, in the seven sections that list a Joins page. The title may now hold one level of bracketed text, which Markdown allows when the brackets pair up. A title whose brackets do not pair still does not match, so such a paragraph stays verbatim as before. Co-Authored-By: Claude Opus 5.5 --- src/distill.js | 5 +++-- tests/text.test.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/distill.js b/src/distill.js index 1eaa2a3..b19c0be 100644 --- a/src/distill.js +++ b/src/distill.js @@ -131,8 +131,9 @@ const pathOf = (url) => { }; // One line of a Markdown link list: `- [title](url)`, then an optional -// description. llms.txt is made of these. -const LINK_ITEM = /^[ \t]*[-*+][ \t]+\[([^\]\n]+)\]\(([^()\s]+)\)(.*)$/; +// description. llms.txt is made of these. A title may hold a bracketed +// word of its own, as Markdown allows: drizzle's reads `[Joins [SQL]]`. +const LINK_ITEM = /^[ \t]*[-*+][ \t]+\[((?:[^[\]\n]|\[[^[\]\n]*\])+)\]\(([^()\s]+)\)(.*)$/; /** * A paragraph that is nothing but a Markdown link list, as a list of real diff --git a/tests/text.test.js b/tests/text.test.js index 3799bfa..117ac04 100644 --- a/tests/text.test.js +++ b/tests/text.test.js @@ -97,3 +97,22 @@ test('a Markdown link list is a list of links to follow, as llms.txt needs', () assert.ok(lines.includes('- [Script](javascript:alert(1))')); assert.equal(toMarkdown(LLMS, 'https://svelte.dev/llms.txt'), LLMS.trimEnd(), 'raw rewrote the file'); }); + +test('a link title holding a bracketed word keeps its list of links', () => { + // drizzle's llms.txt names a page `[Joins [SQL]]`. The title stopped at + // the first `]`, the line did not match, and the whole section around it + // fell back to verbatim text with none of its links followable. + const text = '## PostgreSQL\n\n' + + '- [Select](https://orm.drizzle.team/docs/pg/select): Select rows.\n' + + '- [Joins [SQL]](https://orm.drizzle.team/docs/pg/joins): Join tables.\n' + + '- [Insert](https://orm.drizzle.team/docs/pg/insert)\n'; + const page = distill(text, 'https://orm.drizzle.team/llms.txt'); + assert.deepEqual(page.blocks.filter((b) => b.href).map((b) => [b.text, b.href]), [ + ['Select', 'https://orm.drizzle.team/docs/pg/select'], + ['Joins [SQL]', 'https://orm.drizzle.team/docs/pg/joins'], + ['Insert', 'https://orm.drizzle.team/docs/pg/insert'], + ]); + // Brackets that do not pair up are still not a title. + const loose = distill('- [a ] b](https://example.com/a)\n- [c](https://example.com/c)\n', 'https://example.com/llms.txt'); + assert.equal(loose.blocks.filter((b) => b.href).length, 0); +});