|
|
@ -104,23 +104,24 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
var TABS_SCAN_RE = /[\n\t]/g; |
|
|
|
var NEWLINES_RE = /\r[\n\u0085]|[\u2424\u2028\u0085]/g; |
|
|
|
var SPACES_RE = /\u00a0/g; |
|
|
|
|
|
|
|
ParserBlock.prototype.parse = function (src, options, env) { |
|
|
|
var state, lineStart = 0, lastTabPos = 0; |
|
|
|
|
|
|
|
if (!src) { return ''; } |
|
|
|
if (!src) { return []; } |
|
|
|
|
|
|
|
// Normalize spaces
|
|
|
|
src = src.replace(/\u00a0/g, ' '); |
|
|
|
src = src.replace(SPACES_RE, ' '); |
|
|
|
|
|
|
|
// Normalize newlines
|
|
|
|
src = src.replace(/\r\n/, '\n'); |
|
|
|
src = src.replace(/\r\u0085/, '\n'); |
|
|
|
src = src.replace(/[\u2424\u2028\u0085]/g, '\n'); |
|
|
|
src = src.replace(NEWLINES_RE, '\n'); |
|
|
|
|
|
|
|
// Replace tabs with proper number of spaces (1..4)
|
|
|
|
if (src.indexOf('\t') >= 0) { |
|
|
|
src = src.replace(/[\n\t]/g, function (match, offset) { |
|
|
|
src = src.replace(TABS_SCAN_RE, function (match, offset) { |
|
|
|
var result; |
|
|
|
if (src.charCodeAt(offset) === 0x0A) { |
|
|
|
lineStart = offset + 1; |
|
|
|