-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.html
162 lines (123 loc) · 4.33 KB
/
editor.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="favicon.png">
<title>Online Markdown Editor</title>
<link href="themes/simple.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://google-code-prettify.googlecode.com/svn/loader/prettify.css">
<style type="text/css">
/* Editor */
table.editor { margin: 0 auto; max-width: 64em;}
.editor pre {
word-wrap: break-word;
white-space: pre-wrap;
font-family: inherit;
}
table.editor > tbody > tr > td {
padding: 0 2em;
max-width: 30em;
}
.editor small, .editor small > a {
color: #ccc;
}
</style>
</head>
<body>
<!-- Wrap all page content here -->
<div id="wrap">
<table class="editor">
<tr>
<td>
<h2>Create</h2>
<pre contenteditable="true" id="holder" class="">> Prose is architecture, not interior decoration. - Ernest Hemingway
Facere nisi id cum, eum nemo molestias provident maxime ullam sed autem vitae, culpa nihil eveniet atque doloremque corporis esse quaerat. Eaque nisi ullam blanditiis esse provident repellat ea corporis aliquid molestias, quam nemo maiores obcaecati reiciendis excepturi ducimus laudantium voluptates. Voluptatem eius soluta eum praesentium, mollitia nisi ex cupiditate libero, earum temporibus vitae.
print "hello";
var length = ['hi'].length;
[Google](http://google.com) knows all.
- List Item 1
- List Item 2
- List Item 3
</pre>
</td>
<td>
<h2>Preview</h2>
<div class="preview"></div>
<small style="float: right">(<a href="#" class="clear">delete all</a> my prose)</small>
</td>
</tr>
</table>
</div>
<div id="footer">
<div class="container">
<p class="text-muted"><h3><a href="#" class="download">Download File</a></h3></p>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/showdown.js"></script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/prettify.js"></script>
<!-- jQuery listener for syntax highlight -->
<script type="text/javascript">
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
$(function() {
var localStorageSupport = supports_html5_storage();
var converter = new Showdown.converter({extensions: ['github', 'prettify', 'table'] });
var editor_markdown = null;
$editor = $('.editor pre');
// Load the existing document?
if(localStorageSupport && localStorage["editor.markdown"] && localStorage["editor.markdown"].length > 20) {
$editor.html(localStorage["editor.markdown"]);
}
$editor.keyup(function() {
// Convert to HTML
editor_markdown = $(this).html().replace(/<br\s*[\/]?>/gi, "\n");
//console.log(editor_markdown);
$('.preview').html(converter.makeHtml(editor_markdown));
prettyPrint();
}).trigger('keyup');
// If possible, and editor_markdown has been set
if(localStorageSupport) {
var intervalID = window.setInterval(function() {
if(editor_markdown) {
localStorage.setItem("editor.markdown", editor_markdown);
editor_markdown = null;
console.log('Saving changes');
}
}, 3000); // Every 3 seconds
}
$('.editor .clear').click(function() {
if (window.confirm("Do you really want erase your document?")) {
if(localStorage) {
localStorage['editor.markdown'] = '';
}
editor_markdown = null;
$editor.text("Once upon a time...").trigger('keyup');
}
});
$('.download').click(function(e)
{
var fileParts = [localStorage['editor.markdown']];
// Create a blob object.
var bb = new Blob(fileParts, {type : 'text/plain'});
// Create a blob url for this.
var dnlnk = window.URL.createObjectURL(bb);
$(this).attr('href',dnlnk);
$(this).attr('download','post.html');
});
});
</script>
</body>
</html>