From 079cbe8b6ac9edfc80f41d5e69faf0a19d686249 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 3 Jan 2013 01:06:58 -0600 Subject: [PATCH] small refactor. --- lib/marked.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index e43095b0..ee39cdec 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -89,11 +89,11 @@ Lexer.lex = function(src, options) { }; Lexer.prototype.lex = function(src) { - this.src = src + src = src .replace(/\r\n|\r/g, '\n') .replace(/\t/g, ' '); - return this.token(this.src, true); + return this.token(src, true); }; Lexer.prototype.token = function(src, top) { @@ -562,9 +562,6 @@ Parser.prototype.parse = function(src) { out += this.tok(); } - this.tokens = []; - this.token = null; - return out; }; @@ -572,12 +569,14 @@ Parser.prototype.next = function() { return this.token = this.tokens.pop(); }; -Parser.prototype.parseText = function() { - var body = this.token.text - , top; +Parser.prototype.peek = function() { + return this.tokens[this.tokens.length-1] || 0; +}; - while ((top = this.tokens[this.tokens.length-1]) - && top.type === 'text') { +Parser.prototype.parseText = function() { + var body = this.token.text; + + while (this.peek().type === 'text') { body += '\n' + this.next().text; }