fix: footnote anchors stay internal without internal-link, like Obsidian

This commit is contained in:
saberzero1 committed 2026-11-23 13:41:21 +01:00
1 parent 2386362d57
commit cc253bea53
3 files changed
+30 -1

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Footnote references and back-links keep the `internal` class but no longer get `internal-link`: Obsidian doesn't treat them as note links, and Obsidian themes' link styles (underline, colour) overrode their footnote styles.
+15
View File
@@ -337,6 +337,21 @@ describe("links built-in", () => {
assert.deepStrictEqual(file.data.links?.sort(), ["folder/sibling", "t"])
})
test("footnote anchors stay internal without Obsidian's note-link class", () => {
const fn = (props: Record<string, unknown>): Element => ({
type: "element",
tagName: "a",
properties: { href: "#user-content-fn-1", ...props },
children: [{ type: "text", value: "1" }],
})
const { els } = run([fn({ dataFootnoteRef: "" }), fn({ dataFootnoteBackref: "" })])
for (const el of els.filter((e) => e.tagName === "a")) {
const classes = el.properties.className as string[]
assert.ok(classes.includes("internal"))
assert.ok(!classes.includes("internal-link"))
}
})
test("makes internal links relative, records outgoing links, marks external ones", () => {
const { els, file } = run(
[a("other/note", "Note"), a("https://example.com"), a("#heading")],
+10 -1
View File
@@ -114,8 +114,17 @@ export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
let dest = node.properties.href as RelativeURL
const classes = (node.properties.className ?? []) as string[]
const isExternal = isExternalUrl(dest)
// Footnote anchors aren't note links: Obsidian gives them `footnote-link`,
// never `internal-link`, whose link styles would override theirs.
const isFootnote =
node.properties.dataFootnoteRef !== undefined ||
node.properties.dataFootnoteBackref !== undefined
classes.push(
...(isExternal ? ["external", "external-link"] : ["internal", "internal-link"]),
...(isExternal
? ["external", "external-link"]
: isFootnote
? ["internal"]
: ["internal", "internal-link"]),
)
if (isExternal && opts.externalLinkIcon) {