Compare commits

...
6 changed files with 83 additions and 22 deletions

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
---
"@jackyzha0/quartz": patch
---
Links as in Obsidian 1.15.0:
- A Markdown link whose path is not valid percent-encoding (`[x](%zz)`, `[x](a%E2.md)`) is an external link. Before, it failed the whole build with `URI malformed`.
- Link paths are NFC-normalized, so a link spelled with a decomposed `é` reaches `café.md`.
- An image of a file the site doesn't have, with no alt text, gets its percent-decoded path as alt (`![](missing%20pic.png)` → “missing pic.png”), as Obsidian names a missing embed.
- A wikilink's `^id` no longer names its paragraph (Obsidian Flavored Markdown).
+17 -17
View File
@@ -38,7 +38,7 @@
"@quartz-community/hard-line-breaks": "^1.1.0",
"@quartz-community/latex": "^1.0.1",
"@quartz-community/note-properties": "^1.1.4",
"@quartz-community/obsidian-flavored-markdown": "^2.1.2",
"@quartz-community/obsidian-flavored-markdown": "^2.1.3",
"@quartz-community/og-image": "^1.1.1",
"@quartz-community/ox-hugo": "^1.0.1",
"@quartz-community/page-title": "^1.0.2",
@@ -98,7 +98,7 @@
"devDependencies": {
"@changesets/cli": "^2.29.2",
"@quartz-community/types": "^1.3.0",
"@quartz-community/utils": "^1.1.1",
"@quartz-community/utils": "^1.2.0",
"@types/hast": "^3.0.4",
"@types/js-yaml": "^4.0.9",
"@types/node": "^26.5.1",
@@ -2917,15 +2917,15 @@
}
},
"node_modules/@quartz-community/obsidian-flavored-markdown": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.1.2.tgz",
"integrity": "sha512-aayc91CLyI2nwq0vs4i+7Q8723QuVjADk/EaQlg47GEM3MuRS5RcgEC+NBCeA59/JnJyqqmLHTC1ZITQ9L+Yww==",
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.1.3.tgz",
"integrity": "sha512-p5fls4M7ocUKrlF8MmfrlnNPEvBFZ5diVNVVkLsgTwCvzf19MrnczeKb3Q2yI2S1G2Xb0rXsq8kmF8faj+Q79A==",
"license": "MIT",
"dependencies": {
"@quartz-community/rehype-obsidian": "^1.2.0",
"@quartz-community/remark-obsidian": "^2.2.0",
"@quartz-community/rehype-obsidian": "^1.3.0",
"@quartz-community/remark-obsidian": "^2.2.1",
"@quartz-community/types": "^1.1.0",
"@quartz-community/utils": "^1.1.0",
"@quartz-community/utils": "^1.2.0",
"pele": "^1.13.0"
},
"engines": {
@@ -3089,18 +3089,18 @@
}
},
"node_modules/@quartz-community/rehype-obsidian": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@quartz-community/rehype-obsidian/-/rehype-obsidian-1.2.1.tgz",
"integrity": "sha512-wuxPcG5ie4J7x7KMfOZMDSgyNKFJf6x6I+I6H4XaZ4WX4sPlEfMUDTvxBoHRHpstqfCRX5Hy73d/K9/rYAZdnw==",
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/@quartz-community/rehype-obsidian/-/rehype-obsidian-1.3.0.tgz",
"integrity": "sha512-62YFEr3NR/Z2G/wcq30/VVKTlT4RUKezWfwGTQkNC+9mAXcUb3gAwjgiUJwylXZQyZmBf+SZsCNmdhIb7CPh/g==",
"license": "MIT",
"engines": {
"node": ">=22"
}
},
"node_modules/@quartz-community/remark-obsidian": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@quartz-community/remark-obsidian/-/remark-obsidian-2.2.0.tgz",
"integrity": "sha512-uSuUA3CA2ebAls7IXaevgQGqqbho1fR0lORKUTmhOTEUTYt8GBkl7ipaik4Y7x3q1LzUflejgFIGl/0XO83OGw==",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@quartz-community/remark-obsidian/-/remark-obsidian-2.2.1.tgz",
"integrity": "sha512-Q18F/Px8db8Evf6uwPKz0RMhZNyrsH2Okzhr6FWcsm51fYgJR+SiO98/2fmXQ3wnqV2eeJC7ZMzi81SDjK8vrg==",
"license": "MIT",
"engines": {
"node": ">=22"
@@ -3342,9 +3342,9 @@
}
},
"node_modules/@quartz-community/utils": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.1.1.tgz",
"integrity": "sha512-iHjEOlbpqznut9YkoflXxd2Bl5TaBcMFwIouRxp2HTBcbCQbmHtAsL3sdLheC1YeM9bMxeFLAN2b7rIBR2r/og==",
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.2.0.tgz",
"integrity": "sha512-X32uBfhfNACQw2Ciw6F0XQ9qSoTMQeh78/2ZEj8cYuOk7VTowNf0dpjtSDKAxs1co6aSpIEcDZBIG6p953UPiQ==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0"
+2 -2
View File
@@ -68,7 +68,7 @@
"@quartz-community/hard-line-breaks": "^1.1.0",
"@quartz-community/latex": "^1.0.1",
"@quartz-community/note-properties": "^1.1.4",
"@quartz-community/obsidian-flavored-markdown": "^2.1.2",
"@quartz-community/obsidian-flavored-markdown": "^2.1.3",
"@quartz-community/og-image": "^1.1.1",
"@quartz-community/ox-hugo": "^1.0.1",
"@quartz-community/page-title": "^1.0.2",
@@ -125,7 +125,7 @@
"devDependencies": {
"@changesets/cli": "^2.29.2",
"@quartz-community/types": "^1.3.0",
"@quartz-community/utils": "^1.1.1",
"@quartz-community/utils": "^1.2.0",
"@types/hast": "^3.0.4",
"@types/js-yaml": "^4.0.9",
"@types/node": "^26.5.1",
+35
View File
@@ -361,6 +361,41 @@ describe("links built-in", () => {
assert.strictEqual(els[1].properties.src, "../../media/a.mp4")
})
// Obsidian 1.15.0 (remark-obsidian 2.2.1's triage, re-probed): a path that is not valid
// percent-encoding names no file, so the link is external; `x:y` has a scheme, `../x:y` doesn't
test("links Obsidian reads as external", () => {
const { els } = run([a("%zz"), a("a%E2.md"), a("x:y"), a("../x:y")], "sub/note", {}, ["xy"])
const classes = els.filter((e) => e.tagName === "a").map((e) => e.properties.className)
assert.deepStrictEqual(
classes.map((c) => (c as string[])[0]),
["external", "external", "external", "internal"],
)
})
test("an image of a missing file without alt text shows its decoded path", () => {
const img = (src: string, alt?: string): Element => ({
type: "element",
tagName: "img",
properties: alt === undefined ? { src } : { src, alt },
children: [],
})
const { els } = run(
[
img("missing%20pic.png"),
img("missing%20image.png", "alt"),
img("pic.png"),
img("/static/x.png"),
],
"page",
{ markdownLinkResolution: "absolute" },
["page", "pic.png"],
)
assert.deepStrictEqual(
els.map((e) => e.properties.alt),
["missing pic.png", "alt", undefined, undefined],
)
})
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"))
+18 -3
View File
@@ -8,6 +8,7 @@ import { LinksConfig } from "../../cfg"
import {
FullSlug,
RelativeURL,
linkPathDecodes,
SimpleSlug,
TransformOptions,
resolveRelative,
@@ -46,7 +47,9 @@ export const legacyCrawlLinksDefaults: Partial<LinksConfig> = {
}
const isAbsolute = isAbsoluteUrl as (url: string, options?: { httpOnly?: boolean }) => boolean
const isExternalUrl = (url: string) => isAbsolute(url, { httpOnly: false })
// As in Obsidian: a URL with a scheme (`x:y`, but not `../x:y`), or a link whose path is not valid
// percent-encoding (`%zz`, `a%E2.md`), which names no file
const isExternalUrl = (url: string) => isAbsolute(url, { httpOnly: false }) || !linkPathDecodes(url)
const EXTERNAL_ICON_PATH =
"M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z"
@@ -175,8 +178,20 @@ export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
typeof node.properties.src === "string"
) {
if (opts.lazyLoad) node.properties.loading = "lazy"
if (!isExternalUrl(node.properties.src)) {
node.properties.src = resolveLink(node.properties.src as RelativeURL)
const src = node.properties.src
if (!isExternalUrl(src)) {
node.properties.src = resolveLink(src as RelativeURL)
// An embed of a file the site doesn't have: Obsidian shows its path, percent-decoded
// (`![](missing%20pic.png)` → “missing pic.png”). The image shows its alt text, so
// an image without one gets the path; an author's alt text is kept.
const target =
node.tagName === "img" && !node.properties.alt && !src.startsWith("#")
? canonicalSlug(node.properties.src as string, curSlug)
: undefined
// (quartz/static is served at static/ but holds no content files)
if (target && !target.startsWith("static/") && !ctx.allSlugs.includes(target)) {
node.properties.alt = decodeURI(splitAnchor(src)[0])
}
}
}
+1
View File
@@ -20,6 +20,7 @@ export {
splitAnchor,
slugTag,
transformInternalLink,
linkPathDecodes,
transformLink,
normalizeHastElement,
} from "@quartz-community/utils"