forked from pandao/editor.md
-
Notifications
You must be signed in to change notification settings - Fork 0
221 lines (176 loc) · 8.23 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html lang="zh">
<head>
<title>Marked @ Test</title>
<meta charset="UTF-8">
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" href="../dist/css/editormd.min.css" />
<style>
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td,hr,button,
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
margin:0;
padding:0;
}
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {display: block;}
audio, canvas, video {display: inline-block;}
body, button, input, select, textarea {font:12px/1.5 Tahoma, "Hiragino Sans GB", "Microsoft Yahei", Arial;}
body{font-size:12px;color:#666;background:#fff url(../images/) no-repeat left top;}
body{font-size:14px;color:#444;font-family:"微软雅黑",Arial;background:#fff;padding: 15px;}
a{color:blue;text-decoration: none;}
a:hover{text-decoration: underline;}
.clear{zoom:1;}
.clear:after{content:"";height:0;visibility:hidden;clear:both;display:block;}
img{border:none;vertical-align: middle;}
ul, ol {margin-left: 18px;}
table {
margin: 10px 0;
border-collapse: collapse;
}
table th, table td {
padding: 5px 8px;
border: 1px solid #ddd;
}
pre {
padding:8px;border-radius:3px;border:1px solid #ddd;background:#f6f6f6;margin: 15px 0;display: inline-block;
}
pre code {
}
.editormd-logo,
.editormd-logo-4x {
font-family: editormd-logo;
speak: none;
font-style: normal;
font-weight: 400;
font-variant: normal;
text-transform: none;
font-size: inherit;
line-height: 1;
display: inline-block;
text-rendering: auto;
vertical-align: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.editormd-logo:before,
.editormd-logo-4x:before {
content: "\e1987";
}
.editormd-logo-4x {
font-size:4em;
}
</style>
</head>
<body>
<pre id="test"> ~~@mentions~~, #refs @tylerlong `inline code @tylerlong`, [links](), **formatting**, and <del>tags</del> supported @pandao;
list syntax required (any unordered or ordered list supported) @pandao;
this is @pandao a complete item @pandao;
link [@pandao](https://github.com/pandao "@pandao") @
link [@pandao](https://github.com/pandao "@pandao")
this is an incomplete item **@pandao**;
*@pandao* this is an incomplete item ___@pandao___;
# Github: @pandao
## Github: @pandao
### Github: @tylerlong
#### Github: @tylerlong
##### Github: @tylerlong
###### Github: @tylerlong
- dafssdfsdaf@chjj dfsdfsdf
- dafssdfsdaf@chjj dfsdfsdf
- dafssdfsdaf@chjj dfsdfsdf
- dafss@pandao dfsdaf@chjj dfsdfsdf
- dafssd: @pandao fsdaf@chjj dfsdfsdf @codemirror @pandao
+ dafssdfsdaf@chjj dfsdfsdf
+ dafss@pandaodfsdaf@chjj dfsdfsdf
1. @chjj 第一行@pandao fsdaf@chjj dfsdfsdf :fa-save:: @pandao
- dafssdfsdaf@chjj dfsdfsdf
- dafss@pandao dfsdaf@chjj dfsdfsdf
2. @chjj 第二行@pandao fsdaf@chjj dfsdfsdf @codemirror @pandao
3. 第三行@pandao fsdaf@chjj dfsdfsdf :fa-save:: @pandao
> Blockquotes @pandao
> dd@pandao引用文本(Blockquotes @pandao)fdasfad @_pandao fdasfad @xxx454xxx fdasfad @xx_x454xxx454
|@pandao First Header | Second@pandao Header@pandao |
| ------------- | ------------- |
| Content@pandao Cell | @pandao Content Cell @pandao|
| Con@pandao tent Cell@pandao | Content@pan-dao Cell dfsdfsdf @pan_dao |
dsfdf@pandao fasdfsdfsfddffd@pandao
dfasfasdfasdf:bangbang:
This is an H1 @pandao
=============
This @pandao an H2 @pandao
-------------
</pre>
<script src="../examples/js/jquery.min.js"></script>
<script src="../lib/marked.min.js"></script>
<script type="text/javascript">
$(function() {
var markedRenderer = new marked.Renderer();
var markdownToC = markdownToC || [];
console.log("markedRenderer =>", markedRenderer);
var atReg = /@(\w+)/g;
markedRenderer.at = function(text) {
if (atReg.test(text))
{
text = text.replace(atReg, function($1, $2){
console.log($1, $2);
return "<a href=\"https://github.com/" + $2 + "\">" + $1 + "</a>";
});
}
return text;
};
markedRenderer.link = function (href,title,text){
console.log("link =>", href,title,text);
if(this.options.sanitize) {
try{
var prot=decodeURIComponent(unescape(href)).replace(/[^\w:]/g,"").toLowerCase()
}catch(e){
return""
}
if(prot.indexOf("javascript:")===0){
return""
}
}
var out='<a href="'+href+'"';
if (atReg.test(title) || atReg.test(text))
{
return out + " title=\"" + title.replace(/@/g, "@") + "\">" + text.replace(/@/g, "@") + "</a>";
}
if(title) {
out+=' title="'+title+'"'
}
out+=">"+text+"</a>";
return out;
}
markedRenderer.paragraph = function(text) {
console.log("paragraph =>", text, atReg.test(text));
return "<p>" + this.at(text) + "</p>\n";
};
markedRenderer.heading = function (text,level,raw){
return"<h"+level+' id="'+this.options.headerPrefix+raw.toLowerCase().replace(/[^\w]+/g,"-")+'">'+this.at(text)+"</h"+level+">\n"
};
markedRenderer.listitem = function (text){
return "<li>" + this.at(text) + "</li>\n";
};
markedRenderer.tablecell = function (content,flags){
console.log(content);
var type=flags.header?"th":"td";
var tag=flags.align?"<"+type+' style="text-align:'+flags.align+'">':"<"+type+">";
return tag+this.at(content)+"</"+type+">\n";
}
marked.setOptions({
renderer : markedRenderer,
gfm : true,
tables : true,
breaks : true,
pedantic : false,
smartLists : true,
smartypants : true
});
var markdown = $("#test").html();
var md = marked(markdown);
//console.log(markdown);
$("body").append(md);
});
</script>
</body>
</html>