fron-ui 1.0.0rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +38 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +7 -0
  7. data/.yardopts +8 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +105 -0
  10. data/Rakefile +37 -0
  11. data/Readme.md +4 -0
  12. data/db.json +192 -0
  13. data/fron-ui.gemspec +21 -0
  14. data/lib/fron-ui.rb +1 -0
  15. data/lib/fron_ui.rb +5 -0
  16. data/lib/fron_ui/version.rb +7 -0
  17. data/opal/fron-ui/base.rb +49 -0
  18. data/opal/fron-ui/behaviors/action.rb +40 -0
  19. data/opal/fron-ui/behaviors/actions.rb +40 -0
  20. data/opal/fron-ui/behaviors/confirmation.rb +23 -0
  21. data/opal/fron-ui/behaviors/dropdown.rb +27 -0
  22. data/opal/fron-ui/behaviors/file.rb +48 -0
  23. data/opal/fron-ui/behaviors/intendable_children.rb +76 -0
  24. data/opal/fron-ui/behaviors/keydown.rb +31 -0
  25. data/opal/fron-ui/behaviors/loop.rb +41 -0
  26. data/opal/fron-ui/behaviors/render.rb +30 -0
  27. data/opal/fron-ui/behaviors/rest.rb +121 -0
  28. data/opal/fron-ui/behaviors/selectable_children.rb +67 -0
  29. data/opal/fron-ui/behaviors/serialize.rb +32 -0
  30. data/opal/fron-ui/behaviors/shortcuts.rb +35 -0
  31. data/opal/fron-ui/behaviors/state.rb +56 -0
  32. data/opal/fron-ui/behaviors/transition.rb +63 -0
  33. data/opal/fron-ui/components/action.rb +18 -0
  34. data/opal/fron-ui/components/box.rb +17 -0
  35. data/opal/fron-ui/components/button.rb +61 -0
  36. data/opal/fron-ui/components/calendar.rb +129 -0
  37. data/opal/fron-ui/components/checkbox.rb +57 -0
  38. data/opal/fron-ui/components/chooser.rb +246 -0
  39. data/opal/fron-ui/components/color_panel.rb +235 -0
  40. data/opal/fron-ui/components/color_picker.rb +111 -0
  41. data/opal/fron-ui/components/container.rb +61 -0
  42. data/opal/fron-ui/components/date_picker.rb +141 -0
  43. data/opal/fron-ui/components/drag.rb +76 -0
  44. data/opal/fron-ui/components/dropdown.rb +72 -0
  45. data/opal/fron-ui/components/icon.rb +29 -0
  46. data/opal/fron-ui/components/image.rb +77 -0
  47. data/opal/fron-ui/components/input.rb +30 -0
  48. data/opal/fron-ui/components/label.rb +9 -0
  49. data/opal/fron-ui/components/list.rb +34 -0
  50. data/opal/fron-ui/components/loader.rb +63 -0
  51. data/opal/fron-ui/components/modal.rb +0 -0
  52. data/opal/fron-ui/components/notifications.rb +73 -0
  53. data/opal/fron-ui/components/number.rb +202 -0
  54. data/opal/fron-ui/components/progress.rb +52 -0
  55. data/opal/fron-ui/components/slider.rb +47 -0
  56. data/opal/fron-ui/components/tabs.rb +149 -0
  57. data/opal/fron-ui/components/textarea.rb +13 -0
  58. data/opal/fron-ui/components/time.rb +65 -0
  59. data/opal/fron-ui/components/title.rb +34 -0
  60. data/opal/fron-ui/examples/blog/index.rb +289 -0
  61. data/opal/fron-ui/examples/comments/components/comment.rb +75 -0
  62. data/opal/fron-ui/examples/comments/components/comments.rb +93 -0
  63. data/opal/fron-ui/examples/comments/components/footer.rb +36 -0
  64. data/opal/fron-ui/examples/comments/components/header.rb +35 -0
  65. data/opal/fron-ui/examples/comments/components/list.rb +12 -0
  66. data/opal/fron-ui/examples/comments/index.rb +6 -0
  67. data/opal/fron-ui/examples/contacts/components/contacts.rb +100 -0
  68. data/opal/fron-ui/examples/contacts/components/details.rb +92 -0
  69. data/opal/fron-ui/examples/contacts/components/item.rb +46 -0
  70. data/opal/fron-ui/examples/contacts/components/list.rb +10 -0
  71. data/opal/fron-ui/examples/contacts/components/sidebar.rb +30 -0
  72. data/opal/fron-ui/examples/contacts/index.rb +6 -0
  73. data/opal/fron-ui/examples/editor/index.rb +164 -0
  74. data/opal/fron-ui/examples/kitchensink/index.rb +193 -0
  75. data/opal/fron-ui/examples/todos/components/item.rb +84 -0
  76. data/opal/fron-ui/examples/todos/components/options.rb +26 -0
  77. data/opal/fron-ui/examples/todos/components/todos.rb +145 -0
  78. data/opal/fron-ui/examples/todos/index.rb +6 -0
  79. data/opal/fron-ui/examples/webshop/index.rb +0 -0
  80. data/opal/fron-ui/fonts/ionicons.rb +2954 -0
  81. data/opal/fron-ui/fonts/open_sans.rb +19 -0
  82. data/opal/fron-ui/lib/collection.rb +138 -0
  83. data/opal/fron-ui/lib/date.rb +23 -0
  84. data/opal/fron-ui/lib/debounce.rb +14 -0
  85. data/opal/fron-ui/lib/image_loader.rb +13 -0
  86. data/opal/fron-ui/lib/lorem.rb +93 -0
  87. data/opal/fron-ui/lib/nil.rb +29 -0
  88. data/opal/fron-ui/lib/record.rb +23 -0
  89. data/opal/fron-ui/lib/state_serializer.rb +129 -0
  90. data/opal/fron-ui/lib/storage.rb +57 -0
  91. data/opal/fron-ui/spec/setup.rb +40 -0
  92. data/opal/fron-ui/ui.rb +40 -0
  93. data/opal/fron-ui/utils/theme_roller.rb +63 -0
  94. data/opal/fron-ui/vendor/autoprefixer.js +21114 -0
  95. data/opal/fron-ui/vendor/marked.js +1291 -0
  96. data/opal/fron-ui/vendor/md5.js +274 -0
  97. data/opal/fron-ui/vendor/moment.js +3083 -0
  98. data/opal/fron-ui/vendor/uuid.js +92 -0
  99. data/opal/fron_ui.rb +13 -0
  100. data/spec/behaviors/action_spec.rb +34 -0
  101. data/spec/behaviors/actions_spec.rb +38 -0
  102. data/spec/behaviors/confirmation_spec.rb +23 -0
  103. data/spec/behaviors/dropdown_spec.rb +32 -0
  104. data/spec/behaviors/render_spec.rb +20 -0
  105. data/spec/behaviors/rest_spec.rb +70 -0
  106. data/spec/behaviors/selectable_children_spec.rb +40 -0
  107. data/spec/behaviors/serialize_spec.rb +34 -0
  108. data/spec/components/action_spec.rb +7 -0
  109. data/spec/components/base_spec.rb +19 -0
  110. data/spec/components/box_spec.rb +7 -0
  111. data/spec/components/button_spec.rb +9 -0
  112. data/spec/components/calendar_spec.rb +58 -0
  113. data/spec/components/checkbox_spec.rb +20 -0
  114. data/spec/components/chooser_spec.rb +75 -0
  115. data/spec/components/color_panel_spec.rb +49 -0
  116. data/spec/components/color_picker_spec.rb +41 -0
  117. data/spec/components/container_spec.rb +23 -0
  118. data/spec/components/date_picker_spec.rb +71 -0
  119. data/spec/components/drag_spec.rb +20 -0
  120. data/spec/components/dropdown_spec.rb +33 -0
  121. data/spec/components/image_spec.rb +33 -0
  122. data/spec/components/input_spec.rb +8 -0
  123. data/spec/components/list_spec.rb +10 -0
  124. data/spec/components/loader_spec.rb +9 -0
  125. data/spec/components/notifications_spec.rb +17 -0
  126. data/spec/components/number_spec.rb +64 -0
  127. data/spec/components/progress_spec.rb +23 -0
  128. data/spec/components/slider_spec.rb +25 -0
  129. data/spec/components/tabs_spec.rb +50 -0
  130. data/spec/components/textarea_spec.rb +7 -0
  131. data/spec/components/time_spec.rb +37 -0
  132. data/spec/components/title_spec.rb +11 -0
  133. data/spec/examples/comments_spec.rb +72 -0
  134. data/spec/examples/todos_spec.rb +39 -0
  135. data/spec/lib/collection_spec.rb +38 -0
  136. data/spec/lib/lorem_spec.rb +55 -0
  137. data/spec/lib/state_serializer_spec.rb +58 -0
  138. data/spec/lib/storage_spec.rb +39 -0
  139. data/spec/spec_helper.rb +1 -0
  140. metadata +223 -0
