forked from codex-team/editor.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
54 lines (37 loc) · 918 Bytes
/
code.js
File metadata and controls
54 lines (37 loc) · 918 Bytes
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
/**
* Code Plugin\
* Creates code tag and adds content to this tag
*/
var codeTool = {
baseClass : "ce-code",
/**
* Make initial header block
* @param {object} JSON with block data
* @return {Element} element to append
*/
make : function (data) {
var tag = document.createElement('code');
tag.classList.add(codeTool.baseClass);
if (data && data.text) {
tag.innerHTML = data.text;
}
tag.contentEditable = true;
return tag;
},
/**
* Method to render HTML block from JSON
*/
render : function (data) {
return codeTool.make(data);
},
/**
* Method to extract JSON data from HTML block
*/
save : function (blockContent){
var data = {
text : null,
};
data.text = blockContent.innerHTML;
return data;
}
};