@@ -11,8 +11,8 @@ import unescapeHTML from 'lodash/unescape'
11
11
12
12
import isURL from 'validator/lib/isURL'
13
13
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'
16
16
17
17
import { stripTags } from '../../utils/string'
18
18
@@ -52,6 +52,9 @@ const plantumlEncoder = require('plantuml-encoder')
52
52
53
53
const ui = getUIElements ( )
54
54
55
+ // Initialize markmap transformer
56
+ const markmapTransformer = new Transformer ( )
57
+
55
58
// auto update last change
56
59
window . createtime = null
57
60
window . lastchangetime = null
@@ -569,12 +572,20 @@ export function finishView (view) {
569
572
const content = $value . text ( )
570
573
$value . unwrap ( )
571
574
try {
572
- const { root } = transform ( content )
575
+ const { root, features } = markmapTransformer . transform ( content )
573
576
// Sanitize node contents to prevent XSS before rendering
574
577
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
+
575
585
$elem . html ( '<div class="markmap-container"><svg></svg></div>' )
576
586
Markmap . create ( $elem . find ( 'svg' ) [ 0 ] , {
577
- duration : 0
587
+ duration : 0 ,
588
+ maxWidth : 0
578
589
} , root )
579
590
} catch ( err ) {
580
591
$elem . html ( `<div class="alert alert-warning">${ escapeHTML ( err ) } </div>` )
0 commit comments