@@ -0,0 +1,1291 @@
1
+ /**
2
+ * marked - a markdown parser
3
+ * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
4
+ * https://github.com/chjj/marked
5
+ */
6
+
7
+ ;(function() {
8
+
9
+ /**
10
+ * Block-Level Grammar
11
+ */
12
+
13
+ var block = {
14
+ newline: /^\n+/,
15
+ code: /^( {4}[^\n]+\n*)+/,
16
+ fences: noop,
17
+ hr: /^( *[-*_]){3,} *(?:\n+|$)/,
18
+ heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
19
+ nptable: noop,
20
+ lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
21
+ blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
22
+ list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
23
+ html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
24
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
25
+ table: noop,
26
+ paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
27
+ text: /^[^\n]+/
28
+ };
29
+
30
+ block.bullet = /(?:[*+-]|\d+\.)/;
31
+ block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
32
+ block.item = replace(block.item, 'gm')
33
+ (/bull/g, block.bullet)
34
+ ();
35
+
36
+ block.list = replace(block.list)
37
+ (/bull/g, block.bullet)
38
+ ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
39
+ ('def', '\\n+(?=' + block.def.source + ')')
40
+ ();
41
+
42
+ block.blockquote = replace(block.blockquote)
43
+ ('def', block.def)
44
+ ();
45
+
46
+ block._tag = '(?!(?:'
47
+ + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
48
+ + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
49
+ + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
50
+
51
+ block.html = replace(block.html)
52
+ ('comment', /<!--[\s\S]*?-->/)
53
+ ('closed', /<(tag)[\s\S]+?<\/\1>/)
54
+ ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
55
+ (/tag/g, block._tag)
56
+ ();
57
+
58
+ block.paragraph = replace(block.paragraph)
59
+ ('hr', block.hr)
60
+ ('heading', block.heading)
61
+ ('lheading', block.lheading)
62
+ ('blockquote', block.blockquote)
63
+ ('tag', '<' + block._tag)
64
+ ('def', block.def)
65
+ ();
66
+
67
+ /**
68
+ * Normal Block Grammar
69
+ */
70
+
71
+ block.normal = merge({}, block);
72
+
73
+ /**
74
+ * GFM Block Grammar
75
+ */
76
+
77
+ block.gfm = merge({}, block.normal, {
78
+ fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,
79
+ paragraph: /^/,
80
+ heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
81
+ });
82
+
83
+ block.gfm.paragraph = replace(block.paragraph)
84
+ ('(?!', '(?!'
85
+ + block.gfm.fences.source.replace('\\1', '\\2') + '|'
86
+ + block.list.source.replace('\\1', '\\3') + '|')
87
+ ();
88
+
89
+ /**
90
+ * GFM + Tables Block Grammar
91
+ */
92
+
93
+ block.tables = merge({}, block.gfm, {
94
+ nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
95
+ table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
96
+ });
97
+
98
+ /**
99
+ * Block Lexer
100
+ */
101
+
102
+ function Lexer(options) {
103
+ this.tokens = [];
104
+ this.tokens.links = {};
105
+ this.options = options || marked.defaults;
106
+ this.rules = block.normal;
107
+
108
+ if (this.options.gfm) {
109
+ if (this.options.tables) {
110
+ this.rules = block.tables;
111
+ } else {
112
+ this.rules = block.gfm;
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Expose Block Rules
119
+ */
120
+
121
+ Lexer.rules = block;
122
+
123
+ /**
124
+ * Static Lex Method
125
+ */
126
+
127
+ Lexer.lex = function(src, options) {
128
+ var lexer = new Lexer(options);
129
+ return lexer.lex(src);
130
+ };
131
+
132
+ /**
133
+ * Preprocessing
134
+ */
135
+
136
+ Lexer.prototype.lex = function(src) {
137
+ src = src
138
+ .replace(/\r\n|\r/g, '\n')
139
+ .replace(/\t/g, ' ')
140
+ .replace(/\u00a0/g, ' ')
141
+ .replace(/\u2424/g, '\n');
142
+
143
+ return this.token(src, true);
144
+ };
145
+
146
+ /**
147
+ * Lexing
148
+ */
149
+
150
+ Lexer.prototype.token = function(src, top, bq) {
151
+ var src = src.replace(/^ +$/gm, '')
152
+ , next
153
+ , loose
154
+ , cap
155
+ , bull
156
+ , b
157
+ , item
158
+ , space
159
+ , i
160
+ , l;
161
+
162
+ while (src) {
163
+ // newline
164
+ if (cap = this.rules.newline.exec(src)) {
165
+ src = src.substring(cap[0].length);
166
+ if (cap[0].length > 1) {
167
+ this.tokens.push({
168
+ type: 'space'
169
+ });
170
+ }
171
+ }
172
+
173
+ // code
174
+ if (cap = this.rules.code.exec(src)) {
175
+ src = src.substring(cap[0].length);
176
+ cap = cap[0].replace(/^ {4}/gm, '');
177
+ this.tokens.push({
178
+ type: 'code',
179
+ text: !this.options.pedantic
180
+ ? cap.replace(/\n+$/, '')
181
+ : cap
182
+ });
183
+ continue;
184
+ }
185
+
186
+ // fences (gfm)
187
+ if (cap = this.rules.fences.exec(src)) {
188
+ src = src.substring(cap[0].length);
189
+ this.tokens.push({
190
+ type: 'code',
191
+ lang: cap[2],
192
+ text: cap[3]
193
+ });
194
+ continue;
195
+ }
196
+
197
+ // heading
198
+ if (cap = this.rules.heading.exec(src)) {
199
+ src = src.substring(cap[0].length);
200
+ this.tokens.push({
201
+ type: 'heading',
202
+ depth: cap[1].length,
203
+ text: cap[2]
204
+ });
205
+ continue;
206
+ }
207
+
208
+ // table no leading pipe (gfm)
209
+ if (top && (cap = this.rules.nptable.exec(src))) {
210
+ src = src.substring(cap[0].length);
211
+
212
+ item = {
213
+ type: 'table',
214
+ header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
215
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
216
+ cells: cap[3].replace(/\n$/, '').split('\n')
217
+ };
218
+
219
+ for (i = 0; i < item.align.length; i++) {
220
+ if (/^ *-+: *$/.test(item.align[i])) {
221
+ item.align[i] = 'right';
222
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
223
+ item.align[i] = 'center';
224
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
225
+ item.align[i] = 'left';
226
+ } else {
227
+ item.align[i] = null;
228
+ }
229
+ }
230
+
231
+ for (i = 0; i < item.cells.length; i++) {
232
+ item.cells[i] = item.cells[i].split(/ *\| */);
233
+ }
234
+
235
+ this.tokens.push(item);
236
+
237
+ continue;
238
+ }
239
+
240
+ // lheading
241
+ if (cap = this.rules.lheading.exec(src)) {
242
+ src = src.substring(cap[0].length);
243
+ this.tokens.push({
244
+ type: 'heading',
245
+ depth: cap[2] === '=' ? 1 : 2,
246
+ text: cap[1]
247
+ });
248
+ continue;
249
+ }
250
+
251
+ // hr
252
+ if (cap = this.rules.hr.exec(src)) {
253
+ src = src.substring(cap[0].length);
254
+ this.tokens.push({
255
+ type: 'hr'
256
+ });
257
+ continue;
258
+ }
259
+
260
+ // blockquote
261
+ if (cap = this.rules.blockquote.exec(src)) {
262
+ src = src.substring(cap[0].length);
263
+
264
+ this.tokens.push({
265
+ type: 'blockquote_start'
266
+ });
267
+
268
+ cap = cap[0].replace(/^ *> ?/gm, '');
269
+
270
+ // Pass `top` to keep the current
271
+ // "toplevel" state. This is exactly
272
+ // how markdown.pl works.
273
+ this.token(cap, top, true);
274
+
275
+ this.tokens.push({
276
+ type: 'blockquote_end'
277
+ });
278
+
279
+ continue;
280
+ }
281
+
282
+ // list
283
+ if (cap = this.rules.list.exec(src)) {
284
+ src = src.substring(cap[0].length);
285
+ bull = cap[2];
286
+
287
+ this.tokens.push({
288
+ type: 'list_start',
289
+ ordered: bull.length > 1
290
+ });
291
+
292
+ // Get each top-level item.
293
+ cap = cap[0].match(this.rules.item);
294
+
295
+ next = false;
296
+ l = cap.length;
297
+ i = 0;
298
+
299
+ for (; i < l; i++) {
300
+ item = cap[i];
301
+
302
+ // Remove the list item's bullet
303
+ // so it is seen as the next token.
304
+ space = item.length;
305
+ item = item.replace(/^ *([*+-]|\d+\.) +/, '');
306
+
307
+ // Outdent whatever the
308
+ // list item contains. Hacky.
309
+ if (~item.indexOf('\n ')) {
310
+ space -= item.length;
311
+ item = !this.options.pedantic
312
+ ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
313
+ : item.replace(/^ {1,4}/gm, '');
314
+ }
315
+
316
+ // Determine whether the next list item belongs here.
317
+ // Backpedal if it does not belong in this list.
318
+ if (this.options.smartLists && i !== l - 1) {
319
+ b = block.bullet.exec(cap[i + 1])[0];
320
+ if (bull !== b && !(bull.length > 1 && b.length > 1)) {
321
+ src = cap.slice(i + 1).join('\n') + src;
322
+ i = l - 1;
323
+ }
324
+ }
325
+
326
+ // Determine whether item is loose or not.
327
+ // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
328
+ // for discount behavior.
329
+ loose = next || /\n\n(?!\s*$)/.test(item);
330
+ if (i !== l - 1) {
331
+ next = item.charAt(item.length - 1) === '\n';
332
+ if (!loose) loose = next;
333
+ }
334
+
335
+ this.tokens.push({
336
+ type: loose
337
+ ? 'loose_item_start'
338
+ : 'list_item_start'
339
+ });
340
+
341
+ // Recurse.
342
+ this.token(item, false, bq);
343
+
344
+ this.tokens.push({
345
+ type: 'list_item_end'
346
+ });
347
+ }
348
+
349
+ this.tokens.push({
350
+ type: 'list_end'
351
+ });
352
+
353
+ continue;
354
+ }
355
+
356
+ // html
357
+ if (cap = this.rules.html.exec(src)) {
358
+ src = src.substring(cap[0].length);
359
+ this.tokens.push({
360
+ type: this.options.sanitize
361
+ ? 'paragraph'
362
+ : 'html',
363
+ pre: !this.options.sanitizer
364
+ && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
365
+ text: cap[0]
366
+ });
367
+ continue;
368
+ }
369
+
370
+ // def
371
+ if ((!bq && top) && (cap = this.rules.def.exec(src))) {
372
+ src = src.substring(cap[0].length);
373
+ this.tokens.links[cap[1].toLowerCase()] = {
374
+ href: cap[2],
375
+ title: cap[3]
376
+ };
377
+ continue;
378
+ }
379
+
380
+ // table (gfm)
381
+ if (top && (cap = this.rules.table.exec(src))) {
382
+ src = src.substring(cap[0].length);
383
+
384
+ item = {
385
+ type: 'table',
386
+ header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
387
+ align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
388
+ cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
389
+ };
390
+
391
+ for (i = 0; i < item.align.length; i++) {
392
+ if (/^ *-+: *$/.test(item.align[i])) {
393
+ item.align[i] = 'right';
394
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
395
+ item.align[i] = 'center';
396
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
397
+ item.align[i] = 'left';
398
+ } else {
399
+ item.align[i] = null;
400
+ }
401
+ }
402
+
403
+ for (i = 0; i < item.cells.length; i++) {
404
+ item.cells[i] = item.cells[i]
405
+ .replace(/^ *\| *| *\| *$/g, '')
406
+ .split(/ *\| */);
407
+ }
408
+
409
+ this.tokens.push(item);
410
+
411
+ continue;
412
+ }
413
+
414
+ // top-level paragraph
415
+ if (top && (cap = this.rules.paragraph.exec(src))) {
416
+ src = src.substring(cap[0].length);
417
+ this.tokens.push({
418
+ type: 'paragraph',
419
+ text: cap[1].charAt(cap[1].length - 1) === '\n'
420
+ ? cap[1].slice(0, -1)
421
+ : cap[1]
422
+ });
423
+ continue;
424
+ }
425
+
426
+ // text
427
+ if (cap = this.rules.text.exec(src)) {
428
+ // Top-level should never reach here.
429
+ src = src.substring(cap[0].length);
430
+ this.tokens.push({
431
+ type: 'text',
432
+ text: cap[0]
433
+ });
434
+ continue;
435
+ }
436
+
437
+ if (src) {
438
+ throw new
439
+ Error('Infinite loop on byte: ' + src.charCodeAt(0));
440
+ }
441
+ }
442
+
443
+ return this.tokens;
444
+ };
445
+
446
+ /**
447
+ * Inline-Level Grammar
448
+ */
449
+
450
+ var inline = {
451
+ escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
452
+ autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
453
+ url: noop,
454
+ tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
455
+ link: /^!?\[(inside)\]\(href\)/,
456
+ reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
457
+ nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
458
+ strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
459
+ em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
460
+ code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
461
+ br: /^ {2,}\n(?!\s*$)/,
462
+ del: noop,
463
+ text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
464
+ };
465
+
466
+ inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
467
+ inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
468
+
469
+ inline.link = replace(inline.link)
470
+ ('inside', inline._inside)
471
+ ('href', inline._href)
472
+ ();
473
+
474
+ inline.reflink = replace(inline.reflink)
475
+ ('inside', inline._inside)
476
+ ();
477
+
478
+ /**
479
+ * Normal Inline Grammar
480
+ */
481
+
482
+ inline.normal = merge({}, inline);
483
+
484
+ /**
485
+ * Pedantic Inline Grammar
486
+ */
487
+
488
+ inline.pedantic = merge({}, inline.normal, {
489
+ strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
490
+ em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
491
+ });
492
+
493
+ /**
494
+ * GFM Inline Grammar
495
+ */
496
+
497
+ inline.gfm = merge({}, inline.normal, {
498
+ escape: replace(inline.escape)('])', '~|])')(),
499
+ url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
500
+ del: /^~~(?=\S)([\s\S]*?\S)~~/,
501
+ text: replace(inline.text)
502
+ (']|', '~]|')
503
+ ('|', '|https?://|')
504
+ ()
505
+ });
506
+
507
+ /**
508
+ * GFM + Line Breaks Inline Grammar
509
+ */
510
+
511
+ inline.breaks = merge({}, inline.gfm, {
512
+ br: replace(inline.br)('{2,}', '*')(),
513
+ text: replace(inline.gfm.text)('{2,}', '*')()
514
+ });
515
+
516
+ /**
517
+ * Inline Lexer & Compiler
518
+ */
519
+
520
+ function InlineLexer(links, options) {
521
+ this.options = options || marked.defaults;
522
+ this.links = links;
523
+ this.rules = inline.normal;
524
+ this.renderer = this.options.renderer || new Renderer;
525
+ this.renderer.options = this.options;
526
+
527
+ if (!this.links) {
528
+ throw new
529
+ Error('Tokens array requires a `links` property.');
530
+ }
531
+
532
+ if (this.options.gfm) {
533
+ if (this.options.breaks) {
534
+ this.rules = inline.breaks;
535
+ } else {
536
+ this.rules = inline.gfm;
537
+ }
538
+ } else if (this.options.pedantic) {
539
+ this.rules = inline.pedantic;
540
+ }
541
+ }
542
+
543
+ /**
544
+ * Expose Inline Rules
545
+ */
546
+
547
+ InlineLexer.rules = inline;
548
+
549
+ /**
550
+ * Static Lexing/Compiling Method
551
+ */
552
+
553
+ InlineLexer.output = function(src, links, options) {
554
+ var inline = new InlineLexer(links, options);
555
+ return inline.output(src);
556
+ };
557
+
558
+ /**
559
+ * Lexing/Compiling
560
+ */
561
+
562
+ InlineLexer.prototype.output = function(src) {
563
+ var out = ''
564
+ , link
565
+ , text
566
+ , href
567
+ , cap;
568
+
569
+ while (src) {
570
+ // escape
571
+ if (cap = this.rules.escape.exec(src)) {
572
+ src = src.substring(cap[0].length);
573
+ out += cap[1];
574
+ continue;
575
+ }
576
+
577
+ // autolink
578
+ if (cap = this.rules.autolink.exec(src)) {
579
+ src = src.substring(cap[0].length);
580
+ if (cap[2] === '@') {
581
+ text = cap[1].charAt(6) === ':'
582
+ ? this.mangle(cap[1].substring(7))
583
+ : this.mangle(cap[1]);
584
+ href = this.mangle('mailto:') + text;
585
+ } else {
586
+ text = escape(cap[1]);
587
+ href = text;
588
+ }
589
+ out += this.renderer.link(href, null, text);
590
+ continue;
591
+ }
592
+
593
+ // url (gfm)
594
+ if (!this.inLink && (cap = this.rules.url.exec(src))) {
595
+ src = src.substring(cap[0].length);
596
+ text = escape(cap[1]);
597
+ href = text;
598
+ out += this.renderer.link(href, null, text);
599
+ continue;
600
+ }
601
+
602
+ // tag
603
+ if (cap = this.rules.tag.exec(src)) {
604
+ if (!this.inLink && /^<a /i.test(cap[0])) {
605
+ this.inLink = true;
606
+ } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
607
+ this.inLink = false;
608
+ }
609
+ src = src.substring(cap[0].length);
610
+ out += this.options.sanitize
611
+ ? this.options.sanitizer
612
+ ? this.options.sanitizer(cap[0])
613
+ : escape(cap[0])
614
+ : cap[0]
615
+ continue;
616
+ }
617
+
618
+ // link
619
+ if (cap = this.rules.link.exec(src)) {
620
+ src = src.substring(cap[0].length);
621
+ this.inLink = true;
622
+ out += this.outputLink(cap, {
623
+ href: cap[2],
624
+ title: cap[3]
625
+ });
626
+ this.inLink = false;
627
+ continue;
628
+ }
629
+
630
+ // reflink, nolink
631
+ if ((cap = this.rules.reflink.exec(src))
632
+ || (cap = this.rules.nolink.exec(src))) {
633
+ src = src.substring(cap[0].length);
634
+ link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
635
+ link = this.links[link.toLowerCase()];
636
+ if (!link || !link.href) {
637
+ out += cap[0].charAt(0);
638
+ src = cap[0].substring(1) + src;
639
+ continue;
640
+ }
641
+ this.inLink = true;
642
+ out += this.outputLink(cap, link);
643
+ this.inLink = false;
644
+ continue;
645
+ }
646
+
647
+ // strong
648
+ if (cap = this.rules.strong.exec(src)) {
649
+ src = src.substring(cap[0].length);
650
+ out += this.renderer.strong(this.output(cap[2] || cap[1]));
651
+ continue;
652
+ }
653
+
654
+ // em
655
+ if (cap = this.rules.em.exec(src)) {
656
+ src = src.substring(cap[0].length);
657
+ out += this.renderer.em(this.output(cap[2] || cap[1]));
658
+ continue;
659
+ }
660
+
661
+ // code
662
+ if (cap = this.rules.code.exec(src)) {
663
+ src = src.substring(cap[0].length);
664
+ var code;
665
+ if(this.options.highlight) {
666
+ code = this.options.highlight(cap[2])
667
+ } else {
668
+ escape(cap[2], true)
669
+ }
670
+ out += this.renderer.codespan(code);
671
+ continue;
672
+ }
673
+
674
+ // br
675
+ if (cap = this.rules.br.exec(src)) {
676
+ src = src.substring(cap[0].length);
677
+ out += this.renderer.br();
678
+ continue;
679
+ }
680
+
681
+ // del (gfm)
682
+ if (cap = this.rules.del.exec(src)) {
683
+ src = src.substring(cap[0].length);
684
+ out += this.renderer.del(this.output(cap[1]));
685
+ continue;
686
+ }
687
+
688
+ // text
689
+ if (cap = this.rules.text.exec(src)) {
690
+ src = src.substring(cap[0].length);
691
+ out += this.renderer.text(escape(this.smartypants(cap[0])));
692
+ continue;
693
+ }
694
+
695
+ if (src) {
696
+ throw new
697
+ Error('Infinite loop on byte: ' + src.charCodeAt(0));
698
+ }
699
+ }
700
+
701
+ return out;
702
+ };
703
+
704
+ /**
705
+ * Compile Link
706
+ */
707
+
708
+ InlineLexer.prototype.outputLink = function(cap, link) {
709
+ var href = escape(link.href)
710
+ , title = link.title ? escape(link.title) : null;
711
+
712
+ return cap[0].charAt(0) !== '!'
713
+ ? this.renderer.link(href, title, this.output(cap[1]))
714
+ : this.renderer.image(href, title, escape(cap[1]));
715
+ };
716
+
717
+ /**
718
+ * Smartypants Transformations
719
+ */
720
+
721
+ InlineLexer.prototype.smartypants = function(text) {
722
+ if (!this.options.smartypants) return text;
723
+ return text
724
+ // em-dashes
725
+ .replace(/---/g, '\u2014')
726
+ // en-dashes
727
+ .replace(/--/g, '\u2013')
728
+ // opening singles
729
+ .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
730
+ // closing singles & apostrophes
731
+ .replace(/'/g, '\u2019')
732
+ // opening doubles
733
+ .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
734
+ // closing doubles
735
+ .replace(/"/g, '\u201d')
736
+ // ellipses
737
+ .replace(/\.{3}/g, '\u2026');
738
+ };
739
+
740
+ /**
741
+ * Mangle Links
742
+ */
743
+
744
+ InlineLexer.prototype.mangle = function(text) {
745
+ if (!this.options.mangle) return text;
746
+ var out = ''
747
+ , l = text.length
748
+ , i = 0
749
+ , ch;
750
+
751
+ for (; i < l; i++) {
752
+ ch = text.charCodeAt(i);
753
+ if (Math.random() > 0.5) {
754
+ ch = 'x' + ch.toString(16);
755
+ }
756
+ out += '&#' + ch + ';';
757
+ }
758
+
759
+ return out;
760
+ };
761
+
762
+ /**
763
+ * Renderer
764
+ */
765
+
766
+ function Renderer(options) {
767
+ this.options = options || {};
768
+ }
769
+
770
+ Renderer.prototype.code = function(code, lang, escaped) {
771
+ if (this.options.highlight) {
772
+ var out = this.options.highlight(code, lang);
773
+ if (out != null && out !== code) {
774
+ escaped = true;
775
+ code = out;
776
+ }
777
+ }
778
+
779
+ if (!lang) {
780
+ return '<pre><code>'
781
+ + (escaped ? code : escape(code, true))
782
+ + '\n</code></pre>';
783
+ }
784
+
785
+ return '<pre><code class="'
786
+ + this.options.langPrefix
787
+ + escape(lang, true)
788
+ + '">'
789
+ + (escaped ? code : escape(code, true))
790
+ + '\n</code></pre>\n';
791
+ };
792
+
793
+ Renderer.prototype.blockquote = function(quote) {
794
+ return '<blockquote>\n' + quote + '</blockquote>\n';
795
+ };
796
+
797
+ Renderer.prototype.html = function(html) {
798
+ return html;
799
+ };
800
+
801
+ Renderer.prototype.heading = function(text, level, raw) {
802
+ return '<h'
803
+ + level
804
+ + ' id="'
805
+ + this.options.headerPrefix
806
+ + raw.toLowerCase().replace(/[^\w]+/g, '-')
807
+ + '">'
808
+ + text
809
+ + '</h'
810
+ + level
811
+ + '>\n';
812
+ };
813
+
814
+ Renderer.prototype.hr = function() {
815
+ return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
816
+ };
817
+
818
+ Renderer.prototype.list = function(body, ordered) {
819
+ var type = ordered ? 'ol' : 'ul';
820
+ return '<' + type + '>\n' + body + '</' + type + '>\n';
821
+ };
822
+
823
+ Renderer.prototype.listitem = function(text) {
824
+ return '<li>' + text + '</li>\n';
825
+ };
826
+
827
+ Renderer.prototype.paragraph = function(text) {
828
+ return '<p>' + text + '</p>\n';
829
+ };
830
+
831
+ Renderer.prototype.table = function(header, body) {
832
+ return '<table>\n'
833
+ + '<thead>\n'
834
+ + header
835
+ + '</thead>\n'
836
+ + '<tbody>\n'
837
+ + body
838
+ + '</tbody>\n'
839
+ + '</table>\n';
840
+ };
841
+
842
+ Renderer.prototype.tablerow = function(content) {
843
+ return '<tr>\n' + content + '</tr>\n';
844
+ };
845
+
846
+ Renderer.prototype.tablecell = function(content, flags) {
847
+ var type = flags.header ? 'th' : 'td';
848
+ var tag = flags.align
849
+ ? '<' + type + ' style="text-align:' + flags.align + '">'
850
+ : '<' + type + '>';
851
+ return tag + content + '</' + type + '>\n';
852
+ };
853
+
854
+ // span level renderer
855
+ Renderer.prototype.strong = function(text) {
856
+ return '<strong>' + text + '</strong>';
857
+ };
858
+
859
+ Renderer.prototype.em = function(text) {
860
+ return '<em>' + text + '</em>';
861
+ };
862
+
863
+ Renderer.prototype.codespan = function(text) {
864
+ return '<code>' + text + '</code>';
865
+ };
866
+
867
+ Renderer.prototype.br = function() {
868
+ return this.options.xhtml ? '<br/>' : '<br>';
869
+ };
870
+
871
+ Renderer.prototype.del = function(text) {
872
+ return '<del>' + text + '</del>';
873
+ };
874
+
875
+ Renderer.prototype.link = function(href, title, text) {
876
+ if (this.options.sanitize) {
877
+ try {
878
+ var prot = decodeURIComponent(unescape(href))
879
+ .replace(/[^\w:]/g, '')
880
+ .toLowerCase();
881
+ } catch (e) {
882
+ return '';
883
+ }
884
+ if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
885
+ return '';
886
+ }
887
+ }
888
+ var out = '<a href="' + href + '"';
889
+ if (title) {
890
+ out += ' title="' + title + '"';
891
+ }
892
+ out += '>' + text + '</a>';
893
+ return out;
894
+ };
895
+
896
+ Renderer.prototype.image = function(href, title, text) {
897
+ var out = '<img src="' + href + '" alt="' + text + '"';
898
+ if (title) {
899
+ out += ' title="' + title + '"';
900
+ }
901
+ out += this.options.xhtml ? '/>' : '>';
902
+ return out;
903
+ };
904
+
905
+ Renderer.prototype.text = function(text) {
906
+ return text;
907
+ };
908
+
909
+ /**
910
+ * Parsing & Compiling
911
+ */
912
+
913
+ function Parser(options) {
914
+ this.tokens = [];
915
+ this.token = null;
916
+ this.options = options || marked.defaults;
917
+ this.options.renderer = this.options.renderer || new Renderer;
918
+ this.renderer = this.options.renderer;
919
+ this.renderer.options = this.options;
920
+ }
921
+
922
+ /**
923
+ * Static Parse Method
924
+ */
925
+
926
+ Parser.parse = function(src, options, renderer) {
927
+ var parser = new Parser(options, renderer);
928
+ return parser.parse(src);
929
+ };
930
+
931
+ /**
932
+ * Parse Loop
933
+ */
934
+
935
+ Parser.prototype.parse = function(src) {
936
+ this.inline = new InlineLexer(src.links, this.options, this.renderer);
937
+ this.tokens = src.reverse();
938
+
939
+ var out = '';
940
+ while (this.next()) {
941
+ out += this.tok();
942
+ }
943
+
944
+ return out;
945
+ };
946
+
947
+ /**
948
+ * Next Token
949
+ */
950
+
951
+ Parser.prototype.next = function() {
952
+ return this.token = this.tokens.pop();
953
+ };
954
+
955
+ /**
956
+ * Preview Next Token
957
+ */
958
+
959
+ Parser.prototype.peek = function() {
960
+ return this.tokens[this.tokens.length - 1] || 0;
961
+ };
962
+
963
+ /**
964
+ * Parse Text Tokens
965
+ */
966
+
967
+ Parser.prototype.parseText = function() {
968
+ var body = this.token.text;
969
+
970
+ while (this.peek().type === 'text') {
971
+ body += '\n' + this.next().text;
972
+ }
973
+
974
+ return this.inline.output(body);
975
+ };
976
+
977
+ /**
978
+ * Parse Current Token
979
+ */
980
+
981
+ Parser.prototype.tok = function() {
982
+ switch (this.token.type) {
983
+ case 'space': {
984
+ return '';
985
+ }
986
+ case 'hr': {
987
+ return this.renderer.hr();
988
+ }
989
+ case 'heading': {
990
+ return this.renderer.heading(
991
+ this.inline.output(this.token.text),
992
+ this.token.depth,
993
+ this.token.text);
994
+ }
995
+ case 'code': {
996
+ return this.renderer.code(this.token.text,
997
+ this.token.lang,
998
+ this.token.escaped);
999
+ }
1000
+ case 'table': {
1001
+ var header = ''
1002
+ , body = ''
1003
+ , i
1004
+ , row
1005
+ , cell
1006
+ , flags
1007
+ , j;
1008
+
1009
+ // header
1010
+ cell = '';
1011
+ for (i = 0; i < this.token.header.length; i++) {
1012
+ flags = { header: true, align: this.token.align[i] };
1013
+ cell += this.renderer.tablecell(
1014
+ this.inline.output(this.token.header[i]),
1015
+ { header: true, align: this.token.align[i] }
1016
+ );
1017
+ }
1018
+ header += this.renderer.tablerow(cell);
1019
+
1020
+ for (i = 0; i < this.token.cells.length; i++) {
1021
+ row = this.token.cells[i];
1022
+
1023
+ cell = '';
1024
+ for (j = 0; j < row.length; j++) {
1025
+ cell += this.renderer.tablecell(
1026
+ this.inline.output(row[j]),
1027
+ { header: false, align: this.token.align[j] }
1028
+ );
1029
+ }
1030
+
1031
+ body += this.renderer.tablerow(cell);
1032
+ }
1033
+ return this.renderer.table(header, body);
1034
+ }
1035
+ case 'blockquote_start': {
1036
+ var body = '';
1037
+
1038
+ while (this.next().type !== 'blockquote_end') {
1039
+ body += this.tok();
1040
+ }
1041
+
1042
+ return this.renderer.blockquote(body);
1043
+ }
1044
+ case 'list_start': {
1045
+ var body = ''
1046
+ , ordered = this.token.ordered;
1047
+
1048
+ while (this.next().type !== 'list_end') {
1049
+ body += this.tok();
1050
+ }
1051
+
1052
+ return this.renderer.list(body, ordered);
1053
+ }
1054
+ case 'list_item_start': {
1055
+ var body = '';
1056
+
1057
+ while (this.next().type !== 'list_item_end') {
1058
+ body += this.token.type === 'text'
1059
+ ? this.parseText()
1060
+ : this.tok();
1061
+ }
1062
+
1063
+ return this.renderer.listitem(body);
1064
+ }
1065
+ case 'loose_item_start': {
1066
+ var body = '';
1067
+
1068
+ while (this.next().type !== 'list_item_end') {
1069
+ body += this.tok();
1070
+ }
1071
+
1072
+ return this.renderer.listitem(body);
1073
+ }
1074
+ case 'html': {
1075
+ var html = !this.token.pre && !this.options.pedantic
1076
+ ? this.inline.output(this.token.text)
1077
+ : this.token.text;
1078
+ return this.renderer.html(html);
1079
+ }
1080
+ case 'paragraph': {
1081
+ return this.renderer.paragraph(this.inline.output(this.token.text));
1082
+ }
1083
+ case 'text': {
1084
+ return this.renderer.paragraph(this.parseText());
1085
+ }
1086
+ }
1087
+ };
1088
+
1089
+ /**
1090
+ * Helpers
1091
+ */
1092
+
1093
+ function escape(html, encode) {
1094
+ return html
1095
+ .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
1096
+ .replace(/</g, '&lt;')
1097
+ .replace(/>/g, '&gt;')
1098
+ .replace(/"/g, '&quot;')
1099
+ .replace(/'/g, '&#39;');
1100
+ }
1101
+
1102
+ function unescape(html) {
1103
+ return html.replace(/&([#\w]+);/g, function(_, n) {
1104
+ n = n.toLowerCase();
1105
+ if (n === 'colon') return ':';
1106
+ if (n.charAt(0) === '#') {
1107
+ return n.charAt(1) === 'x'
1108
+ ? String.fromCharCode(parseInt(n.substring(2), 16))
1109
+ : String.fromCharCode(+n.substring(1));
1110
+ }
1111
+ return '';
1112
+ });
1113
+ }
1114
+
1115
+ function replace(regex, opt) {
1116
+ regex = regex.source;
1117
+ opt = opt || '';
1118
+ return function self(name, val) {
1119
+ if (!name) return new RegExp(regex, opt);
1120
+ val = val.source || val;
1121
+ val = val.replace(/(^|[^\[])\^/g, '$1');
1122
+ regex = regex.replace(name, val);
1123
+ return self;
1124
+ };
1125
+ }
1126
+
1127
+ function noop() {}
1128
+ noop.exec = noop;
1129
+
1130
+ function merge(obj) {
1131
+ var i = 1
1132
+ , target
1133
+ , key;
1134
+
1135
+ for (; i < arguments.length; i++) {
1136
+ target = arguments[i];
1137
+ for (key in target) {
1138
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
1139
+ obj[key] = target[key];
1140
+ }
1141
+ }
1142
+ }
1143
+
1144
+ return obj;
1145
+ }
1146
+
1147
+
1148
+ /**
1149
+ * Marked
1150
+ */
1151
+
1152
+ function marked(src, opt, callback) {
1153
+ if (callback || typeof opt === 'function') {
1154
+ if (!callback) {
1155
+ callback = opt;
1156
+ opt = null;
1157
+ }
1158
+
1159
+ opt = merge({}, marked.defaults, opt || {});
1160
+
1161
+ var highlight = opt.highlight
1162
+ , tokens
1163
+ , pending
1164
+ , i = 0;
1165
+
1166
+ try {
1167
+ tokens = Lexer.lex(src, opt)
1168
+ } catch (e) {
1169
+ return callback(e);
1170
+ }
1171
+
1172
+ pending = tokens.length;
1173
+
1174
+ var done = function(err) {
1175
+ if (err) {
1176
+ opt.highlight = highlight;
1177
+ return callback(err);
1178
+ }
1179
+
1180
+ var out;
1181
+
1182
+ try {
1183
+ out = Parser.parse(tokens, opt);
1184
+ } catch (e) {
1185
+ err = e;
1186
+ }
1187
+
1188
+ opt.highlight = highlight;
1189
+
1190
+ return err
1191
+ ? callback(err)
1192
+ : callback(null, out);
1193
+ };
1194
+
1195
+ if (!highlight || highlight.length < 3) {
1196
+ return done();
1197
+ }
1198
+
1199
+ delete opt.highlight;
1200
+
1201
+ if (!pending) return done();
1202
+
1203
+ for (; i < tokens.length; i++) {
1204
+ (function(token) {
1205
+ if (token.type !== 'code') {
1206
+ return --pending || done();
1207
+ }
1208
+ return highlight(token.text, token.lang, function(err, code) {
1209
+ if (err) return done(err);
1210
+ if (code == null || code === token.text) {
1211
+ return --pending || done();
1212
+ }
1213
+ token.text = code;
1214
+ token.escaped = true;
1215
+ --pending || done();
1216
+ });
1217
+ })(tokens[i]);
1218
+ }
1219
+
1220
+ return;
1221
+ }
1222
+ try {
1223
+ if (opt) opt = merge({}, marked.defaults, opt);
1224
+ return Parser.parse(Lexer.lex(src, opt), opt);
1225
+ } catch (e) {
1226
+ e.message += '\nPlease report this to https://github.com/chjj/marked.';
1227
+ if ((opt || marked.defaults).silent) {
1228
+ return '<p>An error occured:</p><pre>'
1229
+ + escape(e.message + '', true)
1230
+ + '</pre>';
1231
+ }
1232
+ throw e;
1233
+ }
1234
+ }
1235
+
1236
+ /**
1237
+ * Options
1238
+ */
1239
+
1240
+ marked.options =
1241
+ marked.setOptions = function(opt) {
1242
+ merge(marked.defaults, opt);
1243
+ return marked;
1244
+ };
1245
+
1246
+ marked.defaults = {
1247
+ gfm: true,
1248
+ tables: true,
1249
+ breaks: false,
1250
+ pedantic: false,
1251
+ sanitize: false,
1252
+ sanitizer: null,
1253
+ mangle: true,
1254
+ smartLists: false,
1255
+ silent: false,
1256
+ highlight: null,
1257
+ langPrefix: 'lang-',
1258
+ smartypants: false,
1259
+ headerPrefix: '',
1260
+ renderer: new Renderer,
1261
+ xhtml: false
1262
+ };
1263
+
1264
+ /**
1265
+ * Expose
1266
+ */
1267
+
1268
+ marked.Parser = Parser;
1269
+ marked.parser = Parser.parse;
1270
+
1271
+ marked.Renderer = Renderer;
1272
+
1273
+ marked.Lexer = Lexer;
1274
+ marked.lexer = Lexer.lex;
1275
+
1276
+ marked.InlineLexer = InlineLexer;
1277
+ marked.inlineLexer = InlineLexer.output;
1278
+
1279
+ marked.parse = marked;
1280
+
1281
+ if (typeof module !== 'undefined' && typeof exports === 'object') {
1282
+ module.exports = marked;
1283
+ } else if (typeof define === 'function' && define.amd) {
1284
+ define(function() { return marked; });
1285
+ } else {
1286
+ this.marked = marked;
1287
+ }
1288
+
1289
+ }).call(function() {
1290
+ return this || (typeof window !== 'undefined' ? window : global);
1291
+ }());