@@ -3,56 +3,60 @@ import "./main.css";
3
3
4
4
mermaid . initialize ( { startOnLoad : false } ) ;
5
5
6
- export function init ( ctx , { diagram, caption, download} ) {
7
- ctx . importCSS ( "main.css" )
8
-
6
+ export function init ( ctx , { diagram, caption, download } ) {
7
+ ctx . importCSS ( "main.css" ) ;
8
+
9
9
function render ( ) {
10
10
mermaid . render ( "diagram" , diagram ) . then ( ( { svg, bindFunctions } ) => {
11
11
// Fix for: https://github.com/mermaid-js/mermaid/issues/1766
12
- const renderedSvg = svg . replace ( / < b r > / gi, "<br />" )
13
-
12
+ const renderedSvg = svg . replace ( / < b r > / gi, "<br />" ) ;
13
+
14
14
let contents = document . createElement ( "div" ) ;
15
15
contents . id = "contents" ;
16
16
ctx . root . appendChild ( contents ) ;
17
-
17
+
18
18
let figure = document . createElement ( "figure" ) ;
19
19
figure . id = "figure" ;
20
20
figure . innerHTML = renderedSvg ;
21
21
contents . appendChild ( figure ) ;
22
-
22
+
23
23
if ( caption ) {
24
24
let figcaption = document . createElement ( "figcaption" ) ;
25
25
figcaption . textContent = caption ;
26
26
figure . appendChild ( figcaption ) ;
27
27
}
28
-
28
+
29
29
if ( download ) {
30
30
let downloadButton = document . createElement ( "button" ) ;
31
- downloadButton . id = "download"
32
- downloadButton . title = `Download ${ download . title } `
33
- downloadButton . textContent = "⇩"
31
+ downloadButton . id = "download" ;
32
+ downloadButton . title = `Download ${ download . title } ` ;
33
+ downloadButton . textContent = "⇩" ;
34
34
contents . prepend ( downloadButton ) ;
35
-
36
- contents . querySelector ( "#download" ) . addEventListener ( "click" , ( event ) => {
37
- var downloadData = [ ] ;
38
- downloadData . push ( renderedSvg ) ;
39
- const downloadBlob = URL . createObjectURL ( new Blob ( downloadData , { type : "image/svg+xml" } ) ) ;
40
-
41
- const downloadLink = document . createElement ( "a" ) ;
42
- downloadLink . href = downloadBlob ;
43
- downloadLink . download = download . filename ;
44
- contents . appendChild ( downloadLink ) ;
45
-
46
- downloadLink . dispatchEvent (
47
- new MouseEvent ( 'click' , {
48
- bubbles : true ,
49
- cancelable : true ,
50
- view : window
51
- } )
52
- ) ;
53
-
54
- contents . removeChild ( downloadLink ) ;
55
- } ) ;
35
+
36
+ contents
37
+ . querySelector ( "#download" )
38
+ . addEventListener ( "click" , ( event ) => {
39
+ var downloadData = [ ] ;
40
+ downloadData . push ( renderedSvg ) ;
41
+ const downloadBlob = URL . createObjectURL (
42
+ new Blob ( downloadData , { type : "image/svg+xml" } )
43
+ ) ;
44
+
45
+ const downloadLink = document . createElement ( "a" ) ;
46
+ downloadLink . href = downloadBlob ;
47
+ downloadLink . download = download . filename ;
48
+ contents . appendChild ( downloadLink ) ;
49
+
50
+ downloadLink . dispatchEvent (
51
+ new MouseEvent ( "click" , {
52
+ bubbles : true ,
53
+ cancelable : true ,
54
+ view : window ,
55
+ } )
56
+ ) ;
57
+
58
+ contents . removeChild ( downloadLink ) ;
59
+ } ) ;
56
60
}
57
61
58
62
if ( bindFunctions ) {
0 commit comments