Skip to content

Commit dc81ffb

Browse files
committed
fix: use latest api for markmap
Signed-off-by: Yukai Huang <[email protected]>
1 parent 7cad0ef commit dc81ffb

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

public/js/extra.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import unescapeHTML from 'lodash/unescape'
1111

1212
import isURL from 'validator/lib/isURL'
1313

14-
import { transform } from 'markmap-lib'
15-
import { Markmap } from 'markmap-view'
14+
import { Transformer } from 'markmap-lib'
15+
import { Markmap, loadCSS, loadJS } from 'markmap-view'
1616

1717
import { stripTags } from '../../utils/string'
1818

@@ -52,6 +52,9 @@ const plantumlEncoder = require('plantuml-encoder')
5252

5353
const ui = getUIElements()
5454

55+
// Initialize markmap transformer
56+
const markmapTransformer = new Transformer()
57+
5558
// auto update last change
5659
window.createtime = null
5760
window.lastchangetime = null
@@ -569,12 +572,20 @@ export function finishView (view) {
569572
const content = $value.text()
570573
$value.unwrap()
571574
try {
572-
const { root } = transform(content)
575+
const { root, features } = markmapTransformer.transform(content)
573576
// Sanitize node contents to prevent XSS before rendering
574577
sanitizeMarkmapNode(root)
578+
579+
// Load required assets
580+
const { styles, scripts } = markmapTransformer.getUsedAssets(features)
581+
582+
if (styles) loadCSS(styles)
583+
if (scripts) loadJS(scripts, { getMarkmap: () => ({ Markmap }) })
584+
575585
$elem.html('<div class="markmap-container"><svg></svg></div>')
576586
Markmap.create($elem.find('svg')[0], {
577-
duration: 0
587+
duration: 0,
588+
maxWidth: 0
578589
}, root)
579590
} catch (err) {
580591
$elem.html(`<div class="alert alert-warning">${escapeHTML(err)}</div>`)

0 commit comments

Comments
 (0)