better recursion?
This commit is contained in:
parent
2f6396e217
commit
a2cccfaf1d
@ -32,32 +32,7 @@ var links;
|
||||
* Lexer
|
||||
*/
|
||||
|
||||
var lex = function(str) {
|
||||
var tokens = []
|
||||
, line = 0;
|
||||
|
||||
// normalize whitespace
|
||||
str = str.replace(/\r\n/g, '\n')
|
||||
.replace(/\r/g, '\n');
|
||||
|
||||
str = str.replace(/\t/g, ' ');
|
||||
//str = str.replace(/(^|\n) +(\n|$)/g, '$1$2');
|
||||
|
||||
// unfortunately, this is the most
|
||||
// performant method of getting link
|
||||
// definitions out of the way.
|
||||
links = {};
|
||||
str = str.replace(
|
||||
/^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +"([^"]+)")?/gm,
|
||||
function(_, id, href, title) {
|
||||
links[id] = {
|
||||
href: href,
|
||||
title: title
|
||||
};
|
||||
return '';
|
||||
});
|
||||
|
||||
(function lex(str) {
|
||||
var lex_ = function lex(str, tokens, line) {
|
||||
var i
|
||||
, key
|
||||
, rule;
|
||||
@ -134,7 +109,7 @@ var lex = function(str) {
|
||||
type: 'list_item_start',
|
||||
line: line
|
||||
});
|
||||
lex(item, tokens);
|
||||
lex(item, tokens, line);
|
||||
tokens.push({
|
||||
type: 'list_item_end',
|
||||
line: line
|
||||
@ -159,7 +134,7 @@ var lex = function(str) {
|
||||
line: line
|
||||
});
|
||||
cap = cap[0].replace(/^ *>/gm, '');
|
||||
lex(cap, tokens);
|
||||
lex(cap, tokens, line);
|
||||
tokens.push({
|
||||
type: 'blockquote_end',
|
||||
line: line
|
||||
@ -168,7 +143,34 @@ var lex = function(str) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
})(str);
|
||||
};
|
||||
|
||||
var lex = function(str) {
|
||||
var tokens = []
|
||||
, line = 0;
|
||||
|
||||
// normalize whitespace
|
||||
str = str.replace(/\r\n/g, '\n')
|
||||
.replace(/\r/g, '\n');
|
||||
|
||||
str = str.replace(/\t/g, ' ');
|
||||
//str = str.replace(/(^|\n) +(\n|$)/g, '$1$2');
|
||||
|
||||
// unfortunately, this is the most
|
||||
// performant method of getting link
|
||||
// definitions out of the way.
|
||||
links = {};
|
||||
str = str.replace(
|
||||
/^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +"([^"]+)")?/gm,
|
||||
function(_, id, href, title) {
|
||||
links[id] = {
|
||||
href: href,
|
||||
title: title
|
||||
};
|
||||
return '';
|
||||
});
|
||||
|
||||
lex_(str, tokens, line);
|
||||
|
||||
return tokens;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user