mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-30 22:44:41 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60c8318b34 | ||
|
|
2ef60c6be5 | ||
|
|
8a62b70b1d | ||
|
|
22c18d1981 | ||
|
|
e5332d4491 | ||
|
|
9f9547eb2d | ||
|
|
986aa227a8 |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
Embedding a section by the anchor Obsidian writes for its heading works when that anchor differs from the heading's id: `![[note#Colon unspaced]]` now embeds `## Colon:unspaced`. It needs GitHubFlavoredMarkdown 2.1.0 or later, which marks those anchors on the heading.
|
||||
Generated
+13
-13
@@ -37,7 +37,7 @@
|
||||
"@quartz-community/graph": "^1.0.0",
|
||||
"@quartz-community/hard-line-breaks": "^1.0.0",
|
||||
"@quartz-community/latex": "^1.0.0",
|
||||
"@quartz-community/note-properties": "^1.0.0",
|
||||
"@quartz-community/note-properties": "^1.1.1",
|
||||
"@quartz-community/obsidian-flavored-markdown": "^2.0.0",
|
||||
"@quartz-community/og-image": "^1.0.0",
|
||||
"@quartz-community/ox-hugo": "^1.0.0",
|
||||
@@ -2892,9 +2892,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/note-properties": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/note-properties/-/note-properties-1.1.0.tgz",
|
||||
"integrity": "sha512-TYpEDTO9Im3zZBqKpsQHFbSABj/FPswPSBBhle9FSiNUQpIOSZk6lj6Yw3LHz2mpa01w3Cvag5MGtugYe+HYEQ==",
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/note-properties/-/note-properties-1.1.1.tgz",
|
||||
"integrity": "sha512-kURVT2PTQZTcRZxiT7o/gerI/8n0EhVogLaMznviJXYKSSvenE+8uKlPxJtZr1nbTJOn73UNBr5iNMhQIycQtg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@quartz-community/types": "^1.0.0",
|
||||
@@ -2918,9 +2918,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/obsidian-flavored-markdown": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.0.0.tgz",
|
||||
"integrity": "sha512-B8Q52yWmtvuNXpmRuNRHZSTgjAcdzT2N0eQiZhYfykUC6dQwMNs/mHIzxBK8T7A8xr3KjkGrtqzEM1s49dYjgw==",
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/obsidian-flavored-markdown/-/obsidian-flavored-markdown-2.1.0.tgz",
|
||||
"integrity": "sha512-yOLBsYrJ5IVjxhl/ppZmXQAHianKkeIGMvDT7mwNOaalsah19p9luHrPYg0eEsn1o6IkHFP8h1LaY2WT+wIABw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@quartz-community/rehype-obsidian": "^1.2.0",
|
||||
@@ -3296,9 +3296,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@quartz-community/types": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/types/-/types-1.1.0.tgz",
|
||||
"integrity": "sha512-FedvwWskypTuEd/ZNqV7o/HjSE+F9rQGpBxy35Ia/hUitUA92tJsoxOtX+OAOjsB0kEq679e60zCXoyoIq8QRA==",
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@quartz-community/types/-/types-1.2.0.tgz",
|
||||
"integrity": "sha512-82L+hallWn9LCMw9kFUWJhAGwlTd4rT2KxxL8B7IAWTEvj/20StWsuC01Mbfk5hLhd8jAHGgj1WHb0u/cdUXEA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"unified": "^11.0.5",
|
||||
@@ -7604,9 +7604,9 @@
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.22.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.22.1.tgz",
|
||||
"integrity": "sha512-oyL6OPYme/CmiFvNuGzeoxCJ4nOrZE2O1FwM9MWM1AsGri6nLXB2pg+lNA8aLeXMSav0J6eIVS1j6vUPzUtK9g==",
|
||||
"version": "8.22.2",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.22.2.tgz",
|
||||
"integrity": "sha512-/rEZ2ejown2N5gxVTHUu9bVVC7ttu0/Tgzf5hbTOixR3Fs7mbbXgn2DbdbcKgJOmpQMtrIUWivtYuVMnp/W/yA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@
|
||||
"@quartz-community/graph": "^1.0.0",
|
||||
"@quartz-community/hard-line-breaks": "^1.0.0",
|
||||
"@quartz-community/latex": "^1.0.0",
|
||||
"@quartz-community/note-properties": "^1.0.0",
|
||||
"@quartz-community/note-properties": "^1.1.1",
|
||||
"@quartz-community/obsidian-flavored-markdown": "^2.0.0",
|
||||
"@quartz-community/og-image": "^1.0.0",
|
||||
"@quartz-community/ox-hugo": "^1.0.0",
|
||||
|
||||
@@ -183,6 +183,46 @@ describe("renderTranscludes", () => {
|
||||
assert.ok(!secondText.includes("Circular transclusion"), "should not show circular warning")
|
||||
})
|
||||
|
||||
test("a header transclusion matches a heading's Obsidian-anchor alias", () => {
|
||||
const root: Root = {
|
||||
type: "root",
|
||||
children: [makeTranscludeBlockquote("target", "#colon-unspaced")],
|
||||
}
|
||||
const targetHtml: Root = {
|
||||
type: "root",
|
||||
children: [
|
||||
{
|
||||
type: "element",
|
||||
tagName: "h2",
|
||||
properties: { id: "colonunspaced" },
|
||||
children: [
|
||||
{
|
||||
type: "element",
|
||||
tagName: "span",
|
||||
properties: { id: "colon-unspaced", className: ["heading-alias"] },
|
||||
children: [],
|
||||
},
|
||||
{ type: "text", value: "Colon:unspaced" },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "element",
|
||||
tagName: "p",
|
||||
properties: {},
|
||||
children: [{ type: "text", value: "Section text" }],
|
||||
},
|
||||
],
|
||||
}
|
||||
renderTranscludes(
|
||||
root,
|
||||
cfg,
|
||||
"current" as FullSlug,
|
||||
makeComponentData([makePageData("target", targetHtml)]) as QuartzComponentProps,
|
||||
new Set<FullSlug>(["current" as FullSlug]),
|
||||
)
|
||||
assert.ok(JSON.stringify((root.children[0] as Element).children).includes("Section text"))
|
||||
})
|
||||
|
||||
test("detects actual circular transclusion (A -> B -> A)", () => {
|
||||
// Page A embeds B, and B's htmlAst contains a transclusion of A
|
||||
const bTranscludesA = makeTranscludeBlockquote("pageA")
|
||||
|
||||
@@ -31,6 +31,25 @@ interface RenderComponents {
|
||||
}
|
||||
|
||||
const headerRegex = new RegExp(/h[1-6]/)
|
||||
|
||||
/**
|
||||
* Whether a heading answers to `id`: its own id, or the id of a `span.heading-alias` inside it.
|
||||
* GitHubFlavoredMarkdown adds that alias when the anchor Obsidian writes for a heading (`:`, `|`,
|
||||
* `^`, `#` and `\` become spaces) slugs differently, e.g. `![[note#Colon unspaced]]` for
|
||||
* `## Colon:unspaced`.
|
||||
*/
|
||||
function headingHasId(heading: Element, id: string): boolean {
|
||||
if (heading.properties?.id === id) return true
|
||||
const hasAlias = (el: Element): boolean =>
|
||||
el.children.some(
|
||||
(child) =>
|
||||
child.type === "element" &&
|
||||
((child.properties?.id === id &&
|
||||
([] as unknown[]).concat(child.properties?.className ?? []).includes("heading-alias")) ||
|
||||
hasAlias(child)),
|
||||
)
|
||||
return hasAlias(heading)
|
||||
}
|
||||
export function pageResources(
|
||||
baseDir: FullSlug | RelativeURL,
|
||||
staticResources: StaticResources,
|
||||
@@ -231,7 +250,7 @@ export function renderTranscludes(
|
||||
const depth = Number(htmlEl.tagName.substring(1))
|
||||
|
||||
if (startIdx === undefined || startDepth === undefined) {
|
||||
if (htmlEl.properties?.id === blockRef) {
|
||||
if (headingHasId(htmlEl, blockRef)) {
|
||||
startIdx = i
|
||||
startDepth = depth
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user