|
@ -32,10 +32,39 @@ Parser.prototype.set = function (options) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parser.prototype.render = function (src) { |
|
|
Parser.prototype.render = function (src) { |
|
|
var state; |
|
|
var state, lineStart = 0, lastTabPos = 0; |
|
|
|
|
|
|
|
|
if (!src) { return ''; } |
|
|
if (!src) { return ''; } |
|
|
|
|
|
|
|
|
|
|
|
if (src.indexOf('\r') >= 0) { |
|
|
|
|
|
src = src.replace(/\r/, ''); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (src.indexOf('\u00a0') >= 0) { |
|
|
|
|
|
src = src.replace(/\u00a0/g, ' '); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (src.indexOf('\u2424') >= 0) { |
|
|
|
|
|
src = src.replace(/\u2424/g, '\n'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: benchmark it
|
|
|
|
|
|
// Replace tabs with proper number of spaces (1..4)
|
|
|
|
|
|
if (src.indexOf('\t') >= 0) { |
|
|
|
|
|
src = src.replace(/[\n\t]/g, function (match, offset) { |
|
|
|
|
|
var result; |
|
|
|
|
|
if (src.charCodeAt(offset) === 0x0A) { |
|
|
|
|
|
lineStart = offset + 1; |
|
|
|
|
|
lastTabPos = 0; |
|
|
|
|
|
return match; |
|
|
|
|
|
} |
|
|
|
|
|
result = ' '.slice((offset - lineStart - lastTabPos) % 4); |
|
|
|
|
|
lastTabPos = offset - lineStart + 1; |
|
|
|
|
|
return result; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state = new State( |
|
|
state = new State( |
|
|
src, |
|
|
src, |
|
|
this.lexerBlock, |
|
|
this.lexerBlock, |
|
|