Mercurial > zeropaste
annotate lib/assets/javascripts/marked.js @ 110:e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 12:31:43 +0700 |
parents | 90b59418828a |
children |
rev | line source |
---|---|
100
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
1 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
2 * marked - A markdown parser (https://github.com/chjj/marked) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
3 * Copyright (c) 2011-2012, Christopher Jeffrey. (MIT Licensed) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
4 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
5 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
6 ;(function() { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
7 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
8 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
9 * Block-Level Grammar |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
10 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
11 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
12 var block = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
13 newline: /^\n+/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
14 code: /^( {4}[^\n]+\n*)+/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
15 fences: noop, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
16 hr: /^( *[-*_]){3,} *(?:\n+|$)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
17 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
18 lheading: /^([^\n]+)\n *(=|-){3,} *\n*/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
19 blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
20 list: /^( *)(bull) [^\0]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
21 html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
22 def: /^ *\[([^\]]+)\]: *([^\s]+)(?: +["(]([^\n]+)[")])? *(?:\n+|$)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
23 paragraph: /^([^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+\n*/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
24 text: /^[^\n]+/ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
25 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
26 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
27 block.bullet = /(?:[*+-]|\d+\.)/; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
28 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
29 block.item = replace(block.item, 'gm') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
30 (/bull/g, block.bullet) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
31 (); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
32 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
33 block.list = replace(block.list) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
34 (/bull/g, block.bullet) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
35 ('hr', /\n+(?=(?: *[-*_]){3,} *(?:\n+|$))/) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
36 (); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
37 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
38 block.html = replace(block.html) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
39 ('comment', /<!--[^\0]*?-->/) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
40 ('closed', /<(tag)[^\0]+?<\/\1>/) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
41 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
42 (/tag/g, tag()) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
43 (); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
44 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
45 block.paragraph = replace(block.paragraph) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
46 ('hr', block.hr) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
47 ('heading', block.heading) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
48 ('lheading', block.lheading) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
49 ('blockquote', block.blockquote) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
50 ('tag', '<' + tag()) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
51 ('def', block.def) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
52 (); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
53 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
54 block.normal = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
55 fences: block.fences, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
56 paragraph: block.paragraph |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
57 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
58 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
59 block.gfm = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
60 fences: /^ *(```|~~~) *(\w+)? *\n([^\0]+?)\s*\1 *(?:\n+|$)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
61 paragraph: /^/ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
62 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
63 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
64 block.gfm.paragraph = replace(block.paragraph) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
65 ('(?!', '(?!' + block.gfm.fences.source.replace('\\1', '\\2') + '|') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
66 (); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
67 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
68 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
69 * Block Lexer |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
70 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
71 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
72 block.lexer = function(src) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
73 var tokens = []; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
74 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
75 tokens.links = {}; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
76 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
77 src = src |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
78 .replace(/\r\n|\r/g, '\n') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
79 .replace(/\t/g, ' '); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
80 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
81 return block.token(src, tokens, true); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
82 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
83 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
84 block.token = function(src, tokens, top) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
85 var src = src.replace(/^ +$/gm, '') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
86 , next |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
87 , loose |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
88 , cap |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
89 , item |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
90 , space |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
91 , i |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
92 , l; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
93 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
94 while (src) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
95 // newline |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
96 if (cap = block.newline.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
97 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
98 if (cap[0].length > 1) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
99 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
100 type: 'space' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
101 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
102 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
103 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
104 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
105 // code |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
106 if (cap = block.code.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
107 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
108 cap = cap[0].replace(/^ {4}/gm, ''); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
109 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
110 type: 'code', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
111 text: !options.pedantic |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
112 ? cap.replace(/\n+$/, '') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
113 : cap |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
114 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
115 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
116 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
117 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
118 // fences (gfm) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
119 if (cap = block.fences.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
120 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
121 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
122 type: 'code', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
123 lang: cap[2], |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
124 text: cap[3] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
125 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
126 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
127 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
128 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
129 // heading |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
130 if (cap = block.heading.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
131 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
132 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
133 type: 'heading', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
134 depth: cap[1].length, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
135 text: cap[2] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
136 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
137 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
138 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
139 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
140 // lheading |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
141 if (cap = block.lheading.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
142 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
143 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
144 type: 'heading', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
145 depth: cap[2] === '=' ? 1 : 2, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
146 text: cap[1] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
147 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
148 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
149 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
150 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
151 // hr |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
152 if (cap = block.hr.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
153 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
154 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
155 type: 'hr' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
156 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
157 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
158 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
159 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
160 // blockquote |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
161 if (cap = block.blockquote.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
162 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
163 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
164 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
165 type: 'blockquote_start' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
166 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
167 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
168 cap = cap[0].replace(/^ *> ?/gm, ''); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
169 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
170 // Pass `top` to keep the current |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
171 // "toplevel" state. This is exactly |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
172 // how markdown.pl works. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
173 block.token(cap, tokens, top); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
174 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
175 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
176 type: 'blockquote_end' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
177 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
178 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
179 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
180 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
181 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
182 // list |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
183 if (cap = block.list.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
184 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
185 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
186 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
187 type: 'list_start', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
188 ordered: isFinite(cap[2]) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
189 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
190 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
191 // Get each top-level item. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
192 cap = cap[0].match(block.item); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
193 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
194 next = false; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
195 l = cap.length; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
196 i = 0; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
197 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
198 for (; i < l; i++) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
199 item = cap[i]; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
200 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
201 // Remove the list item's bullet |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
202 // so it is seen as the next token. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
203 space = item.length; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
204 item = item.replace(/^ *([*+-]|\d+\.) +/, ''); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
205 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
206 // Outdent whatever the |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
207 // list item contains. Hacky. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
208 if (~item.indexOf('\n ')) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
209 space -= item.length; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
210 item = !options.pedantic |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
211 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
212 : item.replace(/^ {1,4}/gm, ''); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
213 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
214 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
215 // Determine whether item is loose or not. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
216 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
217 // for discount behavior. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
218 loose = next || /\n\n(?!\s*$)/.test(item); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
219 if (i !== l - 1) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
220 next = item[item.length-1] === '\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
221 if (!loose) loose = next; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
222 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
223 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
224 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
225 type: loose |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
226 ? 'loose_item_start' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
227 : 'list_item_start' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
228 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
229 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
230 // Recurse. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
231 block.token(item, tokens); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
232 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
233 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
234 type: 'list_item_end' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
235 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
236 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
237 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
238 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
239 type: 'list_end' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
240 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
241 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
242 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
243 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
244 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
245 // html |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
246 if (cap = block.html.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
247 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
248 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
249 type: options.sanitize |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
250 ? 'paragraph' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
251 : 'html', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
252 pre: cap[1] === 'pre', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
253 text: cap[0] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
254 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
255 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
256 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
257 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
258 // def |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
259 if (top && (cap = block.def.exec(src))) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
260 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
261 tokens.links[cap[1].toLowerCase()] = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
262 href: cap[2], |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
263 title: cap[3] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
264 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
265 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
266 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
267 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
268 // top-level paragraph |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
269 if (top && (cap = block.paragraph.exec(src))) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
270 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
271 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
272 type: 'paragraph', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
273 text: cap[0] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
274 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
275 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
276 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
277 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
278 // text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
279 if (cap = block.text.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
280 // Top-level should never reach here. |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
281 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
282 tokens.push({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
283 type: 'text', |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
284 text: cap[0] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
285 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
286 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
287 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
288 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
289 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
290 return tokens; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
291 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
292 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
293 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
294 * Inline Processing |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
295 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
296 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
297 var inline = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
298 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
299 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
300 url: noop, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
301 tag: /^<!--[^\0]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
302 link: /^!?\[(inside)\]\(href\)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
303 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
304 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
305 strong: /^__([^\0]+?)__(?!_)|^\*\*([^\0]+?)\*\*(?!\*)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
306 em: /^\b_((?:__|[^\0])+?)_\b|^\*((?:\*\*|[^\0])+?)\*(?!\*)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
307 code: /^(`+)([^\0]*?[^`])\1(?!`)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
308 br: /^ {2,}\n(?!\s*$)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
309 text: /^[^\0]+?(?=[\\<!\[_*`]| {2,}\n|$)/ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
310 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
311 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
312 inline._linkInside = /(?:\[[^\]]*\]|[^\]]|\](?=[^\[]*\]))*/; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
313 inline._linkHref = /\s*<?([^\s]*?)>?(?:\s+['"]([^\0]*?)['"])?\s*/; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
314 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
315 inline.link = replace(inline.link) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
316 ('inside', inline._linkInside) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
317 ('href', inline._linkHref) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
318 (); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
319 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
320 inline.reflink = replace(inline.reflink) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
321 ('inside', inline._linkInside) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
322 (); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
323 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
324 inline.normal = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
325 url: inline.url, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
326 strong: inline.strong, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
327 em: inline.em, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
328 text: inline.text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
329 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
330 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
331 inline.pedantic = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
332 strong: /^__(?=\S)([^\0]*?\S)__(?!_)|^\*\*(?=\S)([^\0]*?\S)\*\*(?!\*)/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
333 em: /^_(?=\S)([^\0]*?\S)_(?!_)|^\*(?=\S)([^\0]*?\S)\*(?!\*)/ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
334 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
335 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
336 inline.gfm = { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
337 url: /^(https?:\/\/[^\s]+[^.,:;"')\]\s])/, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
338 text: /^[^\0]+?(?=[\\<!\[_*`]|https?:\/\/| {2,}\n|$)/ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
339 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
340 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
341 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
342 * Inline Lexer |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
343 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
344 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
345 inline.lexer = function(src) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
346 var out = '' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
347 , links = tokens.links |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
348 , link |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
349 , text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
350 , href |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
351 , cap; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
352 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
353 while (src) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
354 // escape |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
355 if (cap = inline.escape.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
356 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
357 out += cap[1]; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
358 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
359 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
360 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
361 // autolink |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
362 if (cap = inline.autolink.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
363 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
364 if (cap[2] === '@') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
365 text = cap[1][6] === ':' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
366 ? mangle(cap[1].substring(7)) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
367 : mangle(cap[1]); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
368 href = mangle('mailto:') + text; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
369 } else { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
370 text = escape(cap[1]); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
371 href = text; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
372 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
373 out += '<a href="' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
374 + href |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
375 + '">' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
376 + text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
377 + '</a>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
378 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
379 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
380 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
381 // url (gfm) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
382 if (cap = inline.url.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
383 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
384 text = escape(cap[1]); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
385 href = text; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
386 out += '<a href="' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
387 + href |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
388 + '">' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
389 + text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
390 + '</a>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
391 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
392 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
393 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
394 // tag |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
395 if (cap = inline.tag.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
396 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
397 out += options.sanitize |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
398 ? escape(cap[0]) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
399 : cap[0]; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
400 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
401 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
402 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
403 // link |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
404 if (cap = inline.link.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
405 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
406 out += outputLink(cap, { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
407 href: cap[2], |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
408 title: cap[3] |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
409 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
410 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
411 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
412 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
413 // reflink, nolink |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
414 if ((cap = inline.reflink.exec(src)) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
415 || (cap = inline.nolink.exec(src))) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
416 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
417 link = (cap[2] || cap[1]).replace(/\s+/g, ' '); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
418 link = links[link.toLowerCase()]; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
419 if (!link || !link.href) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
420 out += cap[0][0]; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
421 src = cap[0].substring(1) + src; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
422 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
423 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
424 out += outputLink(cap, link); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
425 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
426 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
427 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
428 // strong |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
429 if (cap = inline.strong.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
430 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
431 out += '<strong>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
432 + inline.lexer(cap[2] || cap[1]) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
433 + '</strong>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
434 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
435 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
436 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
437 // em |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
438 if (cap = inline.em.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
439 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
440 out += '<em>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
441 + inline.lexer(cap[2] || cap[1]) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
442 + '</em>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
443 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
444 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
445 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
446 // code |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
447 if (cap = inline.code.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
448 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
449 out += '<code>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
450 + escape(cap[2], true) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
451 + '</code>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
452 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
453 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
454 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
455 // br |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
456 if (cap = inline.br.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
457 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
458 out += '<br>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
459 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
460 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
461 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
462 // text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
463 if (cap = inline.text.exec(src)) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
464 src = src.substring(cap[0].length); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
465 out += escape(cap[0]); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
466 continue; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
467 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
468 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
469 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
470 return out; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
471 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
472 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
473 function outputLink(cap, link) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
474 if (cap[0][0] !== '!') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
475 return '<a href="' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
476 + escape(link.href) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
477 + '"' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
478 + (link.title |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
479 ? ' title="' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
480 + escape(link.title) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
481 + '"' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
482 : '') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
483 + '>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
484 + inline.lexer(cap[1]) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
485 + '</a>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
486 } else { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
487 return '<img src="' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
488 + escape(link.href) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
489 + '" alt="' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
490 + escape(cap[1]) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
491 + '"' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
492 + (link.title |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
493 ? ' title="' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
494 + escape(link.title) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
495 + '"' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
496 : '') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
497 + '>'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
498 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
499 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
500 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
501 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
502 * Parsing |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
503 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
504 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
505 var tokens |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
506 , token; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
507 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
508 function next() { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
509 return token = tokens.pop(); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
510 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
511 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
512 function tok() { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
513 switch (token.type) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
514 case 'space': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
515 return ''; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
516 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
517 case 'hr': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
518 return '<hr>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
519 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
520 case 'heading': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
521 return '<h' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
522 + token.depth |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
523 + '>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
524 + inline.lexer(token.text) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
525 + '</h' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
526 + token.depth |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
527 + '>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
528 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
529 case 'code': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
530 if (options.highlight) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
531 token.code = options.highlight(token.text, token.lang); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
532 if (token.code != null && token.code !== token.text) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
533 token.escaped = true; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
534 token.text = token.code; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
535 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
536 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
537 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
538 if (!token.escaped) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
539 token.text = escape(token.text, true); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
540 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
541 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
542 return '<pre><code' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
543 + (token.lang |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
544 ? ' class="lang-' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
545 + token.lang |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
546 + '"' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
547 : '') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
548 + '>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
549 + token.text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
550 + '</code></pre>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
551 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
552 case 'blockquote_start': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
553 var body = ''; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
554 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
555 while (next().type !== 'blockquote_end') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
556 body += tok(); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
557 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
558 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
559 return '<blockquote>\n' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
560 + body |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
561 + '</blockquote>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
562 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
563 case 'list_start': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
564 var type = token.ordered ? 'ol' : 'ul' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
565 , body = ''; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
566 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
567 while (next().type !== 'list_end') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
568 body += tok(); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
569 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
570 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
571 return '<' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
572 + type |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
573 + '>\n' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
574 + body |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
575 + '</' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
576 + type |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
577 + '>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
578 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
579 case 'list_item_start': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
580 var body = ''; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
581 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
582 while (next().type !== 'list_item_end') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
583 body += token.type === 'text' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
584 ? parseText() |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
585 : tok(); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
586 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
587 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
588 return '<li>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
589 + body |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
590 + '</li>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
591 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
592 case 'loose_item_start': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
593 var body = ''; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
594 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
595 while (next().type !== 'list_item_end') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
596 body += tok(); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
597 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
598 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
599 return '<li>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
600 + body |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
601 + '</li>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
602 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
603 case 'html': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
604 return !token.pre && !options.pedantic |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
605 ? inline.lexer(token.text) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
606 : token.text; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
607 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
608 case 'paragraph': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
609 return '<p>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
610 + inline.lexer(token.text) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
611 + '</p>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
612 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
613 case 'text': { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
614 return '<p>' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
615 + parseText() |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
616 + '</p>\n'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
617 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
618 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
619 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
620 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
621 function parseText() { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
622 var body = token.text |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
623 , top; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
624 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
625 while ((top = tokens[tokens.length-1]) |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
626 && top.type === 'text') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
627 body += '\n' + next().text; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
628 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
629 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
630 return inline.lexer(body); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
631 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
632 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
633 function parse(src) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
634 tokens = src.reverse(); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
635 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
636 var out = ''; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
637 while (next()) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
638 out += tok(); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
639 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
640 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
641 tokens = null; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
642 token = null; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
643 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
644 return out; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
645 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
646 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
647 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
648 * Helpers |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
649 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
650 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
651 function escape(html, encode) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
652 return html |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
653 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
654 .replace(/</g, '<') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
655 .replace(/>/g, '>') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
656 .replace(/"/g, '"') |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
657 .replace(/'/g, '''); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
658 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
659 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
660 function mangle(text) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
661 var out = '' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
662 , l = text.length |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
663 , i = 0 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
664 , ch; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
665 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
666 for (; i < l; i++) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
667 ch = text.charCodeAt(i); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
668 if (Math.random() > 0.5) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
669 ch = 'x' + ch.toString(16); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
670 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
671 out += '&#' + ch + ';'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
672 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
673 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
674 return out; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
675 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
676 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
677 function tag() { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
678 var tag = '(?!(?:' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
679 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
680 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
681 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|@)\\b'; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
682 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
683 return tag; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
684 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
685 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
686 function replace(regex, opt) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
687 regex = regex.source; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
688 opt = opt || ''; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
689 return function self(name, val) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
690 if (!name) return new RegExp(regex, opt); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
691 val = val.source || val; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
692 val = val.replace(/(^|[^\[])\^/g, '$1'); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
693 regex = regex.replace(name, val); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
694 return self; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
695 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
696 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
697 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
698 function noop() {} |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
699 noop.exec = noop; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
700 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
701 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
702 * Marked |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
703 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
704 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
705 function marked(src, opt) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
706 setOptions(opt); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
707 return parse(block.lexer(src)); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
708 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
709 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
710 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
711 * Options |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
712 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
713 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
714 var options |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
715 , defaults; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
716 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
717 function setOptions(opt) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
718 if (!opt) opt = defaults; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
719 if (options === opt) return; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
720 options = opt; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
721 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
722 if (options.gfm) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
723 block.fences = block.gfm.fences; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
724 block.paragraph = block.gfm.paragraph; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
725 inline.text = inline.gfm.text; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
726 inline.url = inline.gfm.url; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
727 } else { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
728 block.fences = block.normal.fences; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
729 block.paragraph = block.normal.paragraph; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
730 inline.text = inline.normal.text; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
731 inline.url = inline.normal.url; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
732 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
733 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
734 if (options.pedantic) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
735 inline.em = inline.pedantic.em; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
736 inline.strong = inline.pedantic.strong; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
737 } else { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
738 inline.em = inline.normal.em; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
739 inline.strong = inline.normal.strong; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
740 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
741 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
742 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
743 marked.options = |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
744 marked.setOptions = function(opt) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
745 defaults = opt; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
746 setOptions(opt); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
747 return marked; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
748 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
749 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
750 marked.setOptions({ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
751 gfm: true, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
752 pedantic: false, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
753 sanitize: false, |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
754 highlight: null |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
755 }); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
756 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
757 /** |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
758 * Expose |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
759 */ |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
760 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
761 marked.parser = function(src, opt) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
762 setOptions(opt); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
763 return parse(src); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
764 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
765 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
766 marked.lexer = function(src, opt) { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
767 setOptions(opt); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
768 return block.lexer(src); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
769 }; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
770 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
771 marked.parse = marked; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
772 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
773 if (typeof module !== 'undefined') { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
774 module.exports = marked; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
775 } else { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
776 this.marked = marked; |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
777 } |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
778 |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
779 }).call(function() { |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
780 return this || (typeof window !== 'undefined' ? window : global); |
90b59418828a
Three times more fun with tabs (added plain and markdown tab).
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
781 }()); |