Merge pull request #2712 from jackyzha0/dev-mode/block-id-caret

fix: block anchors are #^id, separate from headings (as in Obsidian)
This commit is contained in:
Emile Bangma authored and GitHub committed 2026-11-27 00:44:05 +01:00
commit 29be20f41c
8 files changed
+97 -42

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Block anchors are `#^id`, as in Obsidian: `@quartz-community/utils` 1.3.2 and `@quartz-community/rehype-obsidian` 1.6.0, bundled by obsidian-flavored-markdown 2.5.3, github-flavored-markdown 2.2.2, canvas-page 1.1.4, note-properties 1.2.3 and bases-page 1.5.5, give blocks `id="^id"` and link to them as `#^id`. A block and a heading with the same name (`^para-1`, `## Para 1`) no longer share an id, so `[[#^para-1]]` and `[[#Para 1]]` each reach their own target. canvas-page also scopes the ids of text nodes rendered with `textNodeMarkdown: basic`.
+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
Block anchors are `#^id`: with @quartz-community/utils 1.3.2 and rehype-obsidian 1.6.0, blocks get the id `^id` and links to them `#^id` (was `#id`), as in Obsidian, so block `^para-1` and heading `## Para 1` no longer share an id. A block transclusion finds its block whatever the case of its `^id` (`![[note#^Para-1]]`), and the popover scrolls to a block it links to.
+2 -1
View File
@@ -65,5 +65,6 @@ Heading ids follow the GitHub rule (`github-slugger`, as `rehype-slug` and the t
- `slugHeading(text)`: the id of a heading with this text;
- `HeadingSlugger`: slugs all headings of one page in order and numbers repeats (`foo`, `foo-1`, …) — create one per page;
- `obsidianHeadingAnchor(text)`: the anchor Obsidian writes for a heading (it replaces `:`, `|`, `^`, `#` and `\` with spaces); slug it with `slugHeading` and add it as an extra id when it differs;
- `resolveAnchorHref(href, ids)`: points a same-page `#anchor` at an id that exists on the page (an id as written, a block reference `#^name`, or a heading's text);
- `resolveAnchorHref(href, ids)`: points a same-page `#anchor` at an id that exists on the page (an id as written, or a heading's text); a block reference `#^name` always points at the block (`#^name`), never at a heading;
- `blockAnchor(name)`: the anchor of the block `^name`, `#^name` (lowercased). Blocks have the id `^name`, so they never share an id with a heading;
- `slugTag(tag)`: the slug of a tag, as used for tag pages.
+1
View File
@@ -39,6 +39,7 @@ npx quartz plugin install --latest
### Changes you may notice
- **Block anchors**: a block's id is now `^id` and links to it are `#^id` (`[[note#^para-1]]` → `note#^para-1`, was `note#para-1`), as in Obsidian, where blocks and headings are separate namespaces: block `^para-1` and heading `## Para 1` no longer share an id, so `[[#^para-1]]` and `[[#Para 1]]` each land on their own target. Links inside the site are regenerated; old `#id` URLs of blocks from outside the site now go to the top of the page (or to a heading of that name). CSS or scripts that select a block by id need `#\^para-1` (or `getElementById`).
- **Unresolved links**: `configuration.links.disableBrokenWikilinks` is now on by default. Links to pages that don't exist get the `broken` class and are styled as unresolved, as in Obsidian. Links to pages a filter removes (drafts, unpublished notes) are marked the same way, with `data-filtered="<filter>"`. Set `links.disableBrokenWikilinks: false` to style them as before.
- **Mermaid diagrams** render with [Pele](https://pele.run) by default, as in Obsidian, inside a `<div class="mermaid">` rather than a code block. Set `diagramRenderer: mermaid` on [[ObsidianFlavoredMarkdown]] to keep Mermaid.js. See [[Mermaid diagrams]].
- **Block wrappers**: each top-level block of a note is wrapped in the `div` Obsidian puts it in (`div.el-p > p`, `div.el-h2 > h2`). Custom CSS that selects a page's blocks as direct children (`article > p`) no longer matches. Select them without `>`, or set `blockWrappers: false` on ObsidianFlavoredMarkdown.
+33 -33
View File
@@ -16,9 +16,9 @@
"@quartz-community/alias-redirects": "^1.0.3",
"@quartz-community/article-title": "^1.0.2",
"@quartz-community/backlinks": "^1.0.4",
"@quartz-community/bases-page": "^1.5.4",
"@quartz-community/bases-page": "^1.5.5",
"@quartz-community/breadcrumbs": "^1.0.5",
"@quartz-community/canvas-page": "^1.1.2",
"@quartz-community/canvas-page": "^1.1.4",
"@quartz-community/citations": "^1.0.1",
"@quartz-community/cname": "^1.0.1",
"@quartz-community/comments": "^1.0.2",
@@ -33,12 +33,12 @@
"@quartz-community/favicon": "^1.0.1",
"@quartz-community/folder-page": "^1.1.3",
"@quartz-community/footer": "^1.1.2",
"@quartz-community/github-flavored-markdown": "^2.2.1",
"@quartz-community/github-flavored-markdown": "^2.2.2",
"@quartz-community/graph": "^1.0.8",
"@quartz-community/hard-line-breaks": "^1.1.0",
"@quartz-community/latex": "^1.1.2",
"@quartz-community/note-properties": "^1.2.2",
"@quartz-community/obsidian-flavored-markdown": "^2.5.2",
"@quartz-community/note-properties": "^1.2.3",
"@quartz-community/obsidian-flavored-markdown": "^2.5.3",
"@quartz-community/og-image": "^1.1.3",
"@quartz-community/ox-hugo": "^1.0.3",
"@quartz-community/page-title": "^1.0.2",
@@ -97,7 +97,7 @@
"devDependencies": {
"@changesets/cli": "^3.0.3",
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.3.1",
"@quartz-community/utils": "^1.3.2",
"@types/hast": "^3.0.4",
"@types/node": "^26.5.1",
"@types/pretty-time": "^1.1.5",
@@ -2330,14 +2330,14 @@
}
},
"node_modules/@quartz-community/bases-page": {
"version": "1.5.4",
"resolved": "https://registry.npmjs.org/@quartz-community/bases-page/-/bases-page-1.5.4.tgz",
"integrity": "sha512-WDUQ/FGMz3ynQbHCt/SCn6nAbEfkvK/isfxqKHbfQTl1e1eSBc4AImux9wtJSLpnCriwV9w7ChZpLidDRigk6Q==",
"version": "1.5.5",
"resolved": "https://registry.npmjs.org/@quartz-community/bases-page/-/bases-page-1.5.5.tgz",
"integrity": "sha512-aUJgKt3KjP2UOT4sfeHugkwMyptqXpkRBrHiOthyEND2NI43kZUTNQ2FicTZQLDMLOSnuUu4PXgHv0NF4Ntyrw==",
"license": "MIT",
"dependencies": {
"@lucide/icons": "^1.70.0",
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.3.1"
"@quartz-community/utils": "^1.3.2"
},
"engines": {
"node": ">=22",
@@ -2383,13 +2383,13 @@
}
},
"node_modules/@quartz-community/canvas-page": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@quartz-community/canvas-page/-/canvas-page-1.1.2.tgz",
"integrity": "sha512-dAsTC/cGVdMQqxF+hJxppln3nNDjLOY9FxGszTBOWSFoyylciaoCKiqpdfJcgeVtI4JNUvFZ/kofaWcpW7FDkA==",
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/@quartz-community/canvas-page/-/canvas-page-1.1.4.tgz",
"integrity": "sha512-HNvwpnIbv887epOKTKcr1fMV9cSN6JjQw7mxNSiBJSSe9dtYUu4F7FPIFE33JFSWOpilDgV6f+ApnYVQ1c9yaA==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.3.1"
"@quartz-community/utils": "^1.3.2"
},
"engines": {
"node": ">=22",
@@ -2712,13 +2712,13 @@
}
},
"node_modules/@quartz-community/github-flavored-markdown": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@quartz-community/github-flavored-markdown/-/github-flavored-markdown-2.2.1.tgz",
"integrity": "sha512-i1FwY8AY7d78TOs665XGgeGRZT2EefUZ8hZu35E0sNFiX09VrnSzGz0NmnamFYBMkmEc55R3N6gNtoqLVMr2Kw==",
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/@quartz-community/github-flavored-markdown/-/github-flavored-markdown-2.2.2.tgz",
"integrity": "sha512-JsSeydLs05VZj2jc2KT/5vse+zNGCDH92Ih8/yp5s6EUY+wwOmzSTPxT65Ey0LK/X/nclfkMu4S4Domd2RkwmA==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.1.1"
"@quartz-community/utils": "^1.3.2"
},
"engines": {
"node": ">=22",
@@ -2802,13 +2802,13 @@
}
},
"node_modules/@quartz-community/note-properties": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@quartz-community/note-properties/-/note-properties-1.2.2.tgz",
"integrity": "sha512-qyrNdL+Yveb1/mdN23B0yACvuDMDKPsPhTvATisaN4h0dNS/4i/Nu6J6W1wbcN3t1tKhE7cdNWMYpabay+l42g==",
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@quartz-community/note-properties/-/note-properties-1.2.3.tgz",
"integrity": "sha512-udQ8hWrkX9V1tcrxyxRniE8QkFXHAp1AFYjhZ9ZcRFNdSxgyu7Q18vHRl65jrW7MKoApN6VB3dOjUwiM1hn88A==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0",
"@quartz-community/utils": "^1.3.1"
"@quartz-community/utils": "^1.3.2"
},
"engines": {
"node": ">=22",
@@ -2828,15 +2828,15 @@
}
},
"node_modules/@quartz-community/obsidian-flavored-markdown": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.5.2.tgz",
"integrity": "sha512-t30nSwmEVLvIw4LnOp+iAe3ZcJNy2Bew+luAL425Ek/XM6udXkIzaafEhjXQXTN34k8/6rjvat1w2HGepdv/nw==",
"version": "2.5.3",
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.5.3.tgz",
"integrity": "sha512-nevXFettUGuQemzqcXkDiUjKLeUKQ36RkITQx36G56gAB1TkrHv03gP4iX9EVXHi/9ZCSlgDdyHIkDRgP0lL4Q==",
"license": "MIT",
"dependencies": {
"@quartz-community/rehype-obsidian": "^1.5.1",
"@quartz-community/rehype-obsidian": "^1.6.0",
"@quartz-community/remark-obsidian": "^2.2.4",
"@quartz-community/types": "^1.1.0",
"@quartz-community/utils": "^1.3.1",
"@quartz-community/utils": "^1.3.2",
"pele": "^1.13.0"
},
"engines": {
@@ -2970,9 +2970,9 @@
}
},
"node_modules/@quartz-community/rehype-obsidian": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/@quartz-community/rehype-obsidian/-/rehype-obsidian-1.5.1.tgz",
"integrity": "sha512-PvU1JCyAndgbkjPeFaPs1r/FnijtTFTDetn9F8mUBRGB9zEDEGIHqpo+/LZvQQUP46eCbRUXkz2RVc72g0V/UQ==",
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/@quartz-community/rehype-obsidian/-/rehype-obsidian-1.6.0.tgz",
"integrity": "sha512-7NyJNKr515xtCBBhzLr4UdoENutGPgAJhh3GA0S3j6Qj2r7v+hFNSq4yd3gtFP0GK7b4PPfOtTTyAWCC8BYiig==",
"license": "MIT",
"engines": {
"node": ">=22"
@@ -3230,9 +3230,9 @@
}
},
"node_modules/@quartz-community/utils": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.3.1.tgz",
"integrity": "sha512-HGlcmwzt+nzu77sVfERtGFgw9CqO0/sApDX4RBM4pJZOxBDFKOL+5aKOw3TlHUW+57GJeDO1QM464foXbp+VWQ==",
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/@quartz-community/utils/-/utils-1.3.2.tgz",
"integrity": "sha512-50SiiB1HY2zdpjO7SUJklITcFqH/sJNq6PE1a8dtc8HIvQfPW4kXALoiPUqvaYzcBVscnkZ9rfmlSgn/vaA4eA==",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "^1.0.0"
+6 -6
View File
@@ -46,9 +46,9 @@
"@quartz-community/alias-redirects": "^1.0.3",
"@quartz-community/article-title": "^1.0.2",
"@quartz-community/backlinks": "^1.0.4",
"@quartz-community/bases-page": "^1.5.4",
"@quartz-community/bases-page": "^1.5.5",
"@quartz-community/breadcrumbs": "^1.0.5",
"@quartz-community/canvas-page": "^1.1.2",
"@quartz-community/canvas-page": "^1.1.4",
"@quartz-community/citations": "^1.0.1",
"@quartz-community/cname": "^1.0.1",
"@quartz-community/comments": "^1.0.2",
@@ -63,12 +63,12 @@
"@quartz-community/favicon": "^1.0.1",
"@quartz-community/folder-page": "^1.1.3",
"@quartz-community/footer": "^1.1.2",
"@quartz-community/github-flavored-markdown": "^2.2.1",
"@quartz-community/github-flavored-markdown": "^2.2.2",
"@quartz-community/graph": "^1.0.8",
"@quartz-community/hard-line-breaks": "^1.1.0",
"@quartz-community/latex": "^1.1.2",
"@quartz-community/note-properties": "^1.2.2",
"@quartz-community/obsidian-flavored-markdown": "^2.5.2",
"@quartz-community/note-properties": "^1.2.3",
"@quartz-community/obsidian-flavored-markdown": "^2.5.3",
"@quartz-community/og-image": "^1.1.3",
"@quartz-community/ox-hugo": "^1.0.3",
"@quartz-community/page-title": "^1.0.2",
@@ -124,7 +124,7 @@
"devDependencies": {
"@changesets/cli": "^3.0.3",
"@quartz-community/types": "^1.3.1",
"@quartz-community/utils": "^1.3.1",
"@quartz-community/utils": "^1.3.2",
"@types/hast": "^3.0.4",
"@types/node": "^26.5.1",
"@types/pretty-time": "^1.1.5",
+42
View File
@@ -120,6 +120,48 @@ describe("renderTranscludes", () => {
assert.ok(texts.includes("Target content"), "transcluded content should be inlined")
})
test("a block transclusion finds the block by its name and scopes its ^id", () => {
const block: Element = {
type: "element",
tagName: "p",
properties: { id: "^para-1" },
children: [
{ type: "text", value: "Block text " },
{
type: "element",
tagName: "a",
properties: { href: "#^para-1" },
children: [{ type: "text", value: "self" }],
},
],
}
const heading: Element = {
type: "element",
tagName: "h2",
properties: { id: "para-1" },
children: [{ type: "text", value: "Para 1" }],
}
const targetHtml: Root = { type: "root", children: [heading, block] }
const allFiles = [makePageData("target", targetHtml, { blocks: { "para-1": block } })]
const root: Root = {
type: "root",
children: [makeTranscludeBlockquote("target", "#^Para-1")],
}
renderTranscludes(
root,
cfg,
"current" as FullSlug,
makeComponentData(allFiles) as QuartzComponentProps,
new Set<FullSlug>(["current" as FullSlug]),
)
const html = toHtml(root)
assert.ok(html.includes("Block text"), html)
assert.ok(!html.includes("Para 1"), "the heading of the same name isn't transcluded")
const id = /<p id="([^"]+)"/.exec(html)?.[1]
assert.ok(id?.endsWith("^para-1") && id !== "^para-1", `scoped block id, got ${id}`)
assert.ok(html.includes(`href="#${id}"`), "the link inside points at the scoped id")
})
test("allows the same page to be embedded twice as siblings", () => {
const root: Root = {
type: "root",
+3 -2
View File
@@ -308,8 +308,9 @@ export function renderTranscludes(
let blockRef = el.properties.dataBlock as string | undefined
if (blockRef?.startsWith("#^")) {
// block transclude
blockRef = blockRef.slice("#^".length)
// block transclude: `data.blocks` is keyed by the block's name, lowercased (`para-1`); the
// block element's id is `^para-1` (rehype-obsidian), its anchor `#^para-1`
blockRef = blockRef.slice("#^".length).toLowerCase()
let blockNode = page.blocks?.[blockRef]
if (blockNode) {
if (blockNode.tagName === "li") {