|
@ -3,10 +3,6 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isWhiteSpace(ch) { |
|
|
|
|
|
return ch === 0x20; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if line has zero length or contains spaces only
|
|
|
// Check if line has zero length or contains spaces only
|
|
|
function isEmpty(state, line) { |
|
|
function isEmpty(state, line) { |
|
|
return state.bMarks[line] + state.tShift[line] >= state.eMarks[line]; |
|
|
return state.bMarks[line] + state.tShift[line] >= state.eMarks[line]; |
|
@ -25,7 +21,7 @@ function skipEmptyLines(state, from) { |
|
|
// Skip spaces from given position.
|
|
|
// Skip spaces from given position.
|
|
|
function skipSpaces(state, pos) { |
|
|
function skipSpaces(state, pos) { |
|
|
for (var max = state.src.length; pos < max; pos++) { |
|
|
for (var max = state.src.length; pos < max; pos++) { |
|
|
if (!isWhiteSpace(state.src.charCodeAt(pos))) { break; } |
|
|
if (state.src.charCodeAt(pos) !== 0x20/* space */) { break; } |
|
|
} |
|
|
} |
|
|
return pos; |
|
|
return pos; |
|
|
} |
|
|
} |
|
@ -83,73 +79,9 @@ function getLines(state, begin, end, indent, keepLastLF) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function escapeHtml(str) { |
|
|
|
|
|
if (str.indexOf('&') >= 0) { str = str.replace(/&/g, '&'); } |
|
|
|
|
|
if (str.indexOf('<') >= 0) { str = str.replace(/</g, '<'); } |
|
|
|
|
|
if (str.indexOf('>') >= 0) { str = str.replace(/>/g, '>'); } |
|
|
|
|
|
if (str.indexOf('"') >= 0) { str = str.replace(/"/g, '"'); } |
|
|
|
|
|
return str; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var UNESCAPE_MD_RE = /\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; |
|
|
|
|
|
|
|
|
|
|
|
function unescapeMd(str) { |
|
|
|
|
|
if (str.indexOf('\\') < 0) { return str; } |
|
|
|
|
|
return str.replace(UNESCAPE_MD_RE, '$1'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isValidEntityCode(c) { |
|
|
|
|
|
/*eslint no-bitwise:0*/ |
|
|
|
|
|
// broken sequence
|
|
|
|
|
|
if (c >= 0xD800 && c <= 0xDFFF) { return false; } |
|
|
|
|
|
if (c >= 0xF5 && c <= 0xFF) { return false; } |
|
|
|
|
|
if (c === 0xC0 || c === 0xC1) { return false; } |
|
|
|
|
|
// never used
|
|
|
|
|
|
if (c >= 0xFDD0 && c <= 0xFDEF) { return false; } |
|
|
|
|
|
if ((c & 0xFFFF) === 0xFFFF || (c & 0xFFFF) === 0xFFFE) { return false; } |
|
|
|
|
|
// control codes
|
|
|
|
|
|
if (c <= 0x1F) { return false; } |
|
|
|
|
|
if (c >= 0x7F && c <= 0x9F) { return false; } |
|
|
|
|
|
// out of range
|
|
|
|
|
|
if (c > 0x10FFFF) { return false; } |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function fromCodePoint(c) { |
|
|
|
|
|
/*eslint no-bitwise:0*/ |
|
|
|
|
|
if (c > 0xffff) { |
|
|
|
|
|
c -= 0x10000; |
|
|
|
|
|
var surrogate1 = 0xd800 + (c >> 10), |
|
|
|
|
|
surrogate2 = 0xdc00 + (c & 0x3ff); |
|
|
|
|
|
|
|
|
|
|
|
return String.fromCharCode(surrogate1, surrogate2); |
|
|
|
|
|
} |
|
|
|
|
|
return String.fromCharCode(c); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var NAMED_ENTITY_RE = /&([a-z][a-z0-9]{1,31});/gi; |
|
|
|
|
|
var entities = require('./common/entities'); |
|
|
|
|
|
|
|
|
|
|
|
function replaceEntities(str) { |
|
|
|
|
|
if (str.indexOf('&') < 0) { return str; } |
|
|
|
|
|
|
|
|
|
|
|
return str.replace(NAMED_ENTITY_RE, function(match, name) { |
|
|
|
|
|
if (entities.hasOwnProperty(name)) { |
|
|
|
|
|
return entities[name]; |
|
|
|
|
|
} |
|
|
|
|
|
return match; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
exports.isWhiteSpace = isWhiteSpace; |
|
|
|
|
|
exports.isEmpty = isEmpty; |
|
|
exports.isEmpty = isEmpty; |
|
|
exports.skipEmptyLines = skipEmptyLines; |
|
|
exports.skipEmptyLines = skipEmptyLines; |
|
|
exports.skipSpaces = skipSpaces; |
|
|
exports.skipSpaces = skipSpaces; |
|
|
exports.skipChars = skipChars; |
|
|
exports.skipChars = skipChars; |
|
|
exports.getLines = getLines; |
|
|
exports.getLines = getLines; |
|
|
exports.skipCharsBack = skipCharsBack; |
|
|
exports.skipCharsBack = skipCharsBack; |
|
|
exports.escapeHtml = escapeHtml; |
|
|
|
|
|
exports.unescapeMd = unescapeMd; |
|
|
|
|
|
exports.isValidEntityCode = isValidEntityCode; |
|
|
|
|
|
exports.fromCodePoint = fromCodePoint; |
|
|
|
|
|
exports.replaceEntities = replaceEntities; |
|
|
|
|
|