add gfm code blocks

This commit is contained in:
Christopher Jeffrey 2012-01-02 04:10:23 -06:00
parent f43be5e5e0
commit a6a3239df8

View File

@ -12,6 +12,7 @@
var block = {
newline: /^\n+/,
code: /^ {4,}[^\n]*(?:\n {4,}[^\n]*|\n)*(?=\n| *$)/,
gfm_code: /^ *``` *(\w+)? *\n([^\0]+?)\s*```(?= *\n| *$)/,
hr: /^( *[\-*_]){3,} *\n/,
heading: /^ *(#{1,6}) *([^\0]+?) *#* *\n+/,
lheading: /^([^\n]+)\n *(=|-){3,}/,
@ -82,6 +83,17 @@ block.token = function(str, tokens) {
continue;
}
// gfm_code
if (cap = block.gfm_code.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'code',
lang: cap[1],
text: cap[2]
});
continue;
}
// heading
if (cap = block.heading.exec(str)) {
str = str.substring(cap[0].length);