-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwrapper.js
65 lines (50 loc) · 1.46 KB
/
wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*\
title: $:/plugins/michaeljmcd/mermaid/wrapper.js
type: application/javascript
module-type: widget
Wrapper for Mermaid that provides a `<$mermaid>` widget.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget,
mermaidAPI = null;
if ($tw.browser) {
mermaidAPI = require("$:/plugins/michaeljmcd/mermaid/mermaidAPI.min.js");
}
var MermaidWidget = function(parseTreeNode, options) {
this.initialise(parseTreeNode,options);
};
MermaidWidget.prototype = new Widget();
MermaidWidget.prototype.render = function(parent, nextSibling) {
// Housekeeping
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
var div = this.document.createElement("div");
var source = this.getAttribute("text",this.parseTreeNode.text || "");
var _insertSvg = function(svgCode, bindFunctions) {
div.innerHTML = svgCode;
};
try {
mermaidAPI.render('test1', source, _insertSvg);
// TODO: do something sensible with ID.
} catch (ex) {
div.className = "tc-error";
div.textContent = ex;
}
// Insert the div into the DOM
parent.insertBefore(div,nextSibling);
this.domNodes.push(div);
};
MermaidWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.text) {
this.refreshSelf();
return true;
}
return false;
};
exports.mermaid = MermaidWidget;
})();