Skip to content

Commit

Permalink
Updated marked.js to latest version: markedjs/marked@31c50a9 (v0.2.9)…
Browse files Browse the repository at this point in the history
…. This gives "smartypants" support: three dots to ellipsis, two dashes to m-dash, plain single- and double-quotes to curly ones.
  • Loading branch information
adam-p committed Jun 6, 2013
1 parent 41f78ae commit 5cd48eb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/common/markdown-render.js
Expand Up @@ -46,6 +46,7 @@
tables: true,
smartLists: true,
breaks: true,
smartypants: true,
langPrefix: 'language-',
math: userprefs['math-enabled'] ? mathify : null,
highlight: function(codeText, codeLanguage) {
Expand Down
99 changes: 87 additions & 12 deletions src/common/marked.js 100644 → 100755
Expand Up @@ -70,7 +70,7 @@ block.normal = merge({}, block);
*/

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: /^/
});

Expand Down Expand Up @@ -274,20 +274,16 @@ Lexer.prototype.token = function(src, top) {
// 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);

// Get bullet.
if (this.options.smartLists) {
bull = block.bullet.exec(cap[0])[0];
}

next = false;
l = cap.length;
i = 0;
Expand All @@ -313,7 +309,7 @@ Lexer.prototype.token = function(src, top) {
// 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[1] === '.' && b[1] === '.')) {
if (bull !== b && !(bull.length > 1 && b.length > 1)) {
src = cap.slice(i + 1).join('\n') + src;
i = l - 1;
}
Expand Down Expand Up @@ -356,7 +352,7 @@ Lexer.prototype.token = function(src, top) {
type: this.options.sanitize
? 'paragraph'
: 'html',
pre: cap[1] === 'pre',
pre: cap[1] === 'pre' || cap[1] === 'script',
text: cap[0]
});
continue;
Expand Down Expand Up @@ -691,7 +687,7 @@ InlineLexer.prototype.output = function(src) {
// 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;
}

Expand Down Expand Up @@ -736,6 +732,19 @@ InlineLexer.prototype.outputLink = function(cap, link) {
}
};

/**
* Smartypants Transformations
*/

InlineLexer.prototype.smartypants = function(text) {
if (!this.options.smartypants) return text;
return text
.replace(/--/g, '\u2014')
.replace(/'([^']*)'/g, '\u2018$1\u2019')
.replace(/"([^"]*)"/g, '\u201C$1\u201D')
.replace(/\.{3}/g, '\u2026');
};

/**
* Mangle Links
*/
Expand Down Expand Up @@ -1022,7 +1031,72 @@ function merge(obj) {
* 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 highlight = opt.highlight
, tokens
, pending
, i = 0;

try {
tokens = Lexer.lex(src, opt)
} catch (e) {
return callback(e);
}

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 err
? callback(err)
: callback(null, out);
};

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 || done();
}
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);
Expand Down Expand Up @@ -1056,7 +1130,8 @@ marked.defaults = {
smartLists: false,
silent: false,
highlight: null,
langPrefix: 'lang-'
langPrefix: 'lang-',
smartypants: false
};

/**
Expand Down

0 comments on commit 5cd48eb

Please sign in to comment.