vendor/assets/javascripts/marked.js in marked-rails-0.0.5 vs vendor/assets/javascripts/marked.js in marked-rails-0.2.8.0

- old
+ new

@@ -19,13 +19,13 @@ nptable: noop, lheading: /^([^\n]+)\n *(=|-){3,} *\n*/, blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/, list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/, - def: /^ *\[([^\]]+)\]: *([^\s]+)(?: +["(]([^\n]+)[")])? *(?:\n+|$)/, + def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/, table: noop, - paragraph: /^([^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+\n*/, + paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/, text: /^[^\n]+/ }; block.bullet = /(?:[*+-]|\d+\.)/; block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/; @@ -68,11 +68,11 @@ /** * GFM Block Grammar */ block.gfm = merge({}, block.normal, { - fences: /^ *(`{3,}|~{3,}) *(\w+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/, + fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/, paragraph: /^/ }); block.gfm.paragraph = replace(block.paragraph) ('(?!', '(?!' + block.gfm.fences.source.replace('\\1', '\\2') + '|') @@ -142,10 +142,12 @@ Lexer.prototype.token = function(src, top) { var src = src.replace(/^ +$/gm, '') , next , loose , cap + , bull + , b , item , space , i , l; @@ -270,14 +272,15 @@ } // list if (cap = this.rules.list.exec(src)) { src = src.substring(cap[0].length); + bull = cap[2]; this.tokens.push({ type: 'list_start', - ordered: isFinite(cap[2]) + ordered: bull.length > 1 }); // Get each top-level item. cap = cap[0].match(this.rules.item); @@ -300,10 +303,20 @@ item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, ''); } + // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + if (this.options.smartLists && i !== l - 1) { + b = block.bullet.exec(cap[i+1])[0]; + if (bull !== b && !(bull.length > 1 && b.length > 1)) { + src = cap.slice(i + 1).join('\n') + src; + i = l - 1; + } + } + // Determine whether item is loose or not. // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ // for discount behavior. loose = next || /\n\n(?!\s*$)/.test(item); if (i !== l - 1) { @@ -337,11 +350,11 @@ src = src.substring(cap[0].length); this.tokens.push({ type: this.options.sanitize ? 'paragraph' : 'html', - pre: cap[1] === 'pre', + pre: cap[1] === 'pre' || cap[1] === 'script', text: cap[0] }); continue; } @@ -392,11 +405,13 @@ // top-level paragraph if (top && (cap = this.rules.paragraph.exec(src))) { src = src.substring(cap[0].length); this.tokens.push({ type: 'paragraph', - text: cap[0] + text: cap[1][cap[1].length-1] === '\n' + ? cap[1].slice(0, -1) + : cap[1] }); continue; } // text @@ -422,20 +437,20 @@ /** * Inline-Level Grammar */ var inline = { - escape: /^\\([\\`*{}\[\]()#+\-.!_>|])/, + escape: /^\\([\\`*{}\[\]()#+\-.!_>])/, autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, url: noop, tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/, link: /^!?\[(inside)\]\(href\)/, reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, - code: /^(`+)([\s\S]*?[^`])\1(?!`)/, + code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/, br: /^ {2,}\n(?!\s*$)/, del: noop, text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/ }; @@ -469,13 +484,13 @@ /** * GFM Inline Grammar */ inline.gfm = merge({}, inline.normal, { - escape: replace(inline.escape)('])', '~])')(), - url: /^(https?:\/\/[^\s]+[^.,:;"')\]\s])/, - del: /^~{2,}([\s\S]+?)~{2,}/, + escape: replace(inline.escape)('])', '~|])')(), + url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/, + del: /^~~(?=\S)([\s\S]*?\S)~~/, text: replace(inline.text) (']|', '~]|') ('|', '|https?://|') () }); @@ -522,12 +537,12 @@ /** * Static Lexing/Compiling Method */ -InlineLexer.output = function(src, links, opt) { - var inline = new InlineLexer(links, opt); +InlineLexer.output = function(src, links, options) { + var inline = new InlineLexer(links, options); return inline.output(src); }; /** * Lexing/Compiling @@ -705,10 +720,23 @@ + '>'; } }; /** + * Smartypants Transformations + */ + +InlineLexer.prototype.smartypants = function(text) { + if (!this.options.smartypants) return text; + return text + .replace(/--/g, '—') + .replace(/'([^']*)'/g, '‘$1’') + .replace(/"([^"]*)"/g, '“$1”') + .replace(/\.{3}/g, '…'); +}; + +/** * Mangle Links */ InlineLexer.prototype.mangle = function(text) { var out = '' @@ -826,11 +854,12 @@ this.token.text = escape(this.token.text, true); } return '<pre><code' + (this.token.lang - ? ' class="lang-' + ? ' class="' + + this.options.langPrefix + this.token.lang + '"' : '') + '>' + this.token.text @@ -989,17 +1018,62 @@ /** * Marked */ -function marked(src, opt) { +function marked(src, opt, callback) { + if (callback || typeof opt === 'function') { + if (!callback) { + callback = opt; + opt = null; + } + + if (opt) opt = merge({}, marked.defaults, opt); + + var tokens = Lexer.lex(tokens, opt) + , highlight = opt.highlight + , pending = 0 + , l = tokens.length + , i = 0; + + if (!highlight || highlight.length < 3) { + return callback(null, Parser.parse(tokens, opt)); + } + + var done = function() { + delete opt.highlight; + var out = Parser.parse(tokens, opt); + opt.highlight = highlight; + return callback(null, out); + }; + + for (; i < l; i++) { + (function(token) { + if (token.type !== 'code') return; + pending++; + return highlight(token.text, token.lang, function(err, code) { + if (code == null || code === token.text) { + return --pending || done(); + } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } + + return; + } try { + if (opt) opt = merge({}, marked.defaults, opt); return Parser.parse(Lexer.lex(src, opt), opt); } catch (e) { e.message += '\nPlease report this to https://github.com/chjj/marked.'; if ((opt || marked.defaults).silent) { - return 'An error occured:\n' + e.message; + return '<p>An error occured:</p><pre>' + + escape(e.message + '', true) + + '</pre>'; } throw e; } } @@ -1007,22 +1081,24 @@ * Options */ marked.options = marked.setOptions = function(opt) { - marked.defaults = opt; + merge(marked.defaults, opt); return marked; }; marked.defaults = { gfm: true, tables: true, breaks: false, pedantic: false, sanitize: false, + smartLists: false, silent: false, - highlight: null + highlight: null, + langPrefix: 'lang-' }; /** * Expose */ @@ -1036,10 +1112,10 @@ marked.InlineLexer = InlineLexer; marked.inlineLexer = InlineLexer.output; marked.parse = marked; -if (typeof module !== 'undefined') { +if (typeof exports === 'object') { module.exports = marked; } else if (typeof define === 'function' && define.amd) { define(function() { return marked; }); } else { this.marked = marked;