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

- old
+ new

@@ -674,11 +674,11 @@ } // text if (cap = this.rules.text.exec(src)) { src = src.substring(cap[0].length); - out += escape(cap[0]); + out += escape(this.smartypants(cap[0])); continue; } if (src) { throw new @@ -726,14 +726,14 @@ */ InlineLexer.prototype.smartypants = function(text) { if (!this.options.smartypants) return text; return text - .replace(/--/g, '—') - .replace(/'([^']*)'/g, '‘$1’') - .replace(/"([^"]*)"/g, '“$1”') - .replace(/\.{3}/g, '…'); + .replace(/--/g, '\u2014') + .replace(/'([^']*)'/g, '\u2018$1\u2019') + .replace(/"([^"]*)"/g, '\u201C$1\u201D') + .replace(/\.{3}/g, '\u2026'); }; /** * Mangle Links */ @@ -1027,31 +1027,54 @@ opt = null; } if (opt) opt = merge({}, marked.defaults, opt); - var tokens = Lexer.lex(tokens, opt) - , highlight = opt.highlight - , pending = 0 - , l = tokens.length + var highlight = opt.highlight + , tokens + , pending , i = 0; - if (!highlight || highlight.length < 3) { - return callback(null, Parser.parse(tokens, opt)); + try { + tokens = Lexer.lex(src, opt) + } catch (e) { + return callback(e); } - var done = function() { - delete opt.highlight; - var out = Parser.parse(tokens, opt); + pending = tokens.length; + + var done = function(hi) { + var out, err; + + if (hi !== true) { + delete opt.highlight; + } + + try { + out = Parser.parse(tokens, opt); + } catch (e) { + err = e; + } + opt.highlight = highlight; - return callback(null, out); + + return err + ? callback(err) + : callback(null, out); }; - for (; i < l; i++) { + if (!highlight || highlight.length < 3) { + return done(true); + } + + if (!pending) return done(); + + for (; i < tokens.length; i++) { (function(token) { - if (token.type !== 'code') return; - pending++; + if (token.type !== 'code') { + return --pending || done(); + } return highlight(token.text, token.lang, function(err, code) { if (code == null || code === token.text) { return --pending || done(); } token.text = code; @@ -1094,11 +1117,12 @@ pedantic: false, sanitize: false, smartLists: false, silent: false, highlight: null, - langPrefix: 'lang-' + langPrefix: 'lang-', + smartypants: false }; /** * Expose */ @@ -1122,6 +1146,6 @@ this.marked = marked; } }).call(function() { return this || (typeof window !== 'undefined' ? window : global); -}()); +}()); \ No newline at end of file