fix(frontmatter): Markdown links with an angle-bracket destination resolve (#2672)

This commit is contained in:
saberzero1 committed 2026-11-26 02:51:25 +01:00
1 parent 8417bdc03f
commit 71454c77b6
3 files changed
+22 -1

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Markdown links in frontmatter with an angle-bracket destination, which Obsidian writes for paths with spaces (`[Exec Briefing](<./Exec Briefing.md>)`), resolve to the note instead of a missing `….md` page, so the note gets the backlink and graph edge.
+11
View File
@@ -223,6 +223,17 @@ describe("frontmatter built-in", () => {
)
})
test("frontmatter Markdown links with an angle-bracket destination drop the brackets", () => {
assert.deepStrictEqual(
extractLinksFromValue([
"[Exec Briefing](<./Exec Briefing.md>)",
"[x](<./Exec Briefing.md#Next steps>)",
"[y](./Exec Briefing.md)",
]),
["./Exec Briefing.md", "./Exec Briefing.md#Next steps", "./Exec Briefing.md"],
)
})
test("reads YAML frontmatter with YAML 1.2's core schema, as Obsidian does", () => {
const data = readFrontmatterData(
"---\ntitle: Hello world\ndate: 2024-01-02\ndraft: True\nn: 012\nnone: ~\nratio: .5\nalias: yes\n---\n",
+6 -1
View File
@@ -75,7 +75,12 @@ export function extractLinksFromValue(value: unknown): string[] {
const links: string[] = []
for (const match of value.matchAll(WIKILINK_PATTERN))
links.push(slugifyWikilinkTarget(match[1]!))
for (const match of value.matchAll(MDLINK_PATTERN)) links.push(match[1]!)
for (const match of value.matchAll(MDLINK_PATTERN)) {
// `[x](<./My Note.md>)`: CommonMark's angle-bracket destination, which
// Obsidian writes for paths with spaces. The brackets aren't part of it.
const dest = match[1]!.trim()
links.push(dest.startsWith("<") && dest.endsWith(">") ? dest.slice(1, -1) : dest)
}
return links
}
if (Array.isArray(value)) return value.flatMap((item) => extractLinksFromValue(item))