whitespace, comments

This commit is contained in:
Christopher Jeffrey 2011-10-22 23:39:04 -05:00
parent 9d370fb8c3
commit e482c752ad

View File

@ -22,7 +22,7 @@ var block = {
};
/**
* Lexer
* Block Lexer
*/
block.lexer = function(str) {
@ -58,6 +58,7 @@ block.token = function(str, tokens) {
, l;
while (str) {
// newline
if (cap = block.newline.exec(str)) {
str = str.substring(cap[0].length);
if (cap[0].length > 1) {
@ -68,6 +69,7 @@ block.token = function(str, tokens) {
continue;
}
// code
if (cap = block.code.exec(str)) {
str = str.substring(cap[0].length);
cap = cap[0].replace(/^ {4}/gm, '');
@ -78,6 +80,7 @@ block.token = function(str, tokens) {
continue;
}
// heading
if (cap = block.heading.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
@ -88,6 +91,7 @@ block.token = function(str, tokens) {
continue;
}
// lheading
if (cap = block.lheading.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
@ -98,6 +102,7 @@ block.token = function(str, tokens) {
continue;
}
// hr
if (cap = block.hr.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
@ -106,6 +111,7 @@ block.token = function(str, tokens) {
continue;
}
// blockquote
if (cap = block.blockquote.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
@ -119,6 +125,7 @@ block.token = function(str, tokens) {
continue;
}
// list
if (cap = block.list.exec(str)) {
str = str.substring(cap[0].length);
@ -134,7 +141,8 @@ block.token = function(str, tokens) {
/^( *)([*+-]|\d+\.)[^\n]*(?:\n(?!\1(?:\2|\d+\.))[^\n]*)*/gm
);
i = 0, l = cap.length;
i = 0;
l = cap.length;
for (; i < l; i++) {
// remove the list items sigil
@ -165,6 +173,7 @@ block.token = function(str, tokens) {
continue;
}
// html
if (cap = block.html.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
@ -174,6 +183,7 @@ block.token = function(str, tokens) {
continue;
}
// text
if (cap = block.text.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
@ -239,12 +249,14 @@ inline.lexer = function(str) {
, cap;
while (str) {
// escape
if (cap = inline.escape.exec(str)) {
str = str.substring(cap[0].length);
out += cap[1];
continue;
}
// autolink
if (cap = inline.autolink.exec(str)) {
str = str.substring(cap[0].length);
if (cap[2] === '@') {
@ -264,12 +276,14 @@ inline.lexer = function(str) {
continue;
}
// tag
if (cap = inline.tag.exec(str)) {
str = str.substring(cap[0].length);
out += cap[0];
continue;
}
// link
if (cap = inline.link.exec(str)) {
str = str.substring(cap[0].length);
text = /^\s*<?([^\s]*?)>?(?:\s+"([^\n]+)")?\s*$/.exec(cap[2]);
@ -281,6 +295,7 @@ inline.lexer = function(str) {
continue;
}
// reflink, nolink
if ((cap = inline.reflink.exec(str))
|| (cap = inline.nolink.exec(str))) {
str = str.substring(cap[0].length);
@ -295,6 +310,7 @@ inline.lexer = function(str) {
continue;
}
// strong
if (cap = inline.strong.exec(str)) {
str = str.substring(cap[0].length);
out += '<strong>'
@ -303,6 +319,7 @@ inline.lexer = function(str) {
continue;
}
// em
if (cap = inline.em.exec(str)) {
str = str.substring(cap[0].length);
out += '<em>'
@ -311,6 +328,7 @@ inline.lexer = function(str) {
continue;
}
// code
if (cap = inline.code.exec(str)) {
str = str.substring(cap[0].length);
out += '<code>'
@ -319,12 +337,14 @@ inline.lexer = function(str) {
continue;
}
// br
if (cap = inline.br.exec(str)) {
str = str.substring(cap[0].length);
out += '<br>';
continue;
}
// text
if (cap = inline.text.exec(str)) {
str = str.substring(cap[0].length);
out += escape(cap[0]);
@ -379,11 +399,9 @@ var tok = function() {
case 'space': {
return '';
}
case 'hr': {
return '<hr>';
}
case 'heading': {
return '<h'
+ token.depth
@ -393,13 +411,11 @@ var tok = function() {
+ token.depth
+ '>';
}
case 'code': {
return '<pre><code>'
+ escape(token.text)
+ '</code></pre>';
}
case 'blockquote_start': {
var body = [];
@ -411,7 +427,6 @@ var tok = function() {
+ body.join('')
+ '</blockquote>';
}
case 'list_start': {
var type = token.ordered ? 'ol' : 'ul'
, body = [];
@ -428,7 +443,6 @@ var tok = function() {
+ type
+ '>';
}
case 'list_item_start': {
var body = [];
@ -442,7 +456,6 @@ var tok = function() {
+ body.join(' ')
+ '</li>';
}
case 'loose_item_start': {
var body = [];
@ -454,11 +467,9 @@ var tok = function() {
+ body.join(' ')
+ '</li>';
}
case 'html': {
return inline.lexer(token.text);
}
case 'text': {
return '<p>'
+ text()