mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-27 22:14:40 +01:00
fix: footnote anchors stay internal without internal-link, like Obsidian
This commit is contained in:
3 files changed
+30
-1
No files matched your search
@@ -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.
|
||||
@@ -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")],
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user