@bbob/html
Advanced tools
Comparing version 2.5.8 to 2.6.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [2.6.0](https://github.com/JiLiZART/bbob/compare/v2.5.8...v2.6.0) (2020-12-10) | ||
**Note:** Version bump only for package @bbob/html | ||
## [2.5.8](https://github.com/JiLiZART/bbob/compare/v2.5.7...v2.5.8) (2020-07-08) | ||
@@ -8,0 +16,0 @@ |
1033
dist/index.js
@@ -106,2 +106,6 @@ (function (global, factory) { | ||
var keysReduce = function keysReduce(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
var getNodeLength = function getNodeLength(node) { | ||
@@ -182,7 +186,7 @@ if (isTagNode(node)) { | ||
// To avoid some malformed attributes | ||
if (typeof values === 'undefined') { | ||
if (values == null) { | ||
return ''; | ||
} | ||
return Object.keys(values).reduce(function (arr, key) { | ||
return keysReduce(values, function (arr, key) { | ||
return [].concat(arr, [attrValue(key, values[key])]); | ||
@@ -203,3 +207,3 @@ }, ['']).join(' '); | ||
var getUniqAttr = function getUniqAttr(attrs) { | ||
return Object.keys(attrs).reduce(function (res, key) { | ||
return keysReduce(attrs, function (res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
@@ -288,3 +292,3 @@ }, null); | ||
this.attrs = attrs; | ||
this.content = [].concat(content); | ||
this.content = Array.isArray(content) ? content : [content]; | ||
} | ||
@@ -361,189 +365,2 @@ | ||
var char_1$1 = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.BACKSLASH = exports.PLACEHOLDER_SPACE = exports.PLACEHOLDER_SPACE_TAB = exports.SLASH = exports.CLOSE_BRAKET = exports.OPEN_BRAKET = exports.SPACE = exports.QUOTEMARK = exports.EQ = exports.TAB = exports.R = exports.F = exports.N = void 0; | ||
var N = '\n'; | ||
exports.N = N; | ||
var TAB = '\t'; | ||
exports.TAB = TAB; | ||
var F = '\f'; | ||
exports.F = F; | ||
var R = '\r'; | ||
exports.R = R; | ||
var EQ = '='; | ||
exports.EQ = EQ; | ||
var QUOTEMARK = '"'; | ||
exports.QUOTEMARK = QUOTEMARK; | ||
var SPACE = ' '; | ||
exports.SPACE = SPACE; | ||
var OPEN_BRAKET = '['; | ||
exports.OPEN_BRAKET = OPEN_BRAKET; | ||
var CLOSE_BRAKET = ']'; | ||
exports.CLOSE_BRAKET = CLOSE_BRAKET; | ||
var SLASH = '/'; | ||
exports.SLASH = SLASH; | ||
var BACKSLASH = '\\'; | ||
exports.BACKSLASH = BACKSLASH; | ||
var PLACEHOLDER_SPACE_TAB = ' '; | ||
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
var PLACEHOLDER_SPACE = ' '; // const getChar = String.fromCharCode; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
}); | ||
unwrapExports(char_1$1); | ||
var char_2$1 = char_1$1.BACKSLASH; | ||
var char_3$1 = char_1$1.PLACEHOLDER_SPACE; | ||
var char_4$1 = char_1$1.PLACEHOLDER_SPACE_TAB; | ||
var char_5$1 = char_1$1.SLASH; | ||
var char_6$1 = char_1$1.CLOSE_BRAKET; | ||
var char_7$1 = char_1$1.OPEN_BRAKET; | ||
var char_8$1 = char_1$1.SPACE; | ||
var char_9$1 = char_1$1.QUOTEMARK; | ||
var char_10$1 = char_1$1.EQ; | ||
var char_11$1 = char_1$1.TAB; | ||
var char_12$1 = char_1$1.R; | ||
var char_13$1 = char_1$1.F; | ||
var char_14$1 = char_1$1.N; | ||
var es = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getUniqAttr = exports.getNodeLength = exports.escapeHTML = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0; | ||
var isTagNode = function isTagNode(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
exports.isTagNode = isTagNode; | ||
var isStringNode = function isStringNode(el) { | ||
return typeof el === 'string'; | ||
}; | ||
exports.isStringNode = isStringNode; | ||
var isEOL = function isEOL(el) { | ||
return el === char_1$1.N; | ||
}; | ||
exports.isEOL = isEOL; | ||
var getNodeLength = function getNodeLength(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function (count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return 0; | ||
}; | ||
/** | ||
* Appends value to Tag Node | ||
* @param {TagNode} node | ||
* @param value | ||
*/ | ||
exports.getNodeLength = getNodeLength; | ||
var appendToNode = function appendToNode(node, value) { | ||
node.content.push(value); | ||
}; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ | ||
exports.appendToNode = appendToNode; | ||
var escapeHTML = function escapeHTML(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') // eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ | ||
exports.escapeHTML = escapeHTML; | ||
var attrValue = function attrValue(name, value) { | ||
var type = typeof value; | ||
var types = { | ||
boolean: function boolean() { | ||
return value ? "" + name : ''; | ||
}, | ||
number: function number() { | ||
return name + "=\"" + value + "\""; | ||
}, | ||
string: function string() { | ||
return name + "=\"" + escapeHTML(value) + "\""; | ||
}, | ||
object: function object() { | ||
return name + "=\"" + escapeHTML(JSON.stringify(value)) + "\""; | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
/** | ||
* Transforms attrs to html params string | ||
* @param values | ||
*/ | ||
exports.attrValue = attrValue; | ||
var attrsToString = function attrsToString(values) { | ||
// To avoid some malformed attributes | ||
if (typeof values === 'undefined') { | ||
return ''; | ||
} | ||
return Object.keys(values).reduce(function (arr, key) { | ||
return [].concat(arr, [attrValue(key, values[key])]); | ||
}, ['']).join(' '); | ||
}; | ||
/** | ||
* Gets value from | ||
* @example | ||
* getUniqAttr({ 'foo': true, 'bar': bar' }) => 'bar' | ||
* @param attrs | ||
* @returns {string} | ||
*/ | ||
exports.attrsToString = attrsToString; | ||
var getUniqAttr = function getUniqAttr(attrs) { | ||
return Object.keys(attrs).reduce(function (res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
exports.getUniqAttr = getUniqAttr; | ||
}); | ||
unwrapExports(es); | ||
var es_1 = es.isEOL; | ||
var es_2 = es.isStringNode; | ||
var es_3 = es.isTagNode; | ||
var es_4 = es.getUniqAttr; | ||
var es_5 = es.getNodeLength; | ||
var es_6 = es.escapeHTML; | ||
var es_7 = es.appendToNode; | ||
var es_8 = es.attrValue; | ||
var es_9 = es.attrsToString; | ||
var Token_1 = createCommonjsModule(function (module, exports) { | ||
@@ -565,8 +382,14 @@ | ||
var TOKEN_TYPE_WORD = 'word'; | ||
var TOKEN_TYPE_TAG = 'tag'; | ||
var TOKEN_TYPE_ATTR_NAME = 'attr-name'; | ||
var TOKEN_TYPE_ATTR_VALUE = 'attr-value'; | ||
var TOKEN_TYPE_SPACE = 'space'; | ||
var TOKEN_TYPE_NEW_LINE = 'new-line'; | ||
var TOKEN_TYPE_WORD = 1; // 'word'; | ||
var TOKEN_TYPE_TAG = 2; // 'tag'; | ||
var TOKEN_TYPE_ATTR_NAME = 3; // 'attr-name'; | ||
var TOKEN_TYPE_ATTR_VALUE = 4; // 'attr-value'; | ||
var TOKEN_TYPE_SPACE = 5; // 'space'; | ||
var TOKEN_TYPE_NEW_LINE = 6; // 'new-line'; | ||
/** | ||
@@ -675,3 +498,3 @@ * @param {Token} token | ||
function Token(type, value, line, row) { | ||
this[TOKEN_TYPE_ID] = String(type); | ||
this[TOKEN_TYPE_ID] = Number(type); | ||
this[TOKEN_VALUE_ID] = String(value); | ||
@@ -685,3 +508,4 @@ this[TOKEN_LINE_ID] = Number(line); | ||
_proto.isEmpty = function isEmpty() { | ||
return !!this[TOKEN_TYPE_ID]; | ||
// eslint-disable-next-line no-restricted-globals | ||
return isNaN(this[TOKEN_TYPE_ID]); | ||
}; | ||
@@ -780,107 +604,137 @@ | ||
/** | ||
* @typedef {Object} CharGrabber | ||
* @property {Function} skip | ||
* @property {Function} hasNext | ||
* @property {Function} isLast | ||
* @property {Function} grabWhile | ||
*/ | ||
/** | ||
* Creates a grabber wrapper for source string, that helps to iterate over string char by char | ||
* @param {String} source | ||
* @param {Object} options | ||
* @param {Function} options.onSkip | ||
* @returns | ||
*/ | ||
var createCharGrabber = function createCharGrabber(source, options) { | ||
// let idx = 0; | ||
function CharGrabber(source, options) { | ||
var cursor = { | ||
pos: 0, | ||
length: source.length | ||
len: source.length | ||
}; | ||
var skip = function skip() { | ||
cursor.pos += 1; | ||
var substrUntilChar = function substrUntilChar(char) { | ||
var pos = cursor.pos; | ||
var idx = source.indexOf(char, pos); | ||
return idx >= 0 ? source.substr(pos, idx - pos) : ''; | ||
}; | ||
if (options && options.onSkip) { | ||
options.onSkip(); | ||
} | ||
var includes = function includes(val) { | ||
return source.indexOf(val, cursor.pos) >= 0; | ||
}; | ||
var hasNext = function hasNext() { | ||
return cursor.length > cursor.pos; | ||
return cursor.len > cursor.pos; | ||
}; | ||
var getRest = function getRest() { | ||
var isLast = function isLast() { | ||
return cursor.pos === cursor.len; | ||
}; | ||
var skip = function skip(num, silent) { | ||
if (num === void 0) { | ||
num = 1; | ||
} | ||
cursor.pos += num; | ||
if (options && options.onSkip && !silent) { | ||
options.onSkip(); | ||
} | ||
}; | ||
var rest = function rest() { | ||
return source.substr(cursor.pos); | ||
}; | ||
var getCurr = function getCurr() { | ||
var curr = function curr() { | ||
return source[cursor.pos]; | ||
}; | ||
return { | ||
skip: skip, | ||
hasNext: hasNext, | ||
isLast: function isLast() { | ||
return cursor.pos === cursor.length; | ||
}, | ||
var prev = function prev() { | ||
var prevPos = cursor.pos - 1; | ||
return typeof source[prevPos] !== 'undefined' ? source[prevPos] : null; | ||
}; | ||
/** | ||
* @param {Function} cond | ||
* @returns {string} | ||
*/ | ||
grabWhile: function grabWhile(cond) { | ||
var start = 0; | ||
var next = function next() { | ||
var nextPos = cursor.pos + 1; | ||
return nextPos <= source.length - 1 ? source[nextPos] : null; | ||
}; | ||
if (hasNext()) { | ||
start = cursor.pos; | ||
var grabWhile = function grabWhile(cond, silent) { | ||
var start = 0; | ||
while (hasNext() && cond(getCurr())) { | ||
skip(); | ||
} | ||
if (hasNext()) { | ||
start = cursor.pos; | ||
while (hasNext() && cond(curr())) { | ||
skip(1, silent); | ||
} | ||
} | ||
return source.substr(start, cursor.pos - start); | ||
}, | ||
getNext: function getNext() { | ||
var nextPos = cursor.pos + 1; | ||
return source.substr(start, cursor.pos - start); | ||
}; | ||
/** | ||
* @type {skip} | ||
*/ | ||
if (nextPos <= source.length - 1) { | ||
return source[nextPos]; | ||
} | ||
return null; | ||
}, | ||
getPrev: function getPrev() { | ||
var prevPos = cursor.pos - 1; | ||
this.skip = skip; | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
if (typeof source[prevPos] !== 'undefined') { | ||
return source[prevPos]; | ||
} | ||
this.hasNext = hasNext; | ||
/** | ||
* @returns {String} | ||
*/ | ||
return null; | ||
}, | ||
getCurr: getCurr, | ||
getRest: getRest, | ||
this.getCurr = curr; | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* Grabs rest of string until it find a char | ||
* @param {String} char | ||
* @return {String} | ||
*/ | ||
substrUntilChar: function substrUntilChar(char) { | ||
var restStr = getRest(); | ||
var indexOfChar = restStr.indexOf(char); | ||
this.getRest = rest; | ||
/** | ||
* @returns {String} | ||
*/ | ||
if (indexOfChar >= 0) { | ||
return restStr.substr(0, indexOfChar); | ||
} | ||
this.getNext = next; | ||
/** | ||
* @returns {String} | ||
*/ | ||
return ''; | ||
} | ||
}; | ||
this.getPrev = prev; | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
this.isLast = isLast; | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
this.includes = includes; | ||
/** | ||
* @param {Function} cond | ||
* @param {Boolean} silent | ||
* @return {String} | ||
*/ | ||
this.grabWhile = grabWhile; | ||
/** | ||
* Grabs rest of string until it find a char | ||
* @param {String} char | ||
* @return {String} | ||
*/ | ||
this.substrUntilChar = substrUntilChar; | ||
} | ||
/** | ||
* Creates a grabber wrapper for source string, that helps to iterate over string char by char | ||
* @param {String} source | ||
* @param {Object} options | ||
* @param {Function} options.onSkip | ||
* @return CharGrabber | ||
*/ | ||
var createCharGrabber = function createCharGrabber(source, options) { | ||
return new CharGrabber(source, options); | ||
}; | ||
@@ -924,21 +778,6 @@ /** | ||
}; | ||
/** | ||
* @typedef {Object} ItemList | ||
* @type {Object} | ||
* @property {getLastCb} getLast | ||
* @property {flushLastCb} flushLast | ||
* @property {pushCb} push | ||
* @property {toArrayCb} toArray | ||
*/ | ||
/** | ||
* | ||
* @param values | ||
* @return {ItemList} | ||
*/ | ||
exports.unquote = unquote; | ||
var createList = function createList(values) { | ||
function NodeList(values) { | ||
if (values === void 0) { | ||
@@ -949,49 +788,37 @@ values = []; | ||
var nodes = values; | ||
/** | ||
* @callback getLastCb | ||
*/ | ||
var getLast = function getLast() { | ||
if (Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined') { | ||
return nodes[nodes.length - 1]; | ||
} | ||
return null; | ||
return Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined' ? nodes[nodes.length - 1] : null; | ||
}; | ||
/** | ||
* @callback flushLastCb | ||
* @return {*} | ||
*/ | ||
var flushLast = function flushLast() { | ||
if (nodes.length) { | ||
return nodes.pop(); | ||
} | ||
return false; | ||
return nodes.length ? nodes.pop() : false; | ||
}; | ||
/** | ||
* @callback pushCb | ||
* @param value | ||
*/ | ||
var push = function push(value) { | ||
return nodes.push(value); | ||
}; | ||
/** | ||
* @callback toArrayCb | ||
* @return {Array} | ||
*/ | ||
var toArray = function toArray() { | ||
return nodes; | ||
}; | ||
return { | ||
getLast: getLast, | ||
flushLast: flushLast, | ||
push: push, | ||
toArray: function toArray() { | ||
return nodes; | ||
} | ||
}; | ||
this.push = push; | ||
this.toArray = toArray; | ||
this.getLast = getLast; | ||
this.flushLast = flushLast; | ||
} | ||
/** | ||
* | ||
* @param values | ||
* @return {NodeList} | ||
*/ | ||
var createList = function createList(values) { | ||
if (values === void 0) { | ||
values = []; | ||
} | ||
return new NodeList(values); | ||
}; | ||
@@ -1026,3 +853,3 @@ | ||
* Creates a Token entity class | ||
* @param {String} type | ||
* @param {Number} type | ||
* @param {String} value | ||
@@ -1066,9 +893,20 @@ * @param {Number} r line number | ||
var STATE_WORD = 0; | ||
var STATE_TAG = 1; | ||
var STATE_TAG_ATTRS = 2; | ||
var TAG_STATE_NAME = 0; | ||
var TAG_STATE_ATTR = 1; | ||
var TAG_STATE_VALUE = 2; | ||
var row = 0; | ||
var col = 0; | ||
var tokenIndex = -1; | ||
var stateMode = STATE_WORD; | ||
var tagMode = TAG_STATE_NAME; | ||
var tokens = new Array(Math.floor(buffer.length)); | ||
var openTag = options.openTag || char_1.OPEN_BRAKET; | ||
var closeTag = options.closeTag || char_1.CLOSE_BRAKET; | ||
var escapeTags = options.enableEscapeTags; | ||
var escapeTags = !!options.enableEscapeTags; | ||
var onToken = options.onToken || function () {}; | ||
var RESERVED_CHARS = [closeTag, openTag, char_1.QUOTEMARK, char_1.BACKSLASH, char_1.SPACE, char_1.TAB, char_1.EQ, char_1.N, EM]; | ||
@@ -1084,2 +922,6 @@ var NOT_CHAR_TOKENS = [// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
var isNewLine = function isNewLine(char) { | ||
return char === char_1.N; | ||
}; | ||
var isWhiteSpace = function isWhiteSpace(char) { | ||
@@ -1104,160 +946,246 @@ return WHITESPACES.indexOf(char) >= 0; | ||
}; | ||
var onSkip = function onSkip() { | ||
col++; | ||
}; | ||
var unq = function unq(val) { | ||
return (0, utils.unquote)((0, utils.trimChar)(val, char_1.QUOTEMARK)); | ||
}; | ||
var chars = (0, utils.createCharGrabber)(buffer, { | ||
onSkip: onSkip | ||
}); | ||
/** | ||
* Emits newly created token to subscriber | ||
* @param token | ||
* @param {Number} type | ||
* @param {String} value | ||
*/ | ||
var emitToken = function emitToken(token) { | ||
if (options.onToken) { | ||
options.onToken(token); | ||
} | ||
function emitToken(type, value) { | ||
var token = createToken(type, value, row, col); | ||
onToken(token); | ||
tokenIndex += 1; | ||
tokens[tokenIndex] = token; | ||
}; | ||
/** | ||
* Parses params inside [myTag---params goes here---]content[/myTag] | ||
* @param str | ||
* @returns {{tag: *, attrs: Array}} | ||
*/ | ||
} | ||
function nextTagState(tagChars, isSingleValueTag) { | ||
if (tagMode === TAG_STATE_ATTR) { | ||
var validAttrName = function validAttrName(char) { | ||
return !(char === char_1.EQ || isWhiteSpace(char)); | ||
}; | ||
var parseAttrs = function parseAttrs(str) { | ||
var tagName = null; | ||
var skipSpecialChars = false; | ||
var attrTokens = []; | ||
var attrCharGrabber = (0, utils.createCharGrabber)(str); | ||
var _name = tagChars.grabWhile(validAttrName); | ||
var validAttr = function validAttr(char) { | ||
var isEQ = char === char_1.EQ; | ||
var isWS = isWhiteSpace(char); | ||
var prevChar = attrCharGrabber.getPrev(); | ||
var nextChar = attrCharGrabber.getNext(); | ||
var isPrevSLASH = prevChar === char_1.BACKSLASH; | ||
var isTagNameEmpty = tagName === null; | ||
var isEnd = tagChars.isLast(); | ||
if (isTagNameEmpty) { | ||
return (isEQ || isWS || attrCharGrabber.isLast()) === false; | ||
var isValue = tagChars.getCurr() !== char_1.EQ; | ||
tagChars.skip(); | ||
if (isEnd || isValue) { | ||
emitToken(Token_1.TYPE_ATTR_VALUE, unq(_name)); | ||
} else { | ||
emitToken(Token_1.TYPE_ATTR_NAME, _name); | ||
} | ||
if (skipSpecialChars && isSpecialChar(char)) { | ||
return true; | ||
if (isEnd) { | ||
return TAG_STATE_NAME; | ||
} | ||
if (char === char_1.QUOTEMARK && !isPrevSLASH) { | ||
skipSpecialChars = !skipSpecialChars; | ||
if (isValue) { | ||
return TAG_STATE_ATTR; | ||
} | ||
if (!skipSpecialChars && !(nextChar === char_1.EQ || isWhiteSpace(nextChar))) { | ||
return false; | ||
return TAG_STATE_VALUE; | ||
} | ||
if (tagMode === TAG_STATE_VALUE) { | ||
var stateSpecial = false; | ||
var validAttrValue = function validAttrValue(char) { | ||
// const isEQ = char === EQ; | ||
var isQM = char === char_1.QUOTEMARK; | ||
var prevChar = tagChars.getPrev(); | ||
var nextChar = tagChars.getNext(); | ||
var isPrevSLASH = prevChar === char_1.BACKSLASH; | ||
var isNextEQ = nextChar === char_1.EQ; | ||
var isWS = isWhiteSpace(char); // const isPrevWS = isWhiteSpace(prevChar); | ||
var isNextWS = isWhiteSpace(nextChar); | ||
if (stateSpecial && isSpecialChar(char)) { | ||
return true; | ||
} | ||
} | ||
return (isEQ || isWS) === false; | ||
}; | ||
if (isQM && !isPrevSLASH) { | ||
stateSpecial = !stateSpecial; | ||
var nextAttr = function nextAttr() { | ||
var attrStr = attrCharGrabber.grabWhile(validAttr); | ||
var currChar = attrCharGrabber.getCurr(); // first string before space is a tag name [tagName params...] | ||
if (!stateSpecial && !(isNextEQ || isNextWS)) { | ||
return false; | ||
} | ||
} | ||
if (tagName === null) { | ||
tagName = attrStr; | ||
} else if (isWhiteSpace(currChar) || currChar === char_1.QUOTEMARK || !attrCharGrabber.hasNext()) { | ||
var escaped = (0, utils.unquote)((0, utils.trimChar)(attrStr, char_1.QUOTEMARK)); | ||
attrTokens.push(createToken(Token_1.TYPE_ATTR_VALUE, escaped, row, col)); | ||
} else { | ||
attrTokens.push(createToken(Token_1.TYPE_ATTR_NAME, attrStr, row, col)); | ||
if (!isSingleValueTag) { | ||
return isWS === false; // return (isEQ || isWS) === false; | ||
} | ||
return true; | ||
}; | ||
var _name2 = tagChars.grabWhile(validAttrValue); | ||
tagChars.skip(); | ||
emitToken(Token_1.TYPE_ATTR_VALUE, unq(_name2)); | ||
if (tagChars.isLast()) { | ||
return TAG_STATE_NAME; | ||
} | ||
attrCharGrabber.skip(); | ||
}; | ||
while (attrCharGrabber.hasNext()) { | ||
nextAttr(); | ||
return TAG_STATE_ATTR; | ||
} | ||
return { | ||
tag: tagName, | ||
attrs: attrTokens | ||
var validName = function validName(char) { | ||
return !(char === char_1.EQ || isWhiteSpace(char) || tagChars.isLast()); | ||
}; | ||
}; | ||
var bufferGrabber = (0, utils.createCharGrabber)(buffer, { | ||
onSkip: function onSkip() { | ||
col++; | ||
var name = tagChars.grabWhile(validName); | ||
emitToken(Token_1.TYPE_TAG, name); | ||
tagChars.skip(); // in cases when we has [url=someval]GET[/url] and we dont need to parse all | ||
if (isSingleValueTag) { | ||
return TAG_STATE_VALUE; | ||
} | ||
}); | ||
var next = function next() { | ||
var currChar = bufferGrabber.getCurr(); | ||
var nextChar = bufferGrabber.getNext(); | ||
var hasEQ = tagChars.includes(char_1.EQ); | ||
return hasEQ ? TAG_STATE_ATTR : TAG_STATE_VALUE; | ||
} | ||
if (currChar === char_1.N) { | ||
bufferGrabber.skip(); | ||
col = 0; | ||
row++; | ||
emitToken(createToken(Token_1.TYPE_NEW_LINE, currChar, row, col)); | ||
} else if (isWhiteSpace(currChar)) { | ||
var str = bufferGrabber.grabWhile(isWhiteSpace); | ||
emitToken(createToken(Token_1.TYPE_SPACE, str, row, col)); | ||
} else if (escapeTags && isEscapeChar(currChar) && isEscapableChar(nextChar)) { | ||
bufferGrabber.skip(); // skip the \ without emitting anything | ||
function stateTag() { | ||
var currChar = chars.getCurr(); | ||
bufferGrabber.skip(); // skip past the [, ] or \ as well | ||
if (currChar === openTag) { | ||
var nextChar = chars.getNext(); | ||
chars.skip(); // detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
emitToken(createToken(Token_1.TYPE_WORD, nextChar, row, col)); | ||
} else if (currChar === openTag) { | ||
bufferGrabber.skip(); // skip openTag | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
var substr = bufferGrabber.substrUntilChar(closeTag); | ||
var substr = chars.substrUntilChar(closeTag); | ||
var hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
if (isCharReserved(nextChar) || hasInvalidChars || bufferGrabber.isLast()) { | ||
emitToken(createToken(Token_1.TYPE_WORD, currChar, row, col)); | ||
} else { | ||
var _str = bufferGrabber.grabWhile(function (val) { | ||
return val !== closeTag; | ||
if (isCharReserved(nextChar) || hasInvalidChars || chars.isLast()) { | ||
emitToken(Token_1.TYPE_WORD, currChar); | ||
return STATE_WORD; | ||
} // [myTag ] | ||
var isNoAttrsInTag = substr.indexOf(char_1.EQ) === -1; // [/myTag] | ||
var isClosingTag = substr[0] === char_1.SLASH; | ||
if (isNoAttrsInTag || isClosingTag) { | ||
var name = chars.grabWhile(function (char) { | ||
return char !== closeTag; | ||
}); | ||
chars.skip(); // skip closeTag | ||
bufferGrabber.skip(); // skip closeTag | ||
// [myTag ] | ||
emitToken(Token_1.TYPE_TAG, name); | ||
return STATE_WORD; | ||
} | ||
var isNoAttrsInTag = _str.indexOf(char_1.EQ) === -1; // [/myTag] | ||
return STATE_TAG_ATTRS; | ||
} | ||
var isClosingTag = _str[0] === char_1.SLASH; | ||
return STATE_WORD; | ||
} | ||
if (isNoAttrsInTag || isClosingTag) { | ||
emitToken(createToken(Token_1.TYPE_TAG, _str, row, col)); | ||
} else { | ||
var parsed = parseAttrs(_str); | ||
emitToken(createToken(Token_1.TYPE_TAG, parsed.tag, row, col)); | ||
parsed.attrs.map(emitToken); | ||
} | ||
function stateAttrs() { | ||
var silent = true; | ||
var tagStr = chars.grabWhile(function (char) { | ||
return char !== closeTag; | ||
}, silent); | ||
var tagGrabber = (0, utils.createCharGrabber)(tagStr, { | ||
onSkip: onSkip | ||
}); | ||
var hasSpace = tagGrabber.includes(char_1.SPACE); | ||
while (tagGrabber.hasNext()) { | ||
tagMode = nextTagState(tagGrabber, !hasSpace); | ||
} | ||
chars.skip(); // skip closeTag | ||
return STATE_WORD; | ||
} | ||
function stateWord() { | ||
if (isNewLine(chars.getCurr())) { | ||
emitToken(Token_1.TYPE_NEW_LINE, chars.getCurr()); | ||
chars.skip(); | ||
col = 0; | ||
row++; | ||
return STATE_WORD; | ||
} | ||
if (isWhiteSpace(chars.getCurr())) { | ||
emitToken(Token_1.TYPE_SPACE, chars.grabWhile(isWhiteSpace)); | ||
return STATE_WORD; | ||
} | ||
if (chars.getCurr() === openTag) { | ||
if (chars.includes(closeTag)) { | ||
return STATE_TAG; | ||
} | ||
} else if (currChar === closeTag) { | ||
bufferGrabber.skip(); // skip closeTag | ||
emitToken(createToken(Token_1.TYPE_WORD, currChar, row, col)); | ||
} else if (isCharToken(currChar)) { | ||
if (escapeTags && isEscapeChar(currChar) && !isEscapableChar(nextChar)) { | ||
bufferGrabber.skip(); | ||
emitToken(createToken(Token_1.TYPE_WORD, currChar, row, col)); | ||
} else { | ||
var _str2 = bufferGrabber.grabWhile(function (char) { | ||
if (escapeTags) { | ||
return isCharToken(char) && !isEscapeChar(char); | ||
} | ||
emitToken(Token_1.TYPE_WORD, chars.getCurr()); | ||
chars.skip(); | ||
return STATE_WORD; | ||
} | ||
return isCharToken(char); | ||
}); | ||
if (escapeTags) { | ||
if (isEscapeChar(chars.getCurr())) { | ||
var currChar = chars.getCurr(); | ||
var nextChar = chars.getNext(); | ||
chars.skip(); // skip the \ without emitting anything | ||
emitToken(createToken(Token_1.TYPE_WORD, _str2, row, col)); | ||
if (isEscapableChar(nextChar)) { | ||
chars.skip(); // skip past the [, ] or \ as well | ||
emitToken(Token_1.TYPE_WORD, nextChar); | ||
return STATE_WORD; | ||
} | ||
emitToken(Token_1.TYPE_WORD, currChar); | ||
return STATE_WORD; | ||
} | ||
var isChar = function isChar(char) { | ||
return isCharToken(char) && !isEscapeChar(char); | ||
}; | ||
emitToken(Token_1.TYPE_WORD, chars.grabWhile(isChar)); | ||
return STATE_WORD; | ||
} | ||
}; | ||
var tokenize = function tokenize() { | ||
while (bufferGrabber.hasNext()) { | ||
next(); | ||
emitToken(Token_1.TYPE_WORD, chars.grabWhile(isCharToken)); | ||
return STATE_WORD; | ||
} | ||
function tokenize() { | ||
while (chars.hasNext()) { | ||
switch (stateMode) { | ||
case STATE_TAG: | ||
stateMode = stateTag(); | ||
break; | ||
case STATE_TAG_ATTRS: | ||
stateMode = stateAttrs(); | ||
break; | ||
case STATE_WORD: | ||
stateMode = stateWord(); | ||
break; | ||
default: | ||
stateMode = STATE_WORD; | ||
break; | ||
} | ||
} | ||
@@ -1267,9 +1195,9 @@ | ||
return tokens; | ||
}; | ||
} | ||
var isTokenNested = function isTokenNested(token) { | ||
function isTokenNested(token) { | ||
var value = openTag + char_1.SLASH + token.getValue(); // potential bottleneck | ||
return buffer.indexOf(value) > -1; | ||
}; | ||
} | ||
@@ -1331,3 +1259,3 @@ return { | ||
* @private | ||
* @type {ItemList} | ||
* @type {NodeList} | ||
*/ | ||
@@ -1339,3 +1267,3 @@ | ||
* @private | ||
* @type {ItemList} | ||
* @type {NodeList} | ||
*/ | ||
@@ -1347,3 +1275,3 @@ | ||
* @private | ||
* @type {ItemList} | ||
* @type {NodeList} | ||
*/ | ||
@@ -1355,3 +1283,3 @@ | ||
* @private | ||
* @type {ItemList} | ||
* @type {NodeList} | ||
*/ | ||
@@ -1434,3 +1362,3 @@ | ||
if (Array.isArray(items)) { | ||
if ((0, es.isTagNode)(node)) { | ||
if ((0, lib.isTagNode)(node)) { | ||
if (isAllowedTag(node.tag)) { | ||
@@ -1585,3 +1513,3 @@ items.push(node.toTagNode()); | ||
var es$1 = createCommonjsModule(function (module, exports) { | ||
var es = createCommonjsModule(function (module, exports) { | ||
@@ -1653,5 +1581,5 @@ exports.__esModule = true; | ||
unwrapExports(es$1); | ||
var es_1$1 = es$1.TagNode; | ||
var es_2$1 = es$1.parse; | ||
unwrapExports(es); | ||
var es_1 = es.TagNode; | ||
var es_2 = es.parse; | ||
@@ -1739,3 +1667,3 @@ var utils$1 = createCommonjsModule(function (module, exports) { | ||
var es$2 = createCommonjsModule(function (module, exports) { | ||
var es$1 = createCommonjsModule(function (module, exports) { | ||
@@ -1761,3 +1689,3 @@ exports.__esModule = true; | ||
options = opts || {}; | ||
var parseFn = options.parser || es$1.parse; | ||
var parseFn = options.parser || es.parse; | ||
var renderFn = options.render; | ||
@@ -1804,4 +1732,195 @@ var data = options.data || null; | ||
var core = unwrapExports(es$2); | ||
var core = unwrapExports(es$1); | ||
var char_1$1 = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.BACKSLASH = exports.PLACEHOLDER_SPACE = exports.PLACEHOLDER_SPACE_TAB = exports.SLASH = exports.CLOSE_BRAKET = exports.OPEN_BRAKET = exports.SPACE = exports.QUOTEMARK = exports.EQ = exports.TAB = exports.R = exports.F = exports.N = void 0; | ||
var N = '\n'; | ||
exports.N = N; | ||
var TAB = '\t'; | ||
exports.TAB = TAB; | ||
var F = '\f'; | ||
exports.F = F; | ||
var R = '\r'; | ||
exports.R = R; | ||
var EQ = '='; | ||
exports.EQ = EQ; | ||
var QUOTEMARK = '"'; | ||
exports.QUOTEMARK = QUOTEMARK; | ||
var SPACE = ' '; | ||
exports.SPACE = SPACE; | ||
var OPEN_BRAKET = '['; | ||
exports.OPEN_BRAKET = OPEN_BRAKET; | ||
var CLOSE_BRAKET = ']'; | ||
exports.CLOSE_BRAKET = CLOSE_BRAKET; | ||
var SLASH = '/'; | ||
exports.SLASH = SLASH; | ||
var BACKSLASH = '\\'; | ||
exports.BACKSLASH = BACKSLASH; | ||
var PLACEHOLDER_SPACE_TAB = ' '; | ||
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
var PLACEHOLDER_SPACE = ' '; // const getChar = String.fromCharCode; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
}); | ||
unwrapExports(char_1$1); | ||
var char_2$1 = char_1$1.BACKSLASH; | ||
var char_3$1 = char_1$1.PLACEHOLDER_SPACE; | ||
var char_4$1 = char_1$1.PLACEHOLDER_SPACE_TAB; | ||
var char_5$1 = char_1$1.SLASH; | ||
var char_6$1 = char_1$1.CLOSE_BRAKET; | ||
var char_7$1 = char_1$1.OPEN_BRAKET; | ||
var char_8$1 = char_1$1.SPACE; | ||
var char_9$1 = char_1$1.QUOTEMARK; | ||
var char_10$1 = char_1$1.EQ; | ||
var char_11$1 = char_1$1.TAB; | ||
var char_12$1 = char_1$1.R; | ||
var char_13$1 = char_1$1.F; | ||
var char_14$1 = char_1$1.N; | ||
var es$2 = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getUniqAttr = exports.getNodeLength = exports.escapeHTML = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0; | ||
var isTagNode = function isTagNode(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
exports.isTagNode = isTagNode; | ||
var isStringNode = function isStringNode(el) { | ||
return typeof el === 'string'; | ||
}; | ||
exports.isStringNode = isStringNode; | ||
var isEOL = function isEOL(el) { | ||
return el === char_1$1.N; | ||
}; | ||
exports.isEOL = isEOL; | ||
var keysReduce = function keysReduce(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
var getNodeLength = function getNodeLength(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function (count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return 0; | ||
}; | ||
/** | ||
* Appends value to Tag Node | ||
* @param {TagNode} node | ||
* @param value | ||
*/ | ||
exports.getNodeLength = getNodeLength; | ||
var appendToNode = function appendToNode(node, value) { | ||
node.content.push(value); | ||
}; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ | ||
exports.appendToNode = appendToNode; | ||
var escapeHTML = function escapeHTML(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''') // eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ | ||
exports.escapeHTML = escapeHTML; | ||
var attrValue = function attrValue(name, value) { | ||
var type = typeof value; | ||
var types = { | ||
boolean: function boolean() { | ||
return value ? "" + name : ''; | ||
}, | ||
number: function number() { | ||
return name + "=\"" + value + "\""; | ||
}, | ||
string: function string() { | ||
return name + "=\"" + escapeHTML(value) + "\""; | ||
}, | ||
object: function object() { | ||
return name + "=\"" + escapeHTML(JSON.stringify(value)) + "\""; | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
/** | ||
* Transforms attrs to html params string | ||
* @param values | ||
*/ | ||
exports.attrValue = attrValue; | ||
var attrsToString = function attrsToString(values) { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
return keysReduce(values, function (arr, key) { | ||
return [].concat(arr, [attrValue(key, values[key])]); | ||
}, ['']).join(' '); | ||
}; | ||
/** | ||
* Gets value from | ||
* @example | ||
* getUniqAttr({ 'foo': true, 'bar': bar' }) => 'bar' | ||
* @param attrs | ||
* @returns {string} | ||
*/ | ||
exports.attrsToString = attrsToString; | ||
var getUniqAttr = function getUniqAttr(attrs) { | ||
return keysReduce(attrs, function (res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
exports.getUniqAttr = getUniqAttr; | ||
}); | ||
unwrapExports(es$2); | ||
var es_1$1 = es$2.isEOL; | ||
var es_2$1 = es$2.isStringNode; | ||
var es_3 = es$2.isTagNode; | ||
var es_4 = es$2.getUniqAttr; | ||
var es_5 = es$2.getNodeLength; | ||
var es_6 = es$2.escapeHTML; | ||
var es_7 = es$2.appendToNode; | ||
var es_8 = es$2.attrValue; | ||
var es_9 = es$2.attrsToString; | ||
var SELFCLOSE_END_TAG = '/>'; | ||
@@ -1808,0 +1927,0 @@ var CLOSE_START_TAG = '</'; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).BbobHtml={})}(this,(function(t){"use strict";function e(){return(e=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function r(t,e){return t(e={exports:{}},e.exports),e.exports}var o=r((function(t,e){e.__esModule=!0,e.BACKSLASH=e.PLACEHOLDER_SPACE=e.PLACEHOLDER_SPACE_TAB=e.SLASH=e.CLOSE_BRAKET=e.OPEN_BRAKET=e.SPACE=e.QUOTEMARK=e.EQ=e.TAB=e.R=e.F=e.N=void 0;e.N="\n";e.TAB="\t";e.F="\f";e.R="\r";e.EQ="=";e.QUOTEMARK='"';e.SPACE=" ";e.OPEN_BRAKET="[";e.CLOSE_BRAKET="]";e.SLASH="/";e.BACKSLASH="\\";e.PLACEHOLDER_SPACE_TAB=" ";e.PLACEHOLDER_SPACE=" "}));n(o);var i=r((function(t,e){e.__esModule=!0,e.isEOL=e.isStringNode=e.isTagNode=e.getUniqAttr=e.getNodeLength=e.escapeHTML=e.appendToNode=e.attrValue=e.attrsToString=void 0;var n=function(t){return"object"==typeof t&&!!t.tag};e.isTagNode=n;var r=function(t){return"string"==typeof t};e.isStringNode=r;e.isEOL=function(t){return t===o.N};e.getNodeLength=function t(e){return n(e)?e.content.reduce((function(e,n){return e+t(n)}),0):r(e)?e.length:0};e.appendToNode=function(t,e){t.content.push(e)};var i=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")};e.escapeHTML=i;var u=function(t,e){var n=typeof e,r={boolean:function(){return e?""+t:""},number:function(){return t+'="'+e+'"'},string:function(){return t+'="'+i(e)+'"'},object:function(){return t+'="'+i(JSON.stringify(e))+'"'}};return r[n]?r[n]():""};e.attrValue=u;e.attrsToString=function(t){return void 0===t?"":Object.keys(t).reduce((function(e,n){return[].concat(e,[u(n,t[n])])}),[""]).join(" ")};e.getUniqAttr=function(t){return Object.keys(t).reduce((function(e,n){return t[n]===n?t[n]:null}),null)}}));n(i);var u=r((function(t,e){function n(t,e){for(var n=0;e.length>n;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function r(){return(r=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}e.__esModule=!0,e.default=e.TagNode=void 0;var u=function(){function t(t,e,n){this.tag=t,this.attrs=e,this.content=[].concat(n)}var e,u,a,s=t.prototype;return s.attr=function(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]},s.append=function(t){return(0,i.appendToNode)(this,t)},s.toTagNode=function(){return new t(this.tag.toLowerCase(),this.attrs,this.content)},s.toString=function(){var t=o.OPEN_BRAKET,e=o.CLOSE_BRAKET,n=0===this.content.length,u=this.content.reduce((function(t,e){return t+""+e}),""),a=function(t,e){var n=(0,i.getUniqAttr)(e);if(n){var o=(0,i.attrValue)(t,n),u=r({},e);return delete u[n],""+o+(0,i.attrsToString)(u)}return""+t+(0,i.attrsToString)(e)}(this.tag,this.attrs);return n?""+t+a+e:""+t+a+e+u+t+o.SLASH+this.tag+e},e=t,(u=[{key:"length",get:function(){return(0,i.getNodeLength)(this)}}])&&n(e.prototype,u),a&&n(e,a),t}();e.TagNode=u,u.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n=[]),new u(t,e,n)},u.isOf=function(t,e){return t.tag===e},e.default=u}));n(u);var a=r((function(t,e){e.__esModule=!0,e.BACKSLASH=e.PLACEHOLDER_SPACE=e.PLACEHOLDER_SPACE_TAB=e.SLASH=e.CLOSE_BRAKET=e.OPEN_BRAKET=e.SPACE=e.QUOTEMARK=e.EQ=e.TAB=e.R=e.F=e.N=void 0;e.N="\n";e.TAB="\t";e.F="\f";e.R="\r";e.EQ="=";e.QUOTEMARK='"';e.SPACE=" ";e.OPEN_BRAKET="[";e.CLOSE_BRAKET="]";e.SLASH="/";e.BACKSLASH="\\";e.PLACEHOLDER_SPACE_TAB=" ";e.PLACEHOLDER_SPACE=" "}));n(a);var s=r((function(t,e){e.__esModule=!0,e.isEOL=e.isStringNode=e.isTagNode=e.getUniqAttr=e.getNodeLength=e.escapeHTML=e.appendToNode=e.attrValue=e.attrsToString=void 0;var n=function(t){return"object"==typeof t&&!!t.tag};e.isTagNode=n;var r=function(t){return"string"==typeof t};e.isStringNode=r;e.isEOL=function(t){return t===a.N};e.getNodeLength=function t(e){return n(e)?e.content.reduce((function(e,n){return e+t(n)}),0):r(e)?e.length:0};e.appendToNode=function(t,e){t.content.push(e)};var o=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")};e.escapeHTML=o;var i=function(t,e){var n=typeof e,r={boolean:function(){return e?""+t:""},number:function(){return t+'="'+e+'"'},string:function(){return t+'="'+o(e)+'"'},object:function(){return t+'="'+o(JSON.stringify(e))+'"'}};return r[n]?r[n]():""};e.attrValue=i;e.attrsToString=function(t){return void 0===t?"":Object.keys(t).reduce((function(e,n){return[].concat(e,[i(n,t[n])])}),[""]).join(" ")};e.getUniqAttr=function(t){return Object.keys(t).reduce((function(e,n){return t[n]===n?t[n]:null}),null)}}));n(s);var c=s.attrsToString,f=r((function(t,e){e.__esModule=!0,e.default=e.Token=e.TYPE_NEW_LINE=e.TYPE_SPACE=e.TYPE_ATTR_VALUE=e.TYPE_ATTR_NAME=e.TYPE_TAG=e.TYPE_WORD=e.COLUMN_ID=e.LINE_ID=e.VALUE_ID=e.TYPE_ID=void 0;var n=function(t){return t&&void 0!==t.value?t.value:""},r=function(t){return n(t).charCodeAt(0)===o.SLASH.charCodeAt(0)},i=function(){function t(t,e,n,r){this.type=t+"",this.value=e+"",this.line=Number(n),this.row=Number(r)}var e=t.prototype;return e.isEmpty=function(){return!!this.type},e.isText=function(){return!(!(t=this)||void 0===t.type||"space"!==t.type&&"new-line"!==t.type&&"word"!==t.type);var t},e.isTag=function(){return!(!(t=this)||void 0===t.type)&&"tag"===t.type;var t},e.isAttrName=function(){return!(!(t=this)||void 0===t.type)&&"attr-name"===t.type;var t},e.isAttrValue=function(){return!(!(t=this)||void 0===t.type)&&"attr-value"===t.type;var t},e.isStart=function(){return!r(this)},e.isEnd=function(){return r(this)},e.getName=function(){return e=n(t=this),r(t)?e.slice(1):e;var t,e},e.getValue=function(){return n(this)},e.getLine=function(){return(t=this)&&t.line||0;var t},e.getColumn=function(){return(t=this)&&t.row||0;var t},e.toString=function(){return t=o.OPEN_BRAKET,t+=n(this),t+=o.CLOSE_BRAKET;var t},t}();e.Token=i;e.TYPE_ID="type";e.VALUE_ID="value";e.LINE_ID="line";e.COLUMN_ID="row";e.TYPE_WORD="word";e.TYPE_TAG="tag";e.TYPE_ATTR_NAME="attr-name";e.TYPE_ATTR_VALUE="attr-value";e.TYPE_SPACE="space";e.TYPE_NEW_LINE="new-line",e.default=i}));n(f);var l=r((function(t,e){e.__esModule=!0,e.createList=e.unquote=e.trimChar=e.createCharGrabber=void 0;e.createCharGrabber=function(t,e){var n={pos:0,length:t.length},r=function(){n.pos+=1,e&&e.onSkip&&e.onSkip()},o=function(){return n.length>n.pos},i=function(){return t.substr(n.pos)},u=function(){return t[n.pos]};return{skip:r,hasNext:o,isLast:function(){return n.pos===n.length},grabWhile:function(e){var i=0;if(o())for(i=n.pos;o()&&e(u());)r();return t.substr(i,n.pos-i)},getNext:function(){var e=n.pos+1;return e>t.length-1?null:t[e]},getPrev:function(){var e=n.pos-1;return void 0!==t[e]?t[e]:null},getCurr:u,getRest:i,substrUntilChar:function(t){var e=i(),n=e.indexOf(t);return 0>n?"":e.substr(0,n)}}};e.trimChar=function(t,e){for(;t.charAt(0)===e;)t=t.substring(1);for(;t.charAt(t.length-1)===e;)t=t.substring(0,t.length-1);return t};e.unquote=function(t){return t.replace(o.BACKSLASH+o.QUOTEMARK,o.QUOTEMARK)};e.createList=function(t){void 0===t&&(t=[]);var e=t;return{getLast:function(){return Array.isArray(e)&&e.length>0&&void 0!==e[e.length-1]?e[e.length-1]:null},flushLast:function(){return!!e.length&&e.pop()},push:function(t){return e.push(t)},toArray:function(){return e}}}}));n(l);var p=r((function(t,e){e.__esModule=!0,e.createLexer=function(t,e){void 0===e&&(e={});var r=0,i=0,u=-1,a=Array(Math.floor(t.length)),s=e.openTag||o.OPEN_BRAKET,c=e.closeTag||o.CLOSE_BRAKET,p=e.enableEscapeTags,g=[c,s,o.QUOTEMARK,o.BACKSLASH,o.SPACE,o.TAB,o.EQ,o.N,"!"],d=[s,o.SPACE,o.TAB,o.N],A=[o.SPACE,o.TAB],T=[o.EQ,o.SPACE,o.TAB],E=function(t){return A.indexOf(t)>=0},v=function(t){return-1===d.indexOf(t)},h=function(t){return t===s||t===c||t===o.BACKSLASH},_=function(t){return t===o.BACKSLASH},y=function(t){e.onToken&&e.onToken(t),a[u+=1]=t},L=function(t){for(var e=null,u=!1,a=[],s=(0,l.createCharGrabber)(t),c=function(t){var n=t===o.EQ,r=E(t),i=s.getPrev(),a=s.getNext(),c=i===o.BACKSLASH;return null===e?!1===(n||r||s.isLast()):!(!u||!function(t){return T.indexOf(t)>=0}(t))||!!(t!==o.QUOTEMARK||c||(u=!u)||a===o.EQ||E(a))&&!1===(n||r)},p=function(){var t=s.grabWhile(c),u=s.getCurr();if(null===e)e=t;else if(E(u)||u===o.QUOTEMARK||!s.hasNext()){var p=(0,l.unquote)((0,l.trimChar)(t,o.QUOTEMARK));a.push(n(f.TYPE_ATTR_VALUE,p,r,i))}else a.push(n(f.TYPE_ATTR_NAME,t,r,i));s.skip()};s.hasNext();)p();return{tag:e,attrs:a}},O=(0,l.createCharGrabber)(t,{onSkip:function(){i++}}),S=function(){var t=O.getCurr(),e=O.getNext();if(t===o.N)O.skip(),r++,y(n(f.TYPE_NEW_LINE,t,r,i=0));else if(E(t)){var u=O.grabWhile(E);y(n(f.TYPE_SPACE,u,r,i))}else if(p&&_(t)&&h(e))O.skip(),O.skip(),y(n(f.TYPE_WORD,e,r,i));else if(t===s){O.skip();var a=O.substrUntilChar(c),l=0===a.length||a.indexOf(s)>=0;if(g.indexOf(e)>=0||l||O.isLast())y(n(f.TYPE_WORD,t,r,i));else{var d=O.grabWhile((function(t){return t!==c}));if(O.skip(),-1===d.indexOf(o.EQ)||d[0]===o.SLASH)y(n(f.TYPE_TAG,d,r,i));else{var A=L(d);y(n(f.TYPE_TAG,A.tag,r,i)),A.attrs.map(y)}}}else if(t===c)O.skip(),y(n(f.TYPE_WORD,t,r,i));else if(v(t))if(p&&_(t)&&!h(e))O.skip(),y(n(f.TYPE_WORD,t,r,i));else{var T=O.grabWhile((function(t){return p?v(t)&&!_(t):v(t)}));y(n(f.TYPE_WORD,T,r,i))}};return{tokenize:function(){for(;O.hasNext();)S();return a.length=u+1,a},isTokenNested:function(e){var n=s+o.SLASH+e.getValue();return t.indexOf(n)>-1}}},e.createTokenOfType=void 0;var n=function(t,e,n,r){return void 0===n&&(n=0),void 0===r&&(r=0),new f.Token(t,e,n,r)};e.createTokenOfType=n}));n(p);var g=r((function(t,e){e.__esModule=!0,e.default=e.parse=void 0;var n,r=(n=u)&&n.__esModule?n:{default:n};var o=function(t,e){void 0===e&&(e={});var n=e,o=null,i=(0,l.createList)(),u=(0,l.createList)(),a=(0,l.createList)(),c=(0,l.createList)(),f={},g=function(){a.flushLast()&&c.flushLast()},d=function(t){var e,r,o=(e=u.getLast())&&Array.isArray(e.content)?e.content:i.toArray();Array.isArray(o)&&((0,s.isTagNode)(t)?(r=t.tag,n.onlyAllowTags&&n.onlyAllowTags.length&&0>n.onlyAllowTags.indexOf(r)?o.push(""+t):o.push(t.toTagNode())):o.push(t))},A=function(t){g();var e=r.default.create(t.getValue()),n=function(t){return void 0===f[t.getValue()]&&(f[t.getValue()]=o.isTokenNested(t)),f[t.getValue()]}(t);a.push(e),n?u.push(e):d(e)},T=function(t){t.isStart()&&A(t),t.isEnd()&&function(t){g();var e=u.flushLast();if(e)d(e);else if("function"==typeof n.onError){var r=t.getValue(),o=t.getLine(),i=t.getColumn();n.onError({message:"Inconsistent tag '"+r+"' on line "+o+" and column "+i,tagName:r,lineNumber:o,columnNumber:i})}}(t)},E=function(t){var e=a.getLast(),n=t.getValue(),r=!!f[t];if(e)if(t.isAttrName())c.push(n),e.attr(c.getLast(),"");else if(t.isAttrValue()){var o=c.getLast();o?(e.attr(o,n),c.flushLast()):e.attr(n,n)}else t.isText()?r?e.append(n):d(n):t.isTag()&&d(""+t);else t.isText()?d(n):t.isTag()&&d(""+t)};(o=(e.createTokenizer?e.createTokenizer:p.createLexer)(t,{onToken:function(t){t.isTag()?T(t):E(t)},onlyAllowTags:n.onlyAllowTags,openTag:n.openTag,closeTag:n.closeTag,enableEscapeTags:n.enableEscapeTags})).tokenize();return i.toArray()};e.parse=o,e.default=o}));n(g);var d=r((function(t,e){e.__esModule=!0,e.TagNode=e.parse=e.default=void 0;var n=function(t){if(t&&t.__esModule)return t;if(null===t||"object"!=typeof t&&"function"!=typeof t)return{default:t};var e=r();if(e&&e.has(t))return e.get(t);var n={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var u=o?Object.getOwnPropertyDescriptor(t,i):null;u&&(u.get||u.set)?Object.defineProperty(n,i,u):n[i]=t[i]}n.default=t,e&&e.set(t,n);return n}(g);function r(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return r=function(){return t},t}e.default=n.default,e.parse=n.parse,e.TagNode=u.TagNode}));n(d);var A=r((function(t,e){e.__esModule=!0,e.iterate=r,e.match=function(t,e){return r(this,Array.isArray(t)?function(n){for(var r=0;t.length>r;r++)if(o(t[r],n))return e(n);return n}:function(n){return o(t,n)?e(n):n})};var n=function(t){return"object"==typeof t};function r(t,e){var o=t;if(Array.isArray(o))for(var i=0;o.length>i;i++)o[i]=r(e(o[i]),e);else o&&n(o)&&o.content&&r(o.content,e);return o}function o(t,e){return typeof t==typeof e&&(n(t)&&null!==t?Array.isArray(t)?t.every((function(t){return[].some.call(e,(function(e){return o(t,e)}))})):Object.keys(t).every((function(r){var i=e[r],u=t[r];return n(u)&&null!==u&&null!==i?o(u,i):"boolean"==typeof u?u!==(null===i):i===u})):t===e)}}));n(A);var T=n(r((function(t,e){function n(t){return(0,A.iterate)(this,t)}e.__esModule=!0,e.default=function(t){var e="function"==typeof t?[t]:t||[],r={skipParse:!1};return{process:function(t,o){var i=(r=o||{}).parser||d.parse,u=r.render,a=r.data||null;if("function"!=typeof i)throw Error('"parser" is not a function, please pass to "process(input, { parser })" right function');var s=r.skipParse?t||[]:i(t,r),c=s;return s.messages=[],s.options=r,s.walk=n,s.match=A.match,e.forEach((function(t){s=t(s,{parse:i,render:u,iterate:A.iterate,match:A.match,data:a})||s})),{get html(){if("function"!=typeof u)throw Error('"render" function not defined, please pass to "process(input, { render })"');return u(s,s.options)},tree:s,raw:c,messages:s.messages}}}}}))),E="/>",v="</",h="<",_=">",y=function(t,e){var n=e.stripTags,r=void 0!==n&&n;if(!t)return"";var o=typeof t;return"string"===o||"number"===o?t:"object"===o?!0===r?L(t.content,{stripTags:r}):null===t.content?""+h+t.tag+c(t.attrs)+E:""+h+t.tag+c(t.attrs)+_+L(t.content)+v+t.tag+_:Array.isArray(t)?L(t,{stripTags:r}):""},L=function(t,e){var n=(void 0===e?{}:e).stripTags,r=void 0!==n&&n;return[].concat(t).reduce((function(t,e){return t+y(e,{stripTags:r})}),"")},O=L;t.default=function(t,n,r){return T(n).process(t,e({},r,{render:L})).html},t.render=O,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).BbobHtml={})}(this,(function(t){"use strict";function e(){return(e=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function r(t,e){return t(e={exports:{}},e.exports),e.exports}var i=r((function(t,e){e.__esModule=!0,e.BACKSLASH=e.PLACEHOLDER_SPACE=e.PLACEHOLDER_SPACE_TAB=e.SLASH=e.CLOSE_BRAKET=e.OPEN_BRAKET=e.SPACE=e.QUOTEMARK=e.EQ=e.TAB=e.R=e.F=e.N=void 0;e.N="\n";e.TAB="\t";e.F="\f";e.R="\r";e.EQ="=";e.QUOTEMARK='"';e.SPACE=" ";e.OPEN_BRAKET="[";e.CLOSE_BRAKET="]";e.SLASH="/";e.BACKSLASH="\\";e.PLACEHOLDER_SPACE_TAB=" ";e.PLACEHOLDER_SPACE=" "}));n(i);var o=r((function(t,e){e.__esModule=!0,e.isEOL=e.isStringNode=e.isTagNode=e.getUniqAttr=e.getNodeLength=e.escapeHTML=e.appendToNode=e.attrValue=e.attrsToString=void 0;var n=function(t){return"object"==typeof t&&!!t.tag};e.isTagNode=n;var r=function(t){return"string"==typeof t};e.isStringNode=r;e.isEOL=function(t){return t===i.N};var o=function(t,e,n){return Object.keys(t).reduce(e,n)};e.getNodeLength=function t(e){return n(e)?e.content.reduce((function(e,n){return e+t(n)}),0):r(e)?e.length:0};e.appendToNode=function(t,e){t.content.push(e)};var u=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")};e.escapeHTML=u;var a=function(t,e){var n=typeof e,r={boolean:function(){return e?""+t:""},number:function(){return t+'="'+e+'"'},string:function(){return t+'="'+u(e)+'"'},object:function(){return t+'="'+u(JSON.stringify(e))+'"'}};return r[n]?r[n]():""};e.attrValue=a;e.attrsToString=function(t){return null==t?"":o(t,(function(e,n){return[].concat(e,[a(n,t[n])])}),[""]).join(" ")};e.getUniqAttr=function(t){return o(t,(function(e,n){return t[n]===n?t[n]:null}),null)}}));n(o);var u=r((function(t,e){function n(t,e){for(var n=0;e.length>n;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function r(){return(r=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}e.__esModule=!0,e.default=e.TagNode=void 0;var u=function(){function t(t,e,n){this.tag=t,this.attrs=e,this.content=Array.isArray(n)?n:[n]}var e,u,a,s=t.prototype;return s.attr=function(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]},s.append=function(t){return(0,o.appendToNode)(this,t)},s.toTagNode=function(){return new t(this.tag.toLowerCase(),this.attrs,this.content)},s.toString=function(){var t=i.OPEN_BRAKET,e=i.CLOSE_BRAKET,n=0===this.content.length,u=this.content.reduce((function(t,e){return t+""+e}),""),a=function(t,e){var n=(0,o.getUniqAttr)(e);if(n){var i=(0,o.attrValue)(t,n),u=r({},e);return delete u[n],""+i+(0,o.attrsToString)(u)}return""+t+(0,o.attrsToString)(e)}(this.tag,this.attrs);return n?""+t+a+e:""+t+a+e+u+t+i.SLASH+this.tag+e},e=t,(u=[{key:"length",get:function(){return(0,o.getNodeLength)(this)}}])&&n(e.prototype,u),a&&n(e,a),t}();e.TagNode=u,u.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n=[]),new u(t,e,n)},u.isOf=function(t,e){return t.tag===e},e.default=u}));n(u);var a=r((function(t,e){e.__esModule=!0,e.default=e.Token=e.TYPE_NEW_LINE=e.TYPE_SPACE=e.TYPE_ATTR_VALUE=e.TYPE_ATTR_NAME=e.TYPE_TAG=e.TYPE_WORD=e.COLUMN_ID=e.LINE_ID=e.VALUE_ID=e.TYPE_ID=void 0;var n=function(t){return t&&void 0!==t.value?t.value:""},r=function(t){return n(t).charCodeAt(0)===i.SLASH.charCodeAt(0)},o=function(){function t(t,e,n,r){this.type=Number(t),this.value=e+"",this.line=Number(n),this.row=Number(r)}var e=t.prototype;return e.isEmpty=function(){return isNaN(this.type)},e.isText=function(){return!(!(t=this)||void 0===t.type||5!==t.type&&6!==t.type&&1!==t.type);var t},e.isTag=function(){return!(!(t=this)||void 0===t.type)&&2===t.type;var t},e.isAttrName=function(){return!(!(t=this)||void 0===t.type)&&3===t.type;var t},e.isAttrValue=function(){return!(!(t=this)||void 0===t.type)&&4===t.type;var t},e.isStart=function(){return!r(this)},e.isEnd=function(){return r(this)},e.getName=function(){return e=n(t=this),r(t)?e.slice(1):e;var t,e},e.getValue=function(){return n(this)},e.getLine=function(){return(t=this)&&t.line||0;var t},e.getColumn=function(){return(t=this)&&t.row||0;var t},e.toString=function(){return t=i.OPEN_BRAKET,t+=n(this),t+=i.CLOSE_BRAKET;var t},t}();e.Token=o;e.TYPE_ID="type";e.VALUE_ID="value";e.LINE_ID="line";e.COLUMN_ID="row";e.TYPE_WORD=1;e.TYPE_TAG=2;e.TYPE_ATTR_NAME=3;e.TYPE_ATTR_VALUE=4;e.TYPE_SPACE=5;e.TYPE_NEW_LINE=6,e.default=o}));n(a);var s=r((function(t,e){function n(t,e){var n={pos:0,len:t.length},r=function(){return n.len>n.pos},i=function(t,r){void 0===t&&(t=1),n.pos+=t,e&&e.onSkip&&!r&&e.onSkip()},o=function(){return t[n.pos]};this.skip=i,this.hasNext=r,this.getCurr=o,this.getRest=function(){return t.substr(n.pos)},this.getNext=function(){var e=n.pos+1;return e>t.length-1?null:t[e]},this.getPrev=function(){var e=n.pos-1;return void 0!==t[e]?t[e]:null},this.isLast=function(){return n.pos===n.len},this.includes=function(e){return t.indexOf(e,n.pos)>=0},this.grabWhile=function(e,u){var a=0;if(r())for(a=n.pos;r()&&e(o());)i(1,u);return t.substr(a,n.pos-a)},this.substrUntilChar=function(e){var r=n.pos,i=t.indexOf(e,r);return 0>i?"":t.substr(r,i-r)}}e.__esModule=!0,e.createList=e.unquote=e.trimChar=e.createCharGrabber=void 0;e.createCharGrabber=function(t,e){return new n(t,e)};e.trimChar=function(t,e){for(;t.charAt(0)===e;)t=t.substring(1);for(;t.charAt(t.length-1)===e;)t=t.substring(0,t.length-1);return t};function r(t){void 0===t&&(t=[]);var e=t;this.push=function(t){return e.push(t)},this.toArray=function(){return e},this.getLast=function(){return Array.isArray(e)&&e.length>0&&void 0!==e[e.length-1]?e[e.length-1]:null},this.flushLast=function(){return!!e.length&&e.pop()}}e.unquote=function(t){return t.replace(i.BACKSLASH+i.QUOTEMARK,i.QUOTEMARK)};e.createList=function(t){return void 0===t&&(t=[]),new r(t)}}));n(s);var c=r((function(t,e){e.__esModule=!0,e.createLexer=function(t,e){void 0===e&&(e={});var r=0,o=0,u=-1,c=0,f=0,l=Array(Math.floor(t.length)),p=e.openTag||i.OPEN_BRAKET,g=e.closeTag||i.CLOSE_BRAKET,A=!!e.enableEscapeTags,d=e.onToken||function(){},T=[g,p,i.QUOTEMARK,i.BACKSLASH,i.SPACE,i.TAB,i.EQ,i.N,"!"],E=[p,i.SPACE,i.TAB,i.N],v=[i.SPACE,i.TAB],h=[i.EQ,i.SPACE,i.TAB],_=function(t){return v.indexOf(t)>=0},L=function(t){return-1===E.indexOf(t)},y=function(t){return t===i.BACKSLASH},S=function(){o++},O=function(t){return(0,s.unquote)((0,s.trimChar)(t,i.QUOTEMARK))},N=(0,s.createCharGrabber)(t,{onSkip:S});function P(t,e){var i=n(t,e,r,o);d(i),l[u+=1]=i}function b(t,e){if(1===f){var n=t.grabWhile((function(t){return!(t===i.EQ||_(t))})),r=t.isLast(),o=t.getCurr()!==i.EQ;return t.skip(),r||o?P(a.TYPE_ATTR_VALUE,O(n)):P(a.TYPE_ATTR_NAME,n),r?0:o?1:2}if(2===f){var u=!1,s=t.grabWhile((function(n){var r=n===i.QUOTEMARK,o=t.getPrev(),a=t.getNext(),s=o===i.BACKSLASH,c=a===i.EQ,f=_(n),l=_(a);return!(!u||!function(t){return h.indexOf(t)>=0}(n))||!!(!r||s||(u=!u)||c||l)&&(!!e||!1===f)}));return t.skip(),P(a.TYPE_ATTR_VALUE,O(s)),t.isLast()?0:1}var c=t.grabWhile((function(e){return!(e===i.EQ||_(e)||t.isLast())}));return P(a.TYPE_TAG,c),t.skip(),e?2:t.includes(i.EQ)?1:2}function C(){var t=N.getCurr();if(t===p){var e=N.getNext();N.skip();var n=N.substrUntilChar(g),r=0===n.length||n.indexOf(p)>=0;if(T.indexOf(e)>=0||r||N.isLast())return P(a.TYPE_WORD,t),0;if(-1===n.indexOf(i.EQ)||n[0]===i.SLASH){var o=N.grabWhile((function(t){return t!==g}));return N.skip(),P(a.TYPE_TAG,o),0}return 2}return 0}function R(){for(var t=N.grabWhile((function(t){return t!==g}),!0),e=(0,s.createCharGrabber)(t,{onSkip:S}),n=e.includes(i.SPACE);e.hasNext();)f=b(e,!n);return N.skip(),0}function k(){if(N.getCurr()===i.N)return P(a.TYPE_NEW_LINE,N.getCurr()),N.skip(),o=0,r++,0;if(_(N.getCurr()))return P(a.TYPE_SPACE,N.grabWhile(_)),0;if(N.getCurr()===p)return N.includes(g)?1:(P(a.TYPE_WORD,N.getCurr()),N.skip(),0);if(A){if(y(N.getCurr())){var t=N.getCurr(),e=N.getNext();return N.skip(),function(t){return t===p||t===g||t===i.BACKSLASH}(e)?(N.skip(),P(a.TYPE_WORD,e),0):(P(a.TYPE_WORD,t),0)}return P(a.TYPE_WORD,N.grabWhile((function(t){return L(t)&&!y(t)}))),0}return P(a.TYPE_WORD,N.grabWhile(L)),0}return{tokenize:function(){for(;N.hasNext();)switch(c){case 1:c=C();break;case 2:c=R();break;case 0:c=k();break;default:c=0}return l.length=u+1,l},isTokenNested:function(e){var n=p+i.SLASH+e.getValue();return t.indexOf(n)>-1}}},e.createTokenOfType=void 0;var n=function(t,e,n,r){return void 0===n&&(n=0),void 0===r&&(r=0),new a.Token(t,e,n,r)};e.createTokenOfType=n}));n(c);var f=r((function(t,e){e.__esModule=!0,e.default=e.parse=void 0;var n,r=(n=u)&&n.__esModule?n:{default:n};var i=function(t,e){void 0===e&&(e={});var n=e,i=null,u=(0,s.createList)(),a=(0,s.createList)(),f=(0,s.createList)(),l=(0,s.createList)(),p={},g=function(){f.flushLast()&&l.flushLast()},A=function(t){var e,r,i=(e=a.getLast())&&Array.isArray(e.content)?e.content:u.toArray();Array.isArray(i)&&((0,o.isTagNode)(t)?(r=t.tag,n.onlyAllowTags&&n.onlyAllowTags.length&&0>n.onlyAllowTags.indexOf(r)?i.push(""+t):i.push(t.toTagNode())):i.push(t))},d=function(t){g();var e=r.default.create(t.getValue()),n=function(t){return void 0===p[t.getValue()]&&(p[t.getValue()]=i.isTokenNested(t)),p[t.getValue()]}(t);f.push(e),n?a.push(e):A(e)},T=function(t){t.isStart()&&d(t),t.isEnd()&&function(t){g();var e=a.flushLast();if(e)A(e);else if("function"==typeof n.onError){var r=t.getValue(),i=t.getLine(),o=t.getColumn();n.onError({message:"Inconsistent tag '"+r+"' on line "+i+" and column "+o,tagName:r,lineNumber:i,columnNumber:o})}}(t)},E=function(t){var e=f.getLast(),n=t.getValue(),r=!!p[t];if(e)if(t.isAttrName())l.push(n),e.attr(l.getLast(),"");else if(t.isAttrValue()){var i=l.getLast();i?(e.attr(i,n),l.flushLast()):e.attr(n,n)}else t.isText()?r?e.append(n):A(n):t.isTag()&&A(""+t);else t.isText()?A(n):t.isTag()&&A(""+t)};(i=(e.createTokenizer?e.createTokenizer:c.createLexer)(t,{onToken:function(t){t.isTag()?T(t):E(t)},onlyAllowTags:n.onlyAllowTags,openTag:n.openTag,closeTag:n.closeTag,enableEscapeTags:n.enableEscapeTags})).tokenize();return u.toArray()};e.parse=i,e.default=i}));n(f);var l=r((function(t,e){e.__esModule=!0,e.TagNode=e.parse=e.default=void 0;var n=function(t){if(t&&t.__esModule)return t;if(null===t||"object"!=typeof t&&"function"!=typeof t)return{default:t};var e=r();if(e&&e.has(t))return e.get(t);var n={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var u=i?Object.getOwnPropertyDescriptor(t,o):null;u&&(u.get||u.set)?Object.defineProperty(n,o,u):n[o]=t[o]}n.default=t,e&&e.set(t,n);return n}(f);function r(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return r=function(){return t},t}e.default=n.default,e.parse=n.parse,e.TagNode=u.TagNode}));n(l);var p=r((function(t,e){e.__esModule=!0,e.iterate=r,e.match=function(t,e){return r(this,Array.isArray(t)?function(n){for(var r=0;t.length>r;r++)if(i(t[r],n))return e(n);return n}:function(n){return i(t,n)?e(n):n})};var n=function(t){return"object"==typeof t};function r(t,e){var i=t;if(Array.isArray(i))for(var o=0;i.length>o;o++)i[o]=r(e(i[o]),e);else i&&n(i)&&i.content&&r(i.content,e);return i}function i(t,e){return typeof t==typeof e&&(n(t)&&null!==t?Array.isArray(t)?t.every((function(t){return[].some.call(e,(function(e){return i(t,e)}))})):Object.keys(t).every((function(r){var o=e[r],u=t[r];return n(u)&&null!==u&&null!==o?i(u,o):"boolean"==typeof u?u!==(null===o):o===u})):t===e)}}));n(p);var g=n(r((function(t,e){function n(t){return(0,p.iterate)(this,t)}e.__esModule=!0,e.default=function(t){var e="function"==typeof t?[t]:t||[],r={skipParse:!1};return{process:function(t,i){var o=(r=i||{}).parser||l.parse,u=r.render,a=r.data||null;if("function"!=typeof o)throw Error('"parser" is not a function, please pass to "process(input, { parser })" right function');var s=r.skipParse?t||[]:o(t,r),c=s;return s.messages=[],s.options=r,s.walk=n,s.match=p.match,e.forEach((function(t){s=t(s,{parse:o,render:u,iterate:p.iterate,match:p.match,data:a})||s})),{get html(){if("function"!=typeof u)throw Error('"render" function not defined, please pass to "process(input, { render })"');return u(s,s.options)},tree:s,raw:c,messages:s.messages}}}}}))),A=r((function(t,e){e.__esModule=!0,e.BACKSLASH=e.PLACEHOLDER_SPACE=e.PLACEHOLDER_SPACE_TAB=e.SLASH=e.CLOSE_BRAKET=e.OPEN_BRAKET=e.SPACE=e.QUOTEMARK=e.EQ=e.TAB=e.R=e.F=e.N=void 0;e.N="\n";e.TAB="\t";e.F="\f";e.R="\r";e.EQ="=";e.QUOTEMARK='"';e.SPACE=" ";e.OPEN_BRAKET="[";e.CLOSE_BRAKET="]";e.SLASH="/";e.BACKSLASH="\\";e.PLACEHOLDER_SPACE_TAB=" ";e.PLACEHOLDER_SPACE=" "}));n(A);var d=r((function(t,e){e.__esModule=!0,e.isEOL=e.isStringNode=e.isTagNode=e.getUniqAttr=e.getNodeLength=e.escapeHTML=e.appendToNode=e.attrValue=e.attrsToString=void 0;var n=function(t){return"object"==typeof t&&!!t.tag};e.isTagNode=n;var r=function(t){return"string"==typeof t};e.isStringNode=r;e.isEOL=function(t){return t===A.N};var i=function(t,e,n){return Object.keys(t).reduce(e,n)};e.getNodeLength=function t(e){return n(e)?e.content.reduce((function(e,n){return e+t(n)}),0):r(e)?e.length:0};e.appendToNode=function(t,e){t.content.push(e)};var o=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")};e.escapeHTML=o;var u=function(t,e){var n=typeof e,r={boolean:function(){return e?""+t:""},number:function(){return t+'="'+e+'"'},string:function(){return t+'="'+o(e)+'"'},object:function(){return t+'="'+o(JSON.stringify(e))+'"'}};return r[n]?r[n]():""};e.attrValue=u;e.attrsToString=function(t){return null==t?"":i(t,(function(e,n){return[].concat(e,[u(n,t[n])])}),[""]).join(" ")};e.getUniqAttr=function(t){return i(t,(function(e,n){return t[n]===n?t[n]:null}),null)}}));n(d);var T=d.attrsToString,E="/>",v="</",h="<",_=">",L=function(t,e){var n=e.stripTags,r=void 0!==n&&n;if(!t)return"";var i=typeof t;return"string"===i||"number"===i?t:"object"===i?!0===r?y(t.content,{stripTags:r}):null===t.content?""+h+t.tag+T(t.attrs)+E:""+h+t.tag+T(t.attrs)+_+y(t.content)+v+t.tag+_:Array.isArray(t)?y(t,{stripTags:r}):""},y=function(t,e){var n=(void 0===e?{}:e).stripTags,r=void 0!==n&&n;return[].concat(t).reduce((function(t,e){return t+L(e,{stripTags:r})}),"")},S=y;t.default=function(t,n,r){return g(n).process(t,e({},r,{render:y})).html},t.render=S,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@bbob/html", | ||
"version": "2.5.8", | ||
"version": "2.6.0", | ||
"description": "HTML renderer for @bbob bbcode parser", | ||
"keywords": [], | ||
"dependencies": { | ||
"@bbob/core": "^2.5.8", | ||
"@bbob/plugin-helper": "^2.5.8" | ||
"@bbob/core": "^2.6.0", | ||
"@bbob/plugin-helper": "^2.6.0" | ||
}, | ||
@@ -56,3 +56,3 @@ "main": "lib/index.js", | ||
], | ||
"gitHead": "2eb1fbcccf065a95df2c1a28020119582d4a64d1" | ||
"gitHead": "99f503df0cc35d33c9e57d49b6581631d49ab6c3" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76993
1739
Updated@bbob/core@^2.6.0
Updated@bbob/plugin-helper@^2.6.0