mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-27 22:14:40 +01:00
fix(frontmatter): Markdown links with an angle-bracket destination resolve (#2672)
This commit is contained in:
3 files changed
+22
-1
No files matched your search
@@ -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.
|
||||
@@ -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",
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user