marked-rails 0.0.5 → 0.2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module Marked
2
2
  module Rails
3
- VERSION = "0.0.5"
3
+ VERSION = "0.2.8.0"
4
4
  end
5
5
  end
@@ -21,9 +21,9 @@ var block = {
21
21
  blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/,
22
22
  list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
23
23
  html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,
24
- def: /^ *\[([^\]]+)\]: *([^\s]+)(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
24
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
25
25
  table: noop,
26
- paragraph: /^([^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+\n*/,
26
+ paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
27
27
  text: /^[^\n]+/
28
28
  };
29
29
 
@@ -70,7 +70,7 @@ block.normal = merge({}, block);
70
70
  */
71
71
 
72
72
  block.gfm = merge({}, block.normal, {
73
- fences: /^ *(`{3,}|~{3,}) *(\w+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,
73
+ fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,
74
74
  paragraph: /^/
75
75
  });
76
76
 
@@ -144,6 +144,8 @@ Lexer.prototype.token = function(src, top) {
144
144
  , next
145
145
  , loose
146
146
  , cap
147
+ , bull
148
+ , b
147
149
  , item
148
150
  , space
149
151
  , i
@@ -272,10 +274,11 @@ Lexer.prototype.token = function(src, top) {
272
274
  // list
273
275
  if (cap = this.rules.list.exec(src)) {
274
276
  src = src.substring(cap[0].length);
277
+ bull = cap[2];
275
278
 
276
279
  this.tokens.push({
277
280
  type: 'list_start',
278
- ordered: isFinite(cap[2])
281
+ ordered: bull.length > 1
279
282
  });
280
283
 
281
284
  // Get each top-level item.
@@ -302,6 +305,16 @@ Lexer.prototype.token = function(src, top) {
302
305
  : item.replace(/^ {1,4}/gm, '');
303
306
  }
304
307
 
308
+ // Determine whether the next list item belongs here.
309
+ // Backpedal if it does not belong in this list.
310
+ if (this.options.smartLists && i !== l - 1) {
311
+ b = block.bullet.exec(cap[i+1])[0];
312
+ if (bull !== b && !(bull.length > 1 && b.length > 1)) {
313
+ src = cap.slice(i + 1).join('\n') + src;
314
+ i = l - 1;
315
+ }
316
+ }
317
+
305
318
  // Determine whether item is loose or not.
306
319
  // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
307
320
  // for discount behavior.
@@ -339,7 +352,7 @@ Lexer.prototype.token = function(src, top) {
339
352
  type: this.options.sanitize
340
353
  ? 'paragraph'
341
354
  : 'html',
342
- pre: cap[1] === 'pre',
355
+ pre: cap[1] === 'pre' || cap[1] === 'script',
343
356
  text: cap[0]
344
357
  });
345
358
  continue;
@@ -394,7 +407,9 @@ Lexer.prototype.token = function(src, top) {
394
407
  src = src.substring(cap[0].length);
395
408
  this.tokens.push({
396
409
  type: 'paragraph',
397
- text: cap[0]
410
+ text: cap[1][cap[1].length-1] === '\n'
411
+ ? cap[1].slice(0, -1)
412
+ : cap[1]
398
413
  });
399
414
  continue;
400
415
  }
@@ -424,7 +439,7 @@ Lexer.prototype.token = function(src, top) {
424
439
  */
425
440
 
426
441
  var inline = {
427
- escape: /^\\([\\`*{}\[\]()#+\-.!_>|])/,
442
+ escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
428
443
  autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
429
444
  url: noop,
430
445
  tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
@@ -433,7 +448,7 @@ var inline = {
433
448
  nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
434
449
  strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
435
450
  em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
436
- code: /^(`+)([\s\S]*?[^`])\1(?!`)/,
451
+ code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
437
452
  br: /^ {2,}\n(?!\s*$)/,
438
453
  del: noop,
439
454
  text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
@@ -471,9 +486,9 @@ inline.pedantic = merge({}, inline.normal, {
471
486
  */
472
487
 
473
488
  inline.gfm = merge({}, inline.normal, {
474
- escape: replace(inline.escape)('])', '~])')(),
475
- url: /^(https?:\/\/[^\s]+[^.,:;"')\]\s])/,
476
- del: /^~{2,}([\s\S]+?)~{2,}/,
489
+ escape: replace(inline.escape)('])', '~|])')(),
490
+ url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
491
+ del: /^~~(?=\S)([\s\S]*?\S)~~/,
477
492
  text: replace(inline.text)
478
493
  (']|', '~]|')
479
494
  ('|', '|https?://|')
@@ -524,8 +539,8 @@ InlineLexer.rules = inline;
524
539
  * Static Lexing/Compiling Method
525
540
  */
526
541
 
527
- InlineLexer.output = function(src, links, opt) {
528
- var inline = new InlineLexer(links, opt);
542
+ InlineLexer.output = function(src, links, options) {
543
+ var inline = new InlineLexer(links, options);
529
544
  return inline.output(src);
530
545
  };
531
546
 
@@ -706,6 +721,19 @@ InlineLexer.prototype.outputLink = function(cap, link) {
706
721
  }
707
722
  };
708
723
 
724
+ /**
725
+ * Smartypants Transformations
726
+ */
727
+
728
+ InlineLexer.prototype.smartypants = function(text) {
729
+ if (!this.options.smartypants) return text;
730
+ return text
731
+ .replace(/--/g, '—')
732
+ .replace(/'([^']*)'/g, '‘$1’')
733
+ .replace(/"([^"]*)"/g, '“$1”')
734
+ .replace(/\.{3}/g, '…');
735
+ };
736
+
709
737
  /**
710
738
  * Mangle Links
711
739
  */
@@ -828,7 +856,8 @@ Parser.prototype.tok = function() {
828
856
 
829
857
  return '<pre><code'
830
858
  + (this.token.lang
831
- ? ' class="lang-'
859
+ ? ' class="'
860
+ + this.options.langPrefix
832
861
  + this.token.lang
833
862
  + '"'
834
863
  : '')
@@ -991,13 +1020,58 @@ function merge(obj) {
991
1020
  * Marked
992
1021
  */
993
1022
 
994
- function marked(src, opt) {
1023
+ function marked(src, opt, callback) {
1024
+ if (callback || typeof opt === 'function') {
1025
+ if (!callback) {
1026
+ callback = opt;
1027
+ opt = null;
1028
+ }
1029
+
1030
+ if (opt) opt = merge({}, marked.defaults, opt);
1031
+
1032
+ var tokens = Lexer.lex(tokens, opt)
1033
+ , highlight = opt.highlight
1034
+ , pending = 0
1035
+ , l = tokens.length
1036
+ , i = 0;
1037
+
1038
+ if (!highlight || highlight.length < 3) {
1039
+ return callback(null, Parser.parse(tokens, opt));
1040
+ }
1041
+
1042
+ var done = function() {
1043
+ delete opt.highlight;
1044
+ var out = Parser.parse(tokens, opt);
1045
+ opt.highlight = highlight;
1046
+ return callback(null, out);
1047
+ };
1048
+
1049
+ for (; i < l; i++) {
1050
+ (function(token) {
1051
+ if (token.type !== 'code') return;
1052
+ pending++;
1053
+ return highlight(token.text, token.lang, function(err, code) {
1054
+ if (code == null || code === token.text) {
1055
+ return --pending || done();
1056
+ }
1057
+ token.text = code;
1058
+ token.escaped = true;
1059
+ --pending || done();
1060
+ });
1061
+ })(tokens[i]);
1062
+ }
1063
+
1064
+ return;
1065
+ }
995
1066
  try {
1067
+ if (opt) opt = merge({}, marked.defaults, opt);
996
1068
  return Parser.parse(Lexer.lex(src, opt), opt);
997
1069
  } catch (e) {
998
1070
  e.message += '\nPlease report this to https://github.com/chjj/marked.';
999
1071
  if ((opt || marked.defaults).silent) {
1000
- return 'An error occured:\n' + e.message;
1072
+ return '<p>An error occured:</p><pre>'
1073
+ + escape(e.message + '', true)
1074
+ + '</pre>';
1001
1075
  }
1002
1076
  throw e;
1003
1077
  }
@@ -1009,7 +1083,7 @@ function marked(src, opt) {
1009
1083
 
1010
1084
  marked.options =
1011
1085
  marked.setOptions = function(opt) {
1012
- marked.defaults = opt;
1086
+ merge(marked.defaults, opt);
1013
1087
  return marked;
1014
1088
  };
1015
1089
 
@@ -1019,8 +1093,10 @@ marked.defaults = {
1019
1093
  breaks: false,
1020
1094
  pedantic: false,
1021
1095
  sanitize: false,
1096
+ smartLists: false,
1022
1097
  silent: false,
1023
- highlight: null
1098
+ highlight: null,
1099
+ langPrefix: 'lang-'
1024
1100
  };
1025
1101
 
1026
1102
  /**
@@ -1038,7 +1114,7 @@ marked.inlineLexer = InlineLexer.output;
1038
1114
 
1039
1115
  marked.parse = marked;
1040
1116
 
1041
- if (typeof module !== 'undefined') {
1117
+ if (typeof exports === 'object') {
1042
1118
  module.exports = marked;
1043
1119
  } else if (typeof define === 'function' && define.amd) {
1044
1120
  define(function() { return marked; });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marked-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.2.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-08 00:00:00.000000000 Z
13
+ date: 2013-03-26 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: ! 'A gemified verison of the chjj/marked: "A full-featured markdown parser
16
16
  and compiler, written in javascript."'
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 1.8.10
53
+ rubygems_version: 1.8.24
54
54
  signing_key:
55
55
  specification_version: 3
56
56
  summary: A gemified verison of the chjj/marked