Skip to content

Commit 30dad4d

Browse files
committed
fix: update to markmap v0.18
1 parent 512bf91 commit 30dad4d

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ plugins:
7373
encoding: utf-8
7474
file_extension: .mm.md
7575
d3_version: 7
76-
lib_version: 0.15.3
77-
view_version: 0.15.3
76+
lib_version: 0.18
77+
view_version: 0.18
7878
```
7979
8080
In addition, feel free to define your favourite source urls like this:
@@ -89,8 +89,8 @@ plugins:
8989
9090
extra_javascript:
9191
- https://unpkg.com/d3@7/dist/d3.min.js
92-
- https://unpkg.com/markmap-lib@0.15.3/dist/browser/index.js
93-
- https://unpkg.com/markmap-view@0.15.3/dist/browser/index.js
92+
- https://unpkg.com/markmap-lib@0.18/dist/browser/index.iife.js
93+
- https://unpkg.com/markmap-view@0.18/dist/browser/index.js
9494
```
9595
9696
## Troubleshooting

mkdocs_markmap/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class JsModuleConfig(object):
1414
)
1515

1616
MARKMAP_LIB: JsModuleConfig = JsModuleConfig(
17-
version="0.15.4",
17+
version="0.18",
1818
uri="https://unpkg.com/markmap-lib@{}",
1919
)
2020

2121
MARKMAP_VIEW: JsModuleConfig = JsModuleConfig(
22-
version="0.15.4",
22+
version="0.18",
2323
uri="https://unpkg.com/markmap-view@{}",
2424
)
2525

mkdocs_markmap/static_files/mkdocs-markmap.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,25 @@
33
const assets = transformer.getAssets();
44
const loading = Promise.all([
55
assets.styles && markmap.loadCSS(assets.styles),
6-
assets.scripts && markmap.loadJS(assets.scripts),
6+
markmap.loadJS([
7+
...transformer.plugins.flatMap(
8+
(plugin) =>
9+
plugin.config?.preloadScripts?.map((item) =>
10+
item.data.src
11+
? {
12+
...item,
13+
data: {
14+
...item.data,
15+
src: transformer.urlBuilder.getFullUrl(
16+
item.data.src
17+
),
18+
},
19+
}
20+
: item
21+
) || []
22+
),
23+
...(assets.scripts || []),
24+
]),
725
]);
826

927
function parseData(content) {
@@ -19,8 +37,9 @@
1937
}
2038

2139
function resetMarkmap(m, el) {
22-
const { minX, maxX, minY, maxY } = m.state;
23-
const height = (el.clientWidth * (maxX - minX)) / (maxY - minY);
40+
if (!m.state.rect) return;
41+
const { x1, y1, x2, y2 } = m.state.rect;
42+
const height = (el.offsetWidth / (x2 - x1)) * (y2 - y1);
2443
el.style.height = height + "px";
2544
m.fit();
2645
}
@@ -44,11 +63,9 @@
4463
el.innerHTML = "<svg>";
4564
svg = el.firstChild;
4665
const { root, options } = parseData(content);
47-
const m = markmap.Markmap.create(svg, options, root);
48-
resetMarkmap(m, el);
49-
transformer.hooks.retransform.tap(() => {
50-
const { root, options } = parseData(content);
51-
m.setData(root, options);
66+
const m = markmap.Markmap.create(svg, options);
67+
m.setData(root);
68+
requestAnimationFrame(() => {
5269
resetMarkmap(m, el);
5370
});
5471
}

0 commit comments

Comments
 (0)