text block function

This commit is contained in:
Christopher Jeffrey 2011-10-04 17:32:59 -05:00
parent 9527426b65
commit 70da22d078

View File

@ -380,52 +380,64 @@ var tok = function() {
+ '</code></pre>'; + '</code></pre>';
case 'blockquote_start': case 'blockquote_start':
var body = []; var body = [];
while (next().type !== 'blockquote_end') { while (next().type !== 'blockquote_end') {
body.push(tok()); body.push(tok());
} }
return '<blockquote>' return '<blockquote>'
+ body.join('') + body.join('')
+ '</blockquote>'; + '</blockquote>';
case 'list_start': case 'list_start':
var body = [] var type = token.ordered ? 'ol' : 'ul'
, type = token.ordered ? 'ol' : 'ul'; , body = [];
while (next().type !== 'list_end') { while (next().type !== 'list_end') {
body.push(tok()); body.push(tok());
} }
return '<' + type + '>' return '<' + type + '>'
+ body.join('') + body.join('')
+ '</' + type + '>'; + '</' + type + '>';
case 'list_item_start': case 'list_item_start':
var body = []; var body = [];
while (next().type !== 'list_item_end') { while (next().type !== 'list_item_end') {
body.push(token.type === 'text' body.push(token.type === 'text'
? inline.lexer(token.text) ? text()
: tok()); : tok());
} }
return '<li>' return '<li>'
+ body.join(' ') + body.join(' ')
+ '</li>'; + '</li>';
case 'loose_item_start': case 'loose_item_start':
var body = []; var body = [];
while (next().type !== 'list_item_end') { while (next().type !== 'list_item_end') {
body.push(tok()); body.push(tok());
} }
return '<li>' return '<li>'
+ body.join(' ') + body.join(' ')
+ '</li>'; + '</li>';
case 'html': case 'html':
return inline.lexer(token.text); return inline.lexer(token.text);
case 'text': case 'text':
return '<p>' + text() + '</p>';
}
};
var text = function() {
var body = [ token.text ] var body = [ token.text ]
, top; , top;
while ((top = tokens[tokens.length-1]) while ((top = tokens[tokens.length-1])
&& top.type === 'text') { && top.type === 'text') {
body.push(next().text); body.push(next().text);
} }
return '<p>'
+ inline.lexer(body.join('\n')) return inline.lexer(body.join('\n'));
+ '</p>';
}
}; };
var parse = function(src) { var parse = function(src) {