feat(links): mark broken links by default, as Obsidian marks unresolved links

This commit is contained in:
saberzero1 committed 2026-11-24 23:43:56 +01:00
1 parent 2386362d57
commit 55311cb0bc
9 files changed
+24 -7

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": minor
---
Links: `disableBrokenWikilinks` is on by default. Internal links to pages that don't exist get the `broken` class, as Obsidian marks unresolved links (`is-unresolved`), so Quartz's and Obsidian themes' unresolved-link styles apply. Set `links.disableBrokenWikilinks: false` for the old behaviour.
+1 -1
View File
@@ -33,7 +33,7 @@ configuration:
openLinksInNewTab: false
lazyLoad: false
externalLinkIcon: true
disableBrokenWikilinks: false
disableBrokenWikilinks: true
drafts:
publish: false # true = publish drafts anyway (e.g. preview deployments)
contentIndex:
+1 -1
View File
@@ -32,7 +32,7 @@ Options:
- `openLinksInNewTab`: If `true`, configures external links to open in a new tab. Defaults to `false`.
- `lazyLoad`: If `true`, adds lazy loading to resource elements (`img`, `video`, etc.) to improve page load performance. Defaults to `false`.
- `externalLinkIcon`: Adds an icon next to external links when `true` (default) to visually distinguishing them from internal links.
- `disableBrokenWikilinks`: If `true`, internal links whose resolved slug is not present in the site (i.e. no matching file under `markdownLinkResolution`) gain an additional `broken` CSS class alongside `internal`, so they can be styled distinctly. Defaults to `false`. Applies to both wikilinks and regular Markdown links, since both are indistinguishable `<a>` elements by the time links are processed.
- `disableBrokenWikilinks`: If `true`, internal links whose resolved slug is not present in the site (i.e. no matching file under `markdownLinkResolution`) gain an additional `broken` CSS class alongside `internal`, so they can be styled distinctly. Defaults to `true`, as Obsidian marks unresolved links. Applies to both wikilinks and regular Markdown links, since both are indistinguishable `<a>` elements by the time links are processed.
- `enabled`: set to `false` to turn link processing off (not recommended — links break on nested pages and backlinks/graph are empty).
- `order`: position among transformers. Defaults to `60`, after the Markdown flavour plugins (e.g. [[ObsidianFlavoredMarkdown]] at `40`) that turn wikilinks into links.
+1 -1
View File
@@ -136,7 +136,7 @@ export interface LinksConfig extends BuiltinToggle {
lazyLoad?: boolean
/** Add an icon after external links. Default `true`. */
externalLinkIcon?: boolean
/** Add a `broken` class to internal links whose target does not exist. Default `false`. */
/** Add a `broken` class to internal links whose target does not exist, as Obsidian marks unresolved links. Default `true`. */
disableBrokenWikilinks?: boolean
}
+1 -1
View File
@@ -44,7 +44,7 @@ configuration:
textHighlight: "#b3aa0288"
links:
markdownLinkResolution: shortest
# disableBrokenWikilinks: false # Set true to add a "broken" CSS class to internal links whose target does not exist.
# disableBrokenWikilinks: true # Set false to stop adding a "broken" CSS class to internal links whose target does not exist.
contentIndex:
enableSiteMap: true
enableRSS: true
+1 -1
View File
@@ -44,7 +44,7 @@ configuration:
textHighlight: "#b3aa0288"
links:
markdownLinkResolution: shortest
# disableBrokenWikilinks: false # Set true to add a "broken" CSS class to internal links whose target does not exist.
# disableBrokenWikilinks: true # Set false to stop adding a "broken" CSS class to internal links whose target does not exist.
contentIndex:
enableSiteMap: true
enableRSS: true
+12
View File
@@ -342,6 +342,7 @@ describe("links built-in", () => {
[a("other/note", "Note"), a("https://example.com"), a("#heading")],
"folder/page",
{ markdownLinkResolution: "absolute" },
["folder/page", "other/note"],
)
const [internal, external] = els.filter((e) => e.tagName === "a")
assert.strictEqual(internal.properties.href, "../other/note")
@@ -435,6 +436,17 @@ describe("links built-in", () => {
)
})
test("missing targets get the broken class by default, as Obsidian marks them", () => {
const { els } = run([a("missing"), a("page")], "page", {}, ["page"])
assert.ok((els[0].properties.className as string[]).includes("broken"))
assert.ok(!(els[1].properties.className as string[]).includes("broken"))
})
test("disableBrokenWikilinks: false leaves missing targets unmarked", () => {
const { els } = run([a("missing")], "page", { disableBrokenWikilinks: false }, ["page"])
assert.ok(!(els[0].properties.className as string[]).includes("broken"))
})
test("disableBrokenWikilinks adds a broken class to missing targets", () => {
const { els } = run([a("missing")], "page", { disableBrokenWikilinks: true }, ["page"])
assert.ok((els[0].properties.className as string[]).includes("broken"))
+1 -1
View File
@@ -38,7 +38,7 @@ export const linksDefaults: Required<Omit<LinksConfig, "enabled" | "order">> = {
openLinksInNewTab: false,
lazyLoad: false,
externalLinkIcon: true,
disableBrokenWikilinks: false,
disableBrokenWikilinks: true,
}
/** Defaults of the former crawl-links plugin, applied when its config entry is migrated. */
+1 -1
View File
@@ -277,7 +277,7 @@
},
"disableBrokenWikilinks": {
"type": "boolean",
"description": "Add a `broken` class to internal links whose target does not exist. Default false."
"description": "Add a `broken` class to internal links whose target does not exist, as Obsidian marks unresolved links. Default true."
}
}
}