Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions patches/@tanstack__markdown@0.0.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/parser.js b/dist/parser.js
index 6616130a037737d109c527ec23ea8149ad8a68aa..1b4898b9ac1e749eeb136a5b8d13f8338a026b2b 100644
--- a/dist/parser.js
+++ b/dist/parser.js
@@ -334,7 +334,7 @@ function extractDefinitions(lines) {
footnotes[normalizeReferenceLabel(label)] = { label, content: content.join('\n') };
continue;
}
- const definition = line.match(/^ {0,3}\[([^\]\n]+)\]:[ \t]*(\S+)[ \t]*$/);
+ const definition = line.match(/^ {0,3}\[([^\]\n]+)\]:[ \t]*(\S+)(?:[ \t]+"[^"]*"|[ \t]+'[^']*'|[ \t]+\([^)]*\))?[ \t]*$/);
if (definition) {
references[normalizeReferenceLabel(definition[1])] = { href: definition[2].replace(/^<|>$/g, '') };
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
index++;
7 changes: 5 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ allowBuilds:

# Cloudflare Workers local runtime
workerd: true

patchedDependencies:
'@tanstack/markdown@0.0.5': patches/@tanstack__markdown@0.0.5.patch
43 changes: 43 additions & 0 deletions tests/markdown-link-reference-definitions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import assert from 'node:assert/strict'
import { parseSiteMarkdown } from '../src/utils/markdown'

const markdownCases = [
{
name: 'single-quoted title',
markdown: "[//]: # 'SomeLabel'\n\nVisible content.",
},
{
name: 'double-quoted title',
markdown: '[//]: # "SomeLabel"\n\nVisible content.',
},
{
name: 'parenthesized title',
markdown: '[//]: # (SomeLabel)\n\nVisible content.',
},
]

for (const testCase of markdownCases) {
const document = parseSiteMarkdown(testCase.markdown)

assert.equal(
document.children.length,
1,
`${testCase.name} reference definition is not rendered`,
)

const paragraph = document.children[0]

assert.equal(paragraph?.type, 'paragraph', `${testCase.name} content remains`)

if (paragraph?.type !== 'paragraph') {
throw new Error(`${testCase.name} did not produce a paragraph`)
}

assert.deepEqual(
paragraph.children,
[{ type: 'text', value: 'Visible content.' }],
`${testCase.name} visible paragraph is preserved`,
)
}

console.log('markdown link reference definition tests passed')