Merge branch 'text_blocks'
This commit is contained in:
commit
783eede3ed
@ -41,12 +41,9 @@ block.lexer = function(str) {
|
|||||||
var tokens = []
|
var tokens = []
|
||||||
, links = {};
|
, links = {};
|
||||||
|
|
||||||
// normalize whitespace
|
str = str.replace(/\r\n|\r/g, '\n')
|
||||||
str = str.replace(/\r\n/g, '\n')
|
|
||||||
.replace(/\r/g, '\n')
|
|
||||||
.replace(/\t/g, ' ');
|
.replace(/\t/g, ' ');
|
||||||
|
|
||||||
// grab link definitons
|
|
||||||
str = str.replace(
|
str = str.replace(
|
||||||
/^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +"([^\n]+)")? *$/gm,
|
/^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +"([^\n]+)")? *$/gm,
|
||||||
function(__, id, href, title) {
|
function(__, id, href, title) {
|
||||||
@ -380,52 +377,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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user