Skip to content

Commit 6ccdd1b

Browse files
committed
Quartz sync: May 22, 2025, 4:35 PM
1 parent 2a06fad commit 6ccdd1b

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

quartz/components/MarkmapViewer.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import markmapScript from "./scripts/markmap.inline"
33
import style from "./styles/markmap.scss"
44
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
55
import { classNames } from "../util/lang"
6+
import { FullSlug } from "../util/path"
67

78
import { IPureNode } from 'markmap-common'
89

@@ -28,18 +29,26 @@ function replaceMatches(str: string, regex: RegExp, replacer: (match: RegExpExec
2829
return accumulator
2930
}
3031

31-
const wikilinkRegex = /\[\[(?<link>[^|\]]+)\|?((?<displayText>[^\]]+))?\]\]/g
32+
const wikilinkRegex = /(!)?\[\[(?<link>[^|\]]+)\|?(?<displayText>[^\]]*)\]\]/g
33+
function replacement(currentPath: FullSlug) {
34+
return (match: RegExpExecArray) => {
35+
const { link, displayText } = match.groups!
36+
const isImage = /\.(png|jpg|jpeg|gif|svg)$/.test(link)
3237

33-
function replacement(match) {
34-
const { link, displayText } = match.groups!
35-
const safeLink = `quartz-${link.trim().replace(/\s+/g, "-")}`
36-
return `<a href=\"/${safeLink}\">${displayText || link}</a>`
38+
if (isImage) {
39+
return `<img src="../../../${currentPath}/../attachments/${link}" alt="${displayText || link}" />`
40+
}
41+
42+
const safeLink = `quartz-${link.trim().replace(/\s+/g, "-")}`
43+
return `<a href="/${safeLink}">${displayText || link}</a>`
44+
}
3745
}
3846

39-
export const parseInternalLinks = recurseChildren(node => {
40-
node.content =
41-
replaceMatches(node.content, wikilinkRegex, replacement)
42-
})
47+
export const parseInternalLinks = (slug: FullSlug) =>
48+
recurseChildren((node) => {
49+
node.content =
50+
replaceMatches(node.content, wikilinkRegex, replacement(slug))
51+
})
4352

4453

4554
const MarkmapViewer: QuartzComponent = ({ displayClass, fileData }: QuartzComponentProps) => {
@@ -70,7 +79,7 @@ const MarkmapViewer: QuartzComponent = ({ displayClass, fileData }: QuartzCompon
7079
)
7180
}
7281

73-
parseInternalLinks(root)
82+
parseInternalLinks(fileData.slug!)(root)
7483

7584
return (
7685
<div class={classNames(displayClass, "markmap")}>
@@ -98,7 +107,12 @@ const MarkmapViewer: QuartzComponent = ({ displayClass, fileData }: QuartzCompon
98107
data-markmap={encodeURIComponent(JSON.stringify(fileData.markmap))}
99108
>
100109
<div class="global-markmap-container" >
101-
<svg id="global-markmap" ></svg>
110+
<svg
111+
id="global-markmap"
112+
xmlns="http://www.w3.org/2000/svg"
113+
width="1240px"
114+
height="1240px"
115+
></svg>
102116
<div id="global-markmap-toolbar"></div>
103117
</div>
104118
</div>

quartz/components/scripts/markmap.inline.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { Markmap, deriveOptions } from "markmap-view"
1+
import { Markmap, deriveOptions, loadCSS } from "markmap-view"
2+
import { Transformer } from "markmap-lib"
23
import { Toolbar } from "markmap-toolbar"
34
import { registerEscapeHandler } from "./util"
45

5-
66
function renderGlobalMarkmap() {
7+
const transformer = new Transformer()
8+
const { styles } = transformer.getAssets();
9+
if (styles)
10+
loadCSS(styles)
11+
712
const jsonOptions = {
813
colorFreezeLevel: 2,
14+
spacingHorizontal: 100,
15+
spacingVertical: 10,
916
}
1017
const markmapOptions = deriveOptions(jsonOptions);
1118
markmapOptions.scrollForPan = false
@@ -33,7 +40,6 @@ function renderGlobalMarkmap() {
3340
toolbarEl.append(toolbar.render())
3441

3542
mm.fit()
36-
3743
container.classList.add("active")
3844

3945
registerEscapeHandler(container, hideGlobalMarkmap)

quartz/components/styles/markmap.scss

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
background-color: var(--light);
2222
border-radius: 5px;
2323
box-sizing: border-box;
24+
position: fixed;
2425
top: 50%;
2526
left: 50%;
2627
transform: translate(-50%, -50%);
2728
height: 80vh;
2829
width: 80vw;
29-
overflow: hidden;
30-
position: relative;
3130

3231
@media all and not ($desktop) {
3332
width: 90%;
@@ -38,10 +37,17 @@
3837
width: 100%;
3938
height: 100%;
4039
z-index: 0;
41-
overflow: hidden;
4240
color: var(--darkgray);
4341

44-
.language-frontmatter {}
42+
code {
43+
border-radius: 5px;
44+
padding: 0.12em;
45+
}
46+
47+
img {
48+
margin-top: 1em;
49+
margin-bottom: 0;
50+
}
4551
}
4652

4753
#global-markmap-toolbar {
@@ -51,7 +57,7 @@
5157
right: 0;
5258
width: 100%;
5359
z-index: 10;
54-
color: var(--darkgray);
60+
color: var(--italic);
5561

5662
.mm-toolbar-brand {
5763
display: none;

0 commit comments

Comments
 (0)