-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·77 lines (71 loc) · 1.67 KB
/
index.html
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
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Markdown Editor</title>
<style type="text/css" media="screen">
.header {
font-size: x-large;
font-weight: bolder;
color:#ffffff;
background-color:#ccccff;
border-bottom: 1px solid rgba(0,0,0,1);
}
#editor {
border-right: 1px solid rgba(0,0,0,1);
margin: 0;
position: relative;
height: 600px;
width: 45%;
float: left;
}
#viewer {
width: 45%;
height: 600px;
overflow: auto;
}
</style>
</head>
<body>
<div class="header">Markdown editor</div>
<pre id="editor"># Marked in browser
- Edited by **ACE**
- Rendered by **marked**
</pre>
<div id="viewer" />
<script src="js/require.js" ></script>
<script>
require.config({
baseUrl: "lib",
paths: {ace: "ace"}
});
define('mdliveedit', ['ace/ace','marked'],
function(ace, marked,langtools) {
var editor = ace.edit("editor");
editor.session.setMode("ace/mode/markdown");
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
});
var viewer=document.getElementById('viewer');
viewer.innerHTML = marked(editor.getValue());
editor.getSession().on("change" , function(e){
viewer.innerHTML = marked(editor.getValue());
});
editor.getSession().on('changeScrollTop',function(scroll){
var cursor = editor.selection.getCursor();
var rows = editor.session.getLength();
viewer.scrollTop= (viewer.scrollHeight-viewer.clientHeight)*cursor.row/rows;
});
}
);
require(['mdliveedit'])
</script>
</body>
</html>