@bbob/html
Advanced tools
Comparing version 2.5.4 to 2.5.5
@@ -6,2 +6,10 @@ # Change Log | ||
## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) | ||
**Note:** Version bump only for package @bbob/html | ||
<a name="2.5.4"></a> | ||
@@ -8,0 +16,0 @@ ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) |
2512
dist/index.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.BbobHtml = {}))); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.BbobHtml = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
var char_1 = createCommonjsModule(function (module, exports) { | ||
return target; | ||
}; | ||
exports.__esModule = true; | ||
var N = '\n'; | ||
var TAB = '\t'; | ||
var F = '\f'; | ||
var R = '\r'; | ||
return _extends.apply(this, arguments); | ||
} | ||
var EQ = '='; | ||
var QUOTEMARK = '"'; | ||
var SPACE = ' '; | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
var OPEN_BRAKET = '['; | ||
var CLOSE_BRAKET = ']'; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var SLASH = '/'; | ||
var BACKSLASH = '\\'; | ||
var char_1 = createCommonjsModule(function (module, exports) { | ||
var PLACEHOLDER_SPACE_TAB = ' '; | ||
var PLACEHOLDER_SPACE = ' '; | ||
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; | ||
// const getChar = String.fromCharCode; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
}); | ||
exports.N = N; | ||
exports.F = F; | ||
exports.R = R; | ||
exports.TAB = TAB; | ||
exports.EQ = EQ; | ||
exports.QUOTEMARK = QUOTEMARK; | ||
exports.SPACE = SPACE; | ||
exports.OPEN_BRAKET = OPEN_BRAKET; | ||
exports.CLOSE_BRAKET = CLOSE_BRAKET; | ||
exports.SLASH = SLASH; | ||
exports.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
exports.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
exports.BACKSLASH = BACKSLASH; | ||
}); | ||
unwrapExports(char_1); | ||
var char_2 = char_1.BACKSLASH; | ||
var char_3 = char_1.PLACEHOLDER_SPACE; | ||
var char_4 = char_1.PLACEHOLDER_SPACE_TAB; | ||
var char_5 = char_1.SLASH; | ||
var char_6 = char_1.CLOSE_BRAKET; | ||
var char_7 = char_1.OPEN_BRAKET; | ||
var char_8 = char_1.SPACE; | ||
var char_9 = char_1.QUOTEMARK; | ||
var char_10 = char_1.EQ; | ||
var char_11 = char_1.TAB; | ||
var char_12 = char_1.R; | ||
var char_13 = char_1.F; | ||
var char_14 = char_1.N; | ||
unwrapExports(char_1); | ||
var char_2 = char_1.N; | ||
var char_3 = char_1.F; | ||
var char_4 = char_1.R; | ||
var char_5 = char_1.TAB; | ||
var char_6 = char_1.EQ; | ||
var char_7 = char_1.QUOTEMARK; | ||
var char_8 = char_1.SPACE; | ||
var char_9 = char_1.OPEN_BRAKET; | ||
var char_10 = char_1.CLOSE_BRAKET; | ||
var char_11 = char_1.SLASH; | ||
var char_12 = char_1.PLACEHOLDER_SPACE_TAB; | ||
var char_13 = char_1.PLACEHOLDER_SPACE; | ||
var char_14 = char_1.BACKSLASH; | ||
var lib = createCommonjsModule(function (module, exports) { | ||
var lib = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getNodeLength = exports.appendToNode = exports.attrValue = exports.attrsToString = void 0; | ||
exports.__esModule = true; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getNodeLength = exports.appendToNode = exports.attrValue = exports.attrsToString = undefined; | ||
var isTagNode = function isTagNode(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
var isTagNode = function isTagNode(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
var isStringNode = function isStringNode(el) { | ||
return typeof el === 'string'; | ||
}; | ||
var isEOL = function isEOL(el) { | ||
return el === char_1.N; | ||
}; | ||
exports.isTagNode = isTagNode; | ||
var getNodeLength = function getNodeLength(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function (count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} else if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
var isStringNode = function isStringNode(el) { | ||
return typeof el === 'string'; | ||
}; | ||
return 0; | ||
}; | ||
exports.isStringNode = isStringNode; | ||
/** | ||
* Appends value to Tag Node | ||
* @param {TagNode} node | ||
* @param value | ||
*/ | ||
var appendToNode = function appendToNode(node, value) { | ||
node.content.push(value); | ||
}; | ||
var isEOL = function isEOL(el) { | ||
return el === char_1.N; | ||
}; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ | ||
var escapeQuote = function escapeQuote(value) { | ||
return value.replace(/"/g, '"'); | ||
}; | ||
exports.isEOL = isEOL; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ | ||
var attrValue = function attrValue(name, value) { | ||
var type = typeof value; | ||
var getNodeLength = function getNodeLength(node) { | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function (count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
} | ||
var types = { | ||
boolean: function boolean() { | ||
return value ? '' + name : ''; | ||
}, | ||
number: function number() { | ||
return name + '="' + value + '"'; | ||
}, | ||
string: function string() { | ||
return name + '="' + escapeQuote(value) + '"'; | ||
}, | ||
object: function object() { | ||
return name + '="' + escapeQuote(JSON.stringify(value)) + '"'; | ||
} | ||
}; | ||
if (isStringNode(node)) { | ||
return node.length; | ||
} | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
return 0; | ||
}; | ||
/** | ||
* Appends value to Tag Node | ||
* @param {TagNode} node | ||
* @param value | ||
*/ | ||
/** | ||
* Transforms attrs to html params string | ||
* @param values | ||
*/ | ||
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(' '); | ||
}; | ||
exports.getNodeLength = getNodeLength; | ||
exports.attrsToString = attrsToString; | ||
exports.attrValue = attrValue; | ||
exports.appendToNode = appendToNode; | ||
exports.getNodeLength = getNodeLength; | ||
exports.isTagNode = isTagNode; | ||
exports.isStringNode = isStringNode; | ||
exports.isEOL = isEOL; | ||
}); | ||
var appendToNode = function appendToNode(node, value) { | ||
node.content.push(value); | ||
}; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ | ||
unwrapExports(lib); | ||
var lib_1 = lib.isEOL; | ||
var lib_2 = lib.isStringNode; | ||
var lib_3 = lib.isTagNode; | ||
var lib_4 = lib.getNodeLength; | ||
var lib_5 = lib.appendToNode; | ||
var lib_6 = lib.attrValue; | ||
var lib_7 = lib.attrsToString; | ||
var TagNode_1 = createCommonjsModule(function (module, exports) { | ||
exports.appendToNode = appendToNode; | ||
exports.__esModule = true; | ||
exports.TagNode = undefined; | ||
var escapeQuote = function escapeQuote(value) { | ||
return value.replace(/"/g, '"'); | ||
}; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ | ||
var _createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
}return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; | ||
}; | ||
}(); | ||
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 + "=\"" + escapeQuote(value) + "\""; | ||
}, | ||
object: function object() { | ||
return name + "=\"" + escapeQuote(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 ''; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
return Object.keys(values).reduce(function (arr, key) { | ||
return [].concat(arr, [attrValue(key, values[key])]); | ||
}, ['']).join(' '); | ||
}; | ||
var TagNode = function () { | ||
function TagNode(tag, attrs, content) { | ||
_classCallCheck(this, TagNode); | ||
exports.attrsToString = attrsToString; | ||
}); | ||
this.tag = tag.toLowerCase(); | ||
this.attrs = attrs; | ||
this.content = [].concat(content); | ||
} | ||
unwrapExports(lib); | ||
var lib_1 = lib.isEOL; | ||
var lib_2 = lib.isStringNode; | ||
var lib_3 = lib.isTagNode; | ||
var lib_4 = lib.getNodeLength; | ||
var lib_5 = lib.appendToNode; | ||
var lib_6 = lib.attrValue; | ||
var lib_7 = lib.attrsToString; | ||
TagNode.prototype.attr = function attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
} | ||
var TagNode_1 = createCommonjsModule(function (module, exports) { | ||
return this.attrs[name]; | ||
}; | ||
exports.__esModule = true; | ||
exports["default"] = exports.TagNode = void 0; | ||
TagNode.prototype.append = function append(value) { | ||
return (0, lib.appendToNode)(this, value); | ||
}; | ||
TagNode.prototype.toString = function toString() { | ||
var OB = char_1.OPEN_BRAKET; | ||
var CB = char_1.CLOSE_BRAKET; | ||
return OB + this.tag + CB + this.content.reduce(function (r, node) { | ||
return r + node.toString(); | ||
}, '') + OB + char_1.SLASH + this.tag + CB; | ||
}; | ||
_createClass(TagNode, [{ | ||
key: 'length', | ||
get: function get() { | ||
return (0, lib.getNodeLength)(this); | ||
} | ||
}]); | ||
return TagNode; | ||
}(); | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
TagNode.create = function (tag) { | ||
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var content = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
return new TagNode(tag, attrs, content); | ||
}; | ||
TagNode.isOf = function (node, type) { | ||
return node.tag === type; | ||
}; | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
exports.TagNode = TagNode; | ||
exports.default = TagNode; | ||
}); | ||
var TagNode = | ||
/*#__PURE__*/ | ||
function () { | ||
function TagNode(tag, attrs, content) { | ||
this.tag = tag.toLowerCase(); | ||
this.attrs = attrs; | ||
this.content = [].concat(content); | ||
} | ||
var TagNode = unwrapExports(TagNode_1); | ||
var TagNode_2 = TagNode_1.TagNode; | ||
var _proto = TagNode.prototype; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
_proto.attr = function attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
} | ||
// type, value, line, row, | ||
var TOKEN_TYPE_ID = 'type'; // 0; | ||
var TOKEN_VALUE_ID = 'value'; // 1; | ||
var TOKEN_COLUMN_ID = 'row'; // 2; | ||
var TOKEN_LINE_ID = 'line'; // 3; | ||
return this.attrs[name]; | ||
}; | ||
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'; | ||
_proto.append = function append(value) { | ||
return (0, lib.appendToNode)(this, value); | ||
}; | ||
var getTokenValue = function getTokenValue(token) { | ||
return token[TOKEN_VALUE_ID]; | ||
}; | ||
var getTokenLine = function getTokenLine(token) { | ||
return token[TOKEN_LINE_ID]; | ||
}; | ||
var getTokenColumn = function getTokenColumn(token) { | ||
return token[TOKEN_COLUMN_ID]; | ||
}; | ||
_proto.toString = function toString() { | ||
var OB = char_1.OPEN_BRAKET; | ||
var CB = char_1.CLOSE_BRAKET; | ||
return OB + this.tag + CB + this.content.reduce(function (r, node) { | ||
return r + node.toString(); | ||
}, '') + OB + char_1.SLASH + this.tag + CB; | ||
}; | ||
var isTextToken = function isTextToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD; | ||
}; | ||
_createClass(TagNode, [{ | ||
key: "length", | ||
get: function get() { | ||
return (0, lib.getNodeLength)(this); | ||
} | ||
}]); | ||
var isTagToken = function isTagToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; | ||
}; | ||
var isTagEnd = function isTagEnd(token) { | ||
return getTokenValue(token).charCodeAt(0) === char_11.charCodeAt(0); | ||
}; | ||
var isTagStart = function isTagStart(token) { | ||
return !isTagEnd(token); | ||
}; | ||
var isAttrNameToken = function isAttrNameToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; | ||
}; | ||
var isAttrValueToken = function isAttrValueToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; | ||
}; | ||
return TagNode; | ||
}(); | ||
var getTagName = function getTagName(token) { | ||
var value = getTokenValue(token); | ||
exports.TagNode = TagNode; | ||
return isTagEnd(token) ? value.slice(1) : value; | ||
}; | ||
TagNode.create = function (tag, attrs, content) { | ||
if (attrs === void 0) { | ||
attrs = {}; | ||
} | ||
var convertTagToText = function convertTagToText(token) { | ||
var text = char_9; | ||
if (content === void 0) { | ||
content = []; | ||
} | ||
text += getTokenValue(token); | ||
text += char_10; | ||
return new TagNode(tag, attrs, content); | ||
}; | ||
return text; | ||
}; | ||
TagNode.isOf = function (node, type) { | ||
return node.tag === type; | ||
}; | ||
var Token = function () { | ||
/** | ||
* @param {String} type | ||
* @param {String} value | ||
* @param line | ||
* @param row | ||
*/ | ||
function Token(type, value, line, row) { | ||
_classCallCheck(this, Token); | ||
var _default = TagNode; | ||
exports["default"] = _default; | ||
}); | ||
this[TOKEN_TYPE_ID] = String(type); | ||
this[TOKEN_VALUE_ID] = String(value); | ||
this[TOKEN_LINE_ID] = Number(line); | ||
this[TOKEN_COLUMN_ID] = Number(row); | ||
} | ||
unwrapExports(TagNode_1); | ||
var TagNode_2 = TagNode_1.TagNode; | ||
Token.prototype.isEmpty = function isEmpty() { | ||
return !!this[TOKEN_TYPE_ID]; | ||
}; | ||
var Token_1 = createCommonjsModule(function (module, exports) { | ||
Token.prototype.isText = function isText() { | ||
return isTextToken(this); | ||
}; | ||
exports.__esModule = true; | ||
exports.default = exports.Token = exports.TYPE_NEW_LINE = exports.TYPE_SPACE = exports.TYPE_ATTR_VALUE = exports.TYPE_ATTR_NAME = exports.TYPE_TAG = exports.TYPE_WORD = exports.COLUMN_ID = exports.LINE_ID = exports.VALUE_ID = exports.TYPE_ID = void 0; | ||
Token.prototype.isTag = function isTag() { | ||
return isTagToken(this); | ||
}; | ||
// type, value, line, row, | ||
Token.prototype.isAttrName = function isAttrName() { | ||
return isAttrNameToken(this); | ||
}; | ||
Token.prototype.isAttrValue = function isAttrValue() { | ||
return isAttrValueToken(this); | ||
}; | ||
var TOKEN_TYPE_ID = 'type'; // 0; | ||
Token.prototype.isStart = function isStart() { | ||
return isTagStart(this); | ||
}; | ||
var TOKEN_VALUE_ID = 'value'; // 1; | ||
Token.prototype.isEnd = function isEnd() { | ||
return isTagEnd(this); | ||
}; | ||
var TOKEN_COLUMN_ID = 'row'; // 2; | ||
Token.prototype.getName = function getName() { | ||
return getTagName(this); | ||
}; | ||
var TOKEN_LINE_ID = 'line'; // 3; | ||
Token.prototype.getValue = function getValue() { | ||
return getTokenValue(this); | ||
}; | ||
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'; | ||
Token.prototype.getLine = function getLine() { | ||
return getTokenLine(this); | ||
}; | ||
var getTokenValue = function getTokenValue(token) { | ||
return token[TOKEN_VALUE_ID]; | ||
}; | ||
Token.prototype.getColumn = function getColumn() { | ||
return getTokenColumn(this); | ||
}; | ||
var getTokenLine = function getTokenLine(token) { | ||
return token[TOKEN_LINE_ID]; | ||
}; | ||
Token.prototype.toString = function toString() { | ||
return convertTagToText(this); | ||
}; | ||
var getTokenColumn = function getTokenColumn(token) { | ||
return token[TOKEN_COLUMN_ID]; | ||
}; | ||
return Token; | ||
}(); | ||
var TYPE_WORD = TOKEN_TYPE_WORD; | ||
var TYPE_TAG = TOKEN_TYPE_TAG; | ||
var TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME; | ||
var TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE; | ||
var TYPE_SPACE = TOKEN_TYPE_SPACE; | ||
var TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE; | ||
var isTextToken = function isTextToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD; | ||
}; | ||
/** | ||
* @typedef {Object} CharGrabber | ||
* @property {Function} skip | ||
* @property {Function} hasNext | ||
* @property {Function} isLast | ||
* @property {Function} grabWhile | ||
*/ | ||
var isTagToken = function isTagToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; | ||
}; | ||
/** | ||
* 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; | ||
var cursor = { | ||
pos: 0, | ||
length: source.length | ||
}; | ||
var isTagEnd = function isTagEnd(token) { | ||
return getTokenValue(token).charCodeAt(0) === char_1.SLASH.charCodeAt(0); | ||
}; | ||
var skip = function skip() { | ||
cursor.pos += 1; | ||
var isTagStart = function isTagStart(token) { | ||
return !isTagEnd(token); | ||
}; | ||
if (options && options.onSkip) { | ||
options.onSkip(); | ||
} | ||
}; | ||
var hasNext = function hasNext() { | ||
return cursor.length > cursor.pos; | ||
}; | ||
var getRest = function getRest() { | ||
return source.substr(cursor.pos); | ||
}; | ||
var getCurr = function getCurr() { | ||
return source[cursor.pos]; | ||
}; | ||
var isAttrNameToken = function isAttrNameToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; | ||
}; | ||
return { | ||
skip: skip, | ||
hasNext: hasNext, | ||
isLast: function isLast() { | ||
return cursor.pos === cursor.length; | ||
}, | ||
/** | ||
* @param {Function} cond | ||
* @returns {string} | ||
*/ | ||
grabWhile: function grabWhile(cond) { | ||
var start = 0; | ||
var isAttrValueToken = function isAttrValueToken(token) { | ||
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; | ||
}; | ||
if (hasNext()) { | ||
start = cursor.pos; | ||
var getTagName = function getTagName(token) { | ||
var value = getTokenValue(token); | ||
return isTagEnd(token) ? value.slice(1) : value; | ||
}; | ||
while (hasNext() && cond(getCurr())) { | ||
skip(); | ||
} | ||
} | ||
var convertTagToText = function convertTagToText(token) { | ||
var text = char_1.OPEN_BRAKET; | ||
text += getTokenValue(token); | ||
text += char_1.CLOSE_BRAKET; | ||
return text; | ||
}; | ||
return source.substr(start, cursor.pos - start); | ||
}, | ||
getNext: function getNext() { | ||
return source[cursor.pos + 1]; | ||
}, | ||
getPrev: function getPrev() { | ||
return source[cursor.pos - 1]; | ||
}, | ||
getCurr: getCurr, | ||
getRest: getRest, | ||
/** | ||
* Grabs rest of string until it find a char | ||
* @param {String} char | ||
* @return {String} | ||
*/ | ||
substrUntilChar: function substrUntilChar(char$$1) { | ||
var restStr = getRest(); | ||
var indexOfChar = restStr.indexOf(char$$1); | ||
var Token = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* @param {String} type | ||
* @param {String} value | ||
* @param line | ||
* @param row | ||
*/ | ||
function Token(type, value, line, row) { | ||
this[TOKEN_TYPE_ID] = String(type); | ||
this[TOKEN_VALUE_ID] = String(value); | ||
this[TOKEN_LINE_ID] = Number(line); | ||
this[TOKEN_COLUMN_ID] = Number(row); | ||
} | ||
if (indexOfChar >= 0) { | ||
return restStr.substr(0, indexOfChar); | ||
} | ||
var _proto = Token.prototype; | ||
return ''; | ||
} | ||
}; | ||
}; | ||
_proto.isEmpty = function isEmpty() { | ||
return !!this[TOKEN_TYPE_ID]; | ||
}; | ||
/** | ||
* Trims string from start and end by char | ||
* @example | ||
* trimChar('*hello*', '*') ==> 'hello' | ||
* @param {String} str | ||
* @param {String} charToRemove | ||
* @returns {String} | ||
*/ | ||
var trimChar = function trimChar(str, charToRemove) { | ||
while (str.charAt(0) === charToRemove) { | ||
// eslint-disable-next-line no-param-reassign | ||
str = str.substring(1); | ||
} | ||
_proto.isText = function isText() { | ||
return isTextToken(this); | ||
}; | ||
while (str.charAt(str.length - 1) === charToRemove) { | ||
// eslint-disable-next-line no-param-reassign | ||
str = str.substring(0, str.length - 1); | ||
} | ||
_proto.isTag = function isTag() { | ||
return isTagToken(this); | ||
}; | ||
return str; | ||
}; | ||
_proto.isAttrName = function isAttrName() { | ||
return isAttrNameToken(this); | ||
}; | ||
/** | ||
* Unquotes \" to " | ||
* @param str | ||
* @return {String} | ||
*/ | ||
var unquote = function unquote(str) { | ||
return str.replace(char_14 + char_7, char_7); | ||
}; | ||
_proto.isAttrValue = function isAttrValue() { | ||
return isAttrValueToken(this); | ||
}; | ||
/** | ||
* @typedef {Object} ItemList | ||
* @type {Object} | ||
* @property {getLastCb} getLast | ||
* @property {flushLastCb} flushLast | ||
* @property {pushCb} push | ||
* @property {toArrayCb} toArray | ||
*/ | ||
_proto.isStart = function isStart() { | ||
return isTagStart(this); | ||
}; | ||
/** | ||
* | ||
* @param values | ||
* @return {ItemList} | ||
*/ | ||
var createList = function createList() { | ||
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
_proto.isEnd = function isEnd() { | ||
return isTagEnd(this); | ||
}; | ||
var nodes = values; | ||
/** | ||
* @callback getLastCb | ||
*/ | ||
var getLast = function getLast() { | ||
return nodes.length ? nodes[nodes.length - 1] : null; | ||
}; | ||
/** | ||
* @callback flushLastCb | ||
* @return {*} | ||
*/ | ||
var flushLast = function flushLast() { | ||
if (nodes.length) { | ||
return nodes.pop(); | ||
} | ||
_proto.getName = function getName() { | ||
return getTagName(this); | ||
}; | ||
return false; | ||
}; | ||
/** | ||
* @callback pushCb | ||
* @param value | ||
*/ | ||
var push = function push(value) { | ||
return nodes.push(value); | ||
}; | ||
_proto.getValue = function getValue() { | ||
return getTokenValue(this); | ||
}; | ||
/** | ||
* @callback toArrayCb | ||
* @return {Array} | ||
*/ | ||
_proto.getLine = function getLine() { | ||
return getTokenLine(this); | ||
}; | ||
return { | ||
getLast: getLast, | ||
flushLast: flushLast, | ||
push: push, | ||
toArray: function toArray() { | ||
return nodes; | ||
} | ||
}; | ||
}; | ||
_proto.getColumn = function getColumn() { | ||
return getTokenColumn(this); | ||
}; | ||
/* eslint-disable no-plusplus,no-param-reassign */ | ||
_proto.toString = function toString() { | ||
return convertTagToText(this); | ||
}; | ||
// for cases <!-- --> | ||
var EM = '!'; | ||
return Token; | ||
}(); | ||
/** | ||
* Creates a Token entity class | ||
* @param {String} type | ||
* @param {String} value | ||
* @param {Number} r line number | ||
* @param {Number} cl char number in line | ||
*/ | ||
var createToken = function createToken(type, value) { | ||
var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var cl = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; | ||
return new Token(type, value, r, cl); | ||
}; | ||
exports.Token = Token; | ||
var TYPE_ID = TOKEN_TYPE_ID; | ||
exports.TYPE_ID = TYPE_ID; | ||
var VALUE_ID = TOKEN_VALUE_ID; | ||
exports.VALUE_ID = VALUE_ID; | ||
var LINE_ID = TOKEN_LINE_ID; | ||
exports.LINE_ID = LINE_ID; | ||
var COLUMN_ID = TOKEN_COLUMN_ID; | ||
exports.COLUMN_ID = COLUMN_ID; | ||
var TYPE_WORD = TOKEN_TYPE_WORD; | ||
exports.TYPE_WORD = TYPE_WORD; | ||
var TYPE_TAG = TOKEN_TYPE_TAG; | ||
exports.TYPE_TAG = TYPE_TAG; | ||
var TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME; | ||
exports.TYPE_ATTR_NAME = TYPE_ATTR_NAME; | ||
var TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE; | ||
exports.TYPE_ATTR_VALUE = TYPE_ATTR_VALUE; | ||
var TYPE_SPACE = TOKEN_TYPE_SPACE; | ||
exports.TYPE_SPACE = TYPE_SPACE; | ||
var TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE; | ||
exports.TYPE_NEW_LINE = TYPE_NEW_LINE; | ||
var _default = Token; | ||
exports.default = _default; | ||
}); | ||
/** | ||
* @typedef {Object} Lexer | ||
* @property {Function} tokenize | ||
* @property {Function} isTokenNested | ||
*/ | ||
unwrapExports(Token_1); | ||
var Token_2 = Token_1.Token; | ||
var Token_3 = Token_1.TYPE_NEW_LINE; | ||
var Token_4 = Token_1.TYPE_SPACE; | ||
var Token_5 = Token_1.TYPE_ATTR_VALUE; | ||
var Token_6 = Token_1.TYPE_ATTR_NAME; | ||
var Token_7 = Token_1.TYPE_TAG; | ||
var Token_8 = Token_1.TYPE_WORD; | ||
var Token_9 = Token_1.COLUMN_ID; | ||
var Token_10 = Token_1.LINE_ID; | ||
var Token_11 = Token_1.VALUE_ID; | ||
var Token_12 = Token_1.TYPE_ID; | ||
/** | ||
* @param {String} buffer | ||
* @param {Object} options | ||
* @param {Function} options.onToken | ||
* @param {String} options.openTag | ||
* @param {String} options.closeTag | ||
* @param {Boolean} options.enableEscapeTags | ||
* @return {Lexer} | ||
*/ | ||
function createLexer(buffer) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var utils = createCommonjsModule(function (module, exports) { | ||
var row = 0; | ||
var col = 0; | ||
exports.__esModule = true; | ||
exports.createList = exports.unquote = exports.trimChar = exports.createCharGrabber = void 0; | ||
var tokenIndex = -1; | ||
var tokens = new Array(Math.floor(buffer.length)); | ||
var openTag = options.openTag || char_9; | ||
var closeTag = options.closeTag || char_10; | ||
var escapeTags = options.enableEscapeTags; | ||
var RESERVED_CHARS = [closeTag, openTag, char_7, char_14, char_8, char_5, char_6, char_2, EM]; | ||
var NOT_CHAR_TOKENS = [ | ||
// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, char_8, char_5, char_2]; | ||
var WHITESPACES = [char_8, char_5]; | ||
var SPECIAL_CHARS = [char_6, char_8, char_5]; | ||
/** | ||
* @typedef {Object} CharGrabber | ||
* @property {Function} skip | ||
* @property {Function} hasNext | ||
* @property {Function} isLast | ||
* @property {Function} grabWhile | ||
*/ | ||
var isCharReserved = function isCharReserved(char$$1) { | ||
return RESERVED_CHARS.indexOf(char$$1) >= 0; | ||
}; | ||
var isWhiteSpace = function isWhiteSpace(char$$1) { | ||
return WHITESPACES.indexOf(char$$1) >= 0; | ||
}; | ||
var isCharToken = function isCharToken(char$$1) { | ||
return NOT_CHAR_TOKENS.indexOf(char$$1) === -1; | ||
}; | ||
var isSpecialChar = function isSpecialChar(char$$1) { | ||
return SPECIAL_CHARS.indexOf(char$$1) >= 0; | ||
}; | ||
var isEscapableChar = function isEscapableChar(char$$1) { | ||
return char$$1 === openTag || char$$1 === closeTag || char$$1 === char_14; | ||
}; | ||
var isEscapeChar = function isEscapeChar(char$$1) { | ||
return char$$1 === char_14; | ||
}; | ||
/** | ||
* 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 | ||
*/ | ||
/** | ||
* Emits newly created token to subscriber | ||
* @param token | ||
*/ | ||
var emitToken = function emitToken(token) { | ||
if (options.onToken) { | ||
options.onToken(token); | ||
} | ||
tokenIndex += 1; | ||
tokens[tokenIndex] = token; | ||
}; | ||
var createCharGrabber = function createCharGrabber(source, options) { | ||
// let idx = 0; | ||
var cursor = { | ||
pos: 0, | ||
length: source.length | ||
}; | ||
/** | ||
* Parses params inside [myTag---params goes here---]content[/myTag] | ||
* @param str | ||
* @returns {{tag: *, attrs: Array}} | ||
*/ | ||
var parseAttrs = function parseAttrs(str) { | ||
var tagName = null; | ||
var skipSpecialChars = false; | ||
var skip = function skip() { | ||
cursor.pos += 1; | ||
var attrTokens = []; | ||
var attrCharGrabber = createCharGrabber(str); | ||
if (options && options.onSkip) { | ||
options.onSkip(); | ||
} | ||
}; | ||
var validAttr = function validAttr(char$$1) { | ||
var isEQ = char$$1 === char_6; | ||
var isWS = isWhiteSpace(char$$1); | ||
var prevChar = attrCharGrabber.getPrev(); | ||
var nextChar = attrCharGrabber.getNext(); | ||
var isPrevSLASH = prevChar === char_14; | ||
var isTagNameEmpty = tagName === null; | ||
var hasNext = function hasNext() { | ||
return cursor.length > cursor.pos; | ||
}; | ||
if (isTagNameEmpty) { | ||
return (isEQ || isWS || attrCharGrabber.isLast()) === false; | ||
} | ||
var getRest = function getRest() { | ||
return source.substr(cursor.pos); | ||
}; | ||
if (skipSpecialChars && isSpecialChar(char$$1)) { | ||
return true; | ||
} | ||
var getCurr = function getCurr() { | ||
return source[cursor.pos]; | ||
}; | ||
if (char$$1 === char_7 && !isPrevSLASH) { | ||
skipSpecialChars = !skipSpecialChars; | ||
return { | ||
skip: skip, | ||
hasNext: hasNext, | ||
isLast: function isLast() { | ||
return cursor.pos === cursor.length; | ||
}, | ||
if (!skipSpecialChars && !(nextChar === char_6 || isWhiteSpace(nextChar))) { | ||
return false; | ||
} | ||
} | ||
/** | ||
* @param {Function} cond | ||
* @returns {string} | ||
*/ | ||
grabWhile: function grabWhile(cond) { | ||
var start = 0; | ||
return (isEQ || isWS) === false; | ||
}; | ||
if (hasNext()) { | ||
start = cursor.pos; | ||
var nextAttr = function nextAttr() { | ||
var attrStr = attrCharGrabber.grabWhile(validAttr); | ||
var currChar = attrCharGrabber.getCurr(); | ||
while (hasNext() && cond(getCurr())) { | ||
skip(); | ||
} | ||
} | ||
// first string before space is a tag name [tagName params...] | ||
if (tagName === null) { | ||
tagName = attrStr; | ||
} else if (isWhiteSpace(currChar) || currChar === char_7 || !attrCharGrabber.hasNext()) { | ||
var escaped = unquote(trimChar(attrStr, char_7)); | ||
attrTokens.push(createToken(TYPE_ATTR_VALUE, escaped, row, col)); | ||
} else { | ||
attrTokens.push(createToken(TYPE_ATTR_NAME, attrStr, row, col)); | ||
} | ||
return source.substr(start, cursor.pos - start); | ||
}, | ||
getNext: function getNext() { | ||
return source[cursor.pos + 1]; | ||
}, | ||
getPrev: function getPrev() { | ||
return source[cursor.pos - 1]; | ||
}, | ||
getCurr: getCurr, | ||
getRest: getRest, | ||
attrCharGrabber.skip(); | ||
}; | ||
/** | ||
* 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); | ||
while (attrCharGrabber.hasNext()) { | ||
nextAttr(); | ||
} | ||
if (indexOfChar >= 0) { | ||
return restStr.substr(0, indexOfChar); | ||
} | ||
return { tag: tagName, attrs: attrTokens }; | ||
}; | ||
return ''; | ||
} | ||
}; | ||
}; | ||
/** | ||
* Trims string from start and end by char | ||
* @example | ||
* trimChar('*hello*', '*') ==> 'hello' | ||
* @param {String} str | ||
* @param {String} charToRemove | ||
* @returns {String} | ||
*/ | ||
var bufferGrabber = createCharGrabber(buffer, { | ||
onSkip: function onSkip() { | ||
col++; | ||
} | ||
}); | ||
var next = function next() { | ||
var currChar = bufferGrabber.getCurr(); | ||
var nextChar = bufferGrabber.getNext(); | ||
exports.createCharGrabber = createCharGrabber; | ||
if (currChar === char_2) { | ||
bufferGrabber.skip(); | ||
col = 0; | ||
row++; | ||
var trimChar = function trimChar(str, charToRemove) { | ||
while (str.charAt(0) === charToRemove) { | ||
// eslint-disable-next-line no-param-reassign | ||
str = str.substring(1); | ||
} | ||
emitToken(createToken(TYPE_NEW_LINE, currChar, row, col)); | ||
} else if (isWhiteSpace(currChar)) { | ||
var str = bufferGrabber.grabWhile(isWhiteSpace); | ||
emitToken(createToken(TYPE_SPACE, str, row, col)); | ||
} else if (escapeTags && isEscapeChar(currChar) && isEscapableChar(nextChar)) { | ||
bufferGrabber.skip(); // skip the \ without emitting anything | ||
bufferGrabber.skip(); // skip past the [, ] or \ as well | ||
emitToken(createToken(TYPE_WORD, nextChar, row, col)); | ||
} else if (currChar === openTag) { | ||
bufferGrabber.skip(); // skip openTag | ||
while (str.charAt(str.length - 1) === charToRemove) { | ||
// eslint-disable-next-line no-param-reassign | ||
str = str.substring(0, str.length - 1); | ||
} | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
var substr = bufferGrabber.substrUntilChar(closeTag); | ||
var hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
return str; | ||
}; | ||
/** | ||
* Unquotes \" to " | ||
* @param str | ||
* @return {String} | ||
*/ | ||
if (isCharReserved(nextChar) || hasInvalidChars || bufferGrabber.isLast()) { | ||
emitToken(createToken(TYPE_WORD, currChar, row, col)); | ||
} else { | ||
var _str = bufferGrabber.grabWhile(function (val) { | ||
return val !== closeTag; | ||
}); | ||
bufferGrabber.skip(); // skip closeTag | ||
// [myTag ] | ||
var isNoAttrsInTag = _str.indexOf(char_6) === -1; | ||
// [/myTag] | ||
var isClosingTag = _str[0] === char_11; | ||
exports.trimChar = trimChar; | ||
if (isNoAttrsInTag || isClosingTag) { | ||
emitToken(createToken(TYPE_TAG, _str, row, col)); | ||
} else { | ||
var parsed = parseAttrs(_str); | ||
var unquote = function unquote(str) { | ||
return str.replace(char_1.BACKSLASH + char_1.QUOTEMARK, char_1.QUOTEMARK); | ||
}; | ||
/** | ||
* @typedef {Object} ItemList | ||
* @type {Object} | ||
* @property {getLastCb} getLast | ||
* @property {flushLastCb} flushLast | ||
* @property {pushCb} push | ||
* @property {toArrayCb} toArray | ||
*/ | ||
emitToken(createToken(TYPE_TAG, parsed.tag, row, col)); | ||
/** | ||
* | ||
* @param values | ||
* @return {ItemList} | ||
*/ | ||
parsed.attrs.map(emitToken); | ||
} | ||
} | ||
} else if (currChar === closeTag) { | ||
bufferGrabber.skip(); // skip closeTag | ||
emitToken(createToken(TYPE_WORD, currChar, row, col)); | ||
} else if (isCharToken(currChar)) { | ||
if (escapeTags && isEscapeChar(currChar) && !isEscapableChar(nextChar)) { | ||
bufferGrabber.skip(); | ||
emitToken(createToken(TYPE_WORD, currChar, row, col)); | ||
} else { | ||
var _str2 = bufferGrabber.grabWhile(function (char$$1) { | ||
if (escapeTags) { | ||
return isCharToken(char$$1) && !isEscapeChar(char$$1); | ||
} | ||
return isCharToken(char$$1); | ||
}); | ||
exports.unquote = unquote; | ||
emitToken(createToken(TYPE_WORD, _str2, row, col)); | ||
} | ||
} | ||
}; | ||
var createList = function createList(values) { | ||
if (values === void 0) { | ||
values = []; | ||
} | ||
var tokenize = function tokenize() { | ||
while (bufferGrabber.hasNext()) { | ||
next(); | ||
} | ||
var nodes = values; | ||
/** | ||
* @callback getLastCb | ||
*/ | ||
tokens.length = tokenIndex + 1; | ||
var getLast = function getLast() { | ||
return nodes.length ? nodes[nodes.length - 1] : null; | ||
}; | ||
/** | ||
* @callback flushLastCb | ||
* @return {*} | ||
*/ | ||
return tokens; | ||
}; | ||
var isTokenNested = function isTokenNested(token) { | ||
var value = openTag + char_11 + token.getValue(); | ||
// potential bottleneck | ||
return buffer.indexOf(value) > -1; | ||
}; | ||
var flushLast = function flushLast() { | ||
if (nodes.length) { | ||
return nodes.pop(); | ||
} | ||
return { | ||
tokenize: tokenize, | ||
isTokenNested: isTokenNested | ||
}; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* @callback pushCb | ||
* @param value | ||
*/ | ||
/** | ||
* @public | ||
* @param {String} input | ||
* @param {Object} opts | ||
* @param {Function} opts.createTokenizer | ||
* @param {Array<string>} opts.onlyAllowTags | ||
* @param {String} opts.openTag | ||
* @param {String} opts.closeTag | ||
* @param {Boolean} opts.enableEscapeTags | ||
* @return {Array} | ||
*/ | ||
var parse = function parse(input) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = opts; | ||
var push = function push(value) { | ||
return nodes.push(value); | ||
}; | ||
/** | ||
* @callback toArrayCb | ||
* @return {Array} | ||
*/ | ||
var tokenizer = null; | ||
/** | ||
* Result AST of nodes | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
var nodes = createList(); | ||
/** | ||
* Temp buffer of nodes that's nested to another node | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
var nestedNodes = createList(); | ||
/** | ||
* Temp buffer of nodes [tag..]...[/tag] | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
var tagNodes = createList(); | ||
/** | ||
* Temp buffer of tag attributes | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
var tagNodesAttrName = createList(); | ||
return { | ||
getLast: getLast, | ||
flushLast: flushLast, | ||
push: push, | ||
toArray: function toArray() { | ||
return nodes; | ||
} | ||
}; | ||
}; | ||
/** | ||
* Cache for nested tags checks | ||
* @type {{}} | ||
*/ | ||
var nestedTagsMap = {}; | ||
exports.createList = createList; | ||
}); | ||
var isTokenNested = function isTokenNested(token) { | ||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') { | ||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token); | ||
} | ||
unwrapExports(utils); | ||
var utils_1 = utils.createList; | ||
var utils_2 = utils.unquote; | ||
var utils_3 = utils.trimChar; | ||
var utils_4 = utils.createCharGrabber; | ||
return nestedTagsMap[token.getValue()]; | ||
}; | ||
var lexer = createCommonjsModule(function (module, exports) { | ||
var isTagNested = function isTagNested(tagName) { | ||
return !!nestedTagsMap[tagName]; | ||
}; | ||
exports.__esModule = true; | ||
exports.createLexer = createLexer; | ||
exports.createTokenOfType = void 0; | ||
/** | ||
* Flushes temp tag nodes and its attributes buffers | ||
* @private | ||
* @return {Array} | ||
*/ | ||
var flushTagNodes = function flushTagNodes() { | ||
if (tagNodes.flushLast()) { | ||
tagNodesAttrName.flushLast(); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @return {Array} | ||
*/ | ||
var getNodes = function getNodes() { | ||
var lastNestedNode = nestedNodes.getLast(); | ||
return lastNestedNode ? lastNestedNode.content : nodes.toArray(); | ||
}; | ||
/** | ||
* @private | ||
* @param {TagNode} tag | ||
*/ | ||
var appendNodes = function appendNodes(tag) { | ||
getNodes().push(tag); | ||
}; | ||
/** | ||
* @private | ||
* @param {String} value | ||
* @return {boolean} | ||
*/ | ||
var isAllowedTag = function isAllowedTag(value) { | ||
if (options.onlyAllowTags && options.onlyAllowTags.length) { | ||
return options.onlyAllowTags.indexOf(value) >= 0; | ||
} | ||
return true; | ||
}; | ||
/* eslint-disable no-plusplus,no-param-reassign */ | ||
// for cases <!-- --> | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleTagStart = function handleTagStart(token) { | ||
flushTagNodes(); | ||
var tagNode = TagNode.create(token.getValue()); | ||
var isNested = isTokenNested(token); | ||
var EM = '!'; | ||
/** | ||
* Creates a Token entity class | ||
* @param {String} type | ||
* @param {String} value | ||
* @param {Number} r line number | ||
* @param {Number} cl char number in line | ||
*/ | ||
tagNodes.push(tagNode); | ||
var createToken = function createToken(type, value, r, cl) { | ||
if (r === void 0) { | ||
r = 0; | ||
} | ||
if (isNested) { | ||
nestedNodes.push(tagNode); | ||
} else { | ||
appendNodes(tagNode); | ||
} | ||
}; | ||
if (cl === void 0) { | ||
cl = 0; | ||
} | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleTagEnd = function handleTagEnd(token) { | ||
flushTagNodes(); | ||
return new Token_1.Token(type, value, r, cl); | ||
}; | ||
/** | ||
* @typedef {Object} Lexer | ||
* @property {Function} tokenize | ||
* @property {Function} isTokenNested | ||
*/ | ||
var lastNestedNode = nestedNodes.flushLast(); | ||
/** | ||
* @param {String} buffer | ||
* @param {Object} options | ||
* @param {Function} options.onToken | ||
* @param {String} options.openTag | ||
* @param {String} options.closeTag | ||
* @param {Boolean} options.enableEscapeTags | ||
* @return {Lexer} | ||
*/ | ||
if (lastNestedNode) { | ||
appendNodes(lastNestedNode); | ||
} else if (options.onError) { | ||
var tag = token.getValue(); | ||
var line = token.getLine(); | ||
var column = token.getColumn(); | ||
options.onError({ | ||
message: 'Inconsistent tag \'' + tag + '\' on line ' + line + ' and column ' + column, | ||
tagName: tag, | ||
lineNumber: line, | ||
columnNumber: column | ||
}); | ||
} | ||
}; | ||
function createLexer(buffer, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleTag = function handleTag(token) { | ||
// [tag] | ||
if (token.isStart()) { | ||
handleTagStart(token); | ||
} | ||
var row = 0; | ||
var col = 0; | ||
var tokenIndex = -1; | ||
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 RESERVED_CHARS = [closeTag, openTag, char_1.QUOTEMARK, char_1.BACKSLASH, char_1.SPACE, char_1.TAB, char_1.EQ, char_1.N, EM]; | ||
var NOT_CHAR_TOKENS = [// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, char_1.SPACE, char_1.TAB, char_1.N]; | ||
var WHITESPACES = [char_1.SPACE, char_1.TAB]; | ||
var SPECIAL_CHARS = [char_1.EQ, char_1.SPACE, char_1.TAB]; | ||
// [/tag] | ||
if (token.isEnd()) { | ||
handleTagEnd(token); | ||
} | ||
}; | ||
var isCharReserved = function isCharReserved(char) { | ||
return RESERVED_CHARS.indexOf(char) >= 0; | ||
}; | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleNode = function handleNode(token) { | ||
/** | ||
* @type {TagNode} | ||
*/ | ||
var lastTagNode = tagNodes.getLast(); | ||
var tokenValue = token.getValue(); | ||
var isNested = isTagNested(token); | ||
var isWhiteSpace = function isWhiteSpace(char) { | ||
return WHITESPACES.indexOf(char) >= 0; | ||
}; | ||
if (lastTagNode) { | ||
if (token.isAttrName()) { | ||
tagNodesAttrName.push(tokenValue); | ||
lastTagNode.attr(tagNodesAttrName.getLast(), ''); | ||
} else if (token.isAttrValue()) { | ||
var attrName = tagNodesAttrName.getLast(); | ||
var isCharToken = function isCharToken(char) { | ||
return NOT_CHAR_TOKENS.indexOf(char) === -1; | ||
}; | ||
if (attrName) { | ||
lastTagNode.attr(attrName, tokenValue); | ||
tagNodesAttrName.flushLast(); | ||
} else { | ||
lastTagNode.attr(tokenValue, tokenValue); | ||
} | ||
} else if (token.isText()) { | ||
if (isNested) { | ||
lastTagNode.append(tokenValue); | ||
} else { | ||
appendNodes(tokenValue); | ||
} | ||
} else if (token.isTag()) { | ||
// if tag is not allowed, just past it as is | ||
appendNodes(token.toString()); | ||
} | ||
} else if (token.isText()) { | ||
appendNodes(tokenValue); | ||
} else if (token.isTag()) { | ||
// if tag is not allowed, just past it as is | ||
appendNodes(token.toString()); | ||
} | ||
}; | ||
var isSpecialChar = function isSpecialChar(char) { | ||
return SPECIAL_CHARS.indexOf(char) >= 0; | ||
}; | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var onToken = function onToken(token) { | ||
if (token.isTag() && isAllowedTag(token.getName())) { | ||
handleTag(token); | ||
} else { | ||
handleNode(token); | ||
} | ||
}; | ||
var isEscapableChar = function isEscapableChar(char) { | ||
return char === openTag || char === closeTag || char === char_1.BACKSLASH; | ||
}; | ||
tokenizer = (opts.createTokenizer ? opts.createTokenizer : createLexer)(input, { | ||
onToken: onToken, | ||
onlyAllowTags: options.onlyAllowTags, | ||
openTag: options.openTag, | ||
closeTag: options.closeTag, | ||
enableEscapeTags: options.enableEscapeTags | ||
}); | ||
var isEscapeChar = function isEscapeChar(char) { | ||
return char === char_1.BACKSLASH; | ||
}; | ||
/** | ||
* Emits newly created token to subscriber | ||
* @param token | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
var tokens = tokenizer.tokenize(); | ||
return nodes.toArray(); | ||
}; | ||
var emitToken = function emitToken(token) { | ||
if (options.onToken) { | ||
options.onToken(token); | ||
} | ||
/* eslint-disable no-plusplus */ | ||
var isObj = function isObj(value) { | ||
return typeof value === 'object'; | ||
}; | ||
var isBool = function isBool(value) { | ||
return typeof value === 'boolean'; | ||
}; | ||
tokenIndex += 1; | ||
tokens[tokenIndex] = token; | ||
}; | ||
/** | ||
* Parses params inside [myTag---params goes here---]content[/myTag] | ||
* @param str | ||
* @returns {{tag: *, attrs: Array}} | ||
*/ | ||
function iterate(t, cb) { | ||
var tree = t; | ||
if (Array.isArray(tree)) { | ||
for (var idx = 0; idx < tree.length; idx++) { | ||
tree[idx] = iterate(cb(tree[idx]), cb); | ||
} | ||
} else if (tree && isObj(tree) && tree.content) { | ||
iterate(tree.content, cb); | ||
} | ||
var parseAttrs = function parseAttrs(str) { | ||
var tagName = null; | ||
var skipSpecialChars = false; | ||
var attrTokens = []; | ||
var attrCharGrabber = (0, utils.createCharGrabber)(str); | ||
return tree; | ||
} | ||
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; | ||
function same(expected, actual) { | ||
if (typeof expected !== typeof actual) { | ||
return false; | ||
} | ||
if (isTagNameEmpty) { | ||
return (isEQ || isWS || attrCharGrabber.isLast()) === false; | ||
} | ||
if (!isObj(expected) || expected === null) { | ||
return expected === actual; | ||
} | ||
if (skipSpecialChars && isSpecialChar(char)) { | ||
return true; | ||
} | ||
if (Array.isArray(expected)) { | ||
return expected.every(function (exp) { | ||
return [].some.call(actual, function (act) { | ||
return same(exp, act); | ||
}); | ||
}); | ||
} | ||
if (char === char_1.QUOTEMARK && !isPrevSLASH) { | ||
skipSpecialChars = !skipSpecialChars; | ||
return Object.keys(expected).every(function (key) { | ||
var ao = actual[key]; | ||
var eo = expected[key]; | ||
if (!skipSpecialChars && !(nextChar === char_1.EQ || isWhiteSpace(nextChar))) { | ||
return false; | ||
} | ||
} | ||
if (isObj(eo) && eo !== null && ao !== null) { | ||
return same(eo, ao); | ||
} | ||
return (isEQ || isWS) === false; | ||
}; | ||
if (isBool(eo)) { | ||
return eo !== (ao === null); | ||
} | ||
var nextAttr = function nextAttr() { | ||
var attrStr = attrCharGrabber.grabWhile(validAttr); | ||
var currChar = attrCharGrabber.getCurr(); // first string before space is a tag name [tagName params...] | ||
return ao === eo; | ||
}); | ||
} | ||
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)); | ||
} | ||
function match(expression, cb) { | ||
return Array.isArray(expression) ? iterate(this, function (node) { | ||
for (var idx = 0; idx < expression.length; idx++) { | ||
if (same(expression[idx], node)) { | ||
return cb(node); | ||
} | ||
} | ||
attrCharGrabber.skip(); | ||
}; | ||
return node; | ||
}) : iterate(this, function (node) { | ||
return same(expression, node) ? cb(node) : node; | ||
}); | ||
} | ||
while (attrCharGrabber.hasNext()) { | ||
nextAttr(); | ||
} | ||
function walk(cb) { | ||
return iterate(this, cb); | ||
} | ||
return { | ||
tag: tagName, | ||
attrs: attrTokens | ||
}; | ||
}; | ||
function bbob(plugs) { | ||
var plugins = typeof plugs === 'function' ? [plugs] : plugs || []; | ||
var bufferGrabber = (0, utils.createCharGrabber)(buffer, { | ||
onSkip: function onSkip() { | ||
col++; | ||
} | ||
}); | ||
var options = { | ||
skipParse: false | ||
}; | ||
var next = function next() { | ||
var currChar = bufferGrabber.getCurr(); | ||
var nextChar = bufferGrabber.getNext(); | ||
return { | ||
process: function process(input, opts) { | ||
options = opts || {}; | ||
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 | ||
var parseFn = options.parser || parse; | ||
var renderFn = options.render; | ||
bufferGrabber.skip(); // skip past the [, ] or \ as well | ||
if (typeof parseFn !== 'function') { | ||
throw new Error('"parser" is not a function, please pass to "process(input, { parser })" right function'); | ||
} | ||
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 tree = options.skipParse ? input || [] : parseFn(input, options); | ||
var substr = bufferGrabber.substrUntilChar(closeTag); | ||
var hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
// raw tree before modification with plugins | ||
var raw = tree; | ||
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; | ||
}); | ||
tree.messages = []; | ||
tree.options = options; | ||
tree.walk = walk; | ||
tree.match = match; | ||
bufferGrabber.skip(); // skip closeTag | ||
// [myTag ] | ||
plugins.forEach(function (plugin) { | ||
tree = plugin(tree, { | ||
parse: parseFn, | ||
render: renderFn, | ||
iterate: iterate, | ||
match: match | ||
}) || tree; | ||
}); | ||
var isNoAttrsInTag = _str.indexOf(char_1.EQ) === -1; // [/myTag] | ||
return { | ||
get html() { | ||
if (typeof renderFn !== 'function') { | ||
throw new Error('"render" function not defined, please pass to "process(input, { render })"'); | ||
} | ||
return renderFn(tree, tree.options); | ||
}, | ||
tree: tree, | ||
raw: raw, | ||
messages: tree.messages | ||
}; | ||
} | ||
}; | ||
} | ||
var isClosingTag = _str[0] === char_1.SLASH; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ | ||
var escapeQuote = function escapeQuote(value) { | ||
return value.replace(/"/g, '"'); | ||
}; | ||
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); | ||
} | ||
} | ||
} else if (currChar === closeTag) { | ||
bufferGrabber.skip(); // skip closeTag | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ | ||
var attrValue = function attrValue(name, value) { | ||
var type = typeof value; | ||
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); | ||
} | ||
var types = { | ||
boolean: function boolean() { | ||
return value ? '' + name : ''; | ||
}, | ||
number: function number() { | ||
return name + '="' + value + '"'; | ||
}, | ||
string: function string() { | ||
return name + '="' + escapeQuote(value) + '"'; | ||
}, | ||
object: function object() { | ||
return name + '="' + escapeQuote(JSON.stringify(value)) + '"'; | ||
} | ||
}; | ||
return isCharToken(char); | ||
}); | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
emitToken(createToken(Token_1.TYPE_WORD, _str2, row, col)); | ||
} | ||
} | ||
}; | ||
/** | ||
* Transforms attrs to html params string | ||
* @param values | ||
*/ | ||
var attrsToString = function attrsToString(values) { | ||
// To avoid some malformed attributes | ||
if (typeof values === 'undefined') { | ||
return ''; | ||
} | ||
var tokenize = function tokenize() { | ||
while (bufferGrabber.hasNext()) { | ||
next(); | ||
} | ||
return Object.keys(values).reduce(function (arr, key) { | ||
return [].concat(arr, [attrValue(key, values[key])]); | ||
}, ['']).join(' '); | ||
}; | ||
tokens.length = tokenIndex + 1; | ||
return tokens; | ||
}; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var isTokenNested = function isTokenNested(token) { | ||
var value = openTag + char_1.SLASH + token.getValue(); // potential bottleneck | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return buffer.indexOf(value) > -1; | ||
}; | ||
return target; | ||
}; | ||
return { | ||
tokenize: tokenize, | ||
isTokenNested: isTokenNested | ||
}; | ||
} | ||
var SELFCLOSE_END_TAG = '/>'; | ||
var CLOSE_START_TAG = '</'; | ||
var START_TAG = '<'; | ||
var END_TAG = '>'; | ||
var createTokenOfType = createToken; | ||
exports.createTokenOfType = createTokenOfType; | ||
}); | ||
var renderNode = function renderNode(node, _ref) { | ||
var _ref$stripTags = _ref.stripTags, | ||
stripTags = _ref$stripTags === undefined ? false : _ref$stripTags; | ||
unwrapExports(lexer); | ||
var lexer_1 = lexer.createLexer; | ||
var lexer_2 = lexer.createTokenOfType; | ||
if (!node) return ''; | ||
var type = typeof node; | ||
var parse_1 = createCommonjsModule(function (module, exports) { | ||
if (type === 'string' || type === 'number') { | ||
return node; | ||
} | ||
exports.__esModule = true; | ||
exports.default = exports.parse = void 0; | ||
if (type === 'object') { | ||
if (stripTags === true) { | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node.content, { stripTags: stripTags }); | ||
} | ||
var _TagNode = _interopRequireDefault(TagNode_1); | ||
if (node.content === null) { | ||
return [START_TAG, node.tag, attrsToString(node.attrs), SELFCLOSE_END_TAG].join(''); | ||
} | ||
// eslint-disable-next-line no-use-before-define | ||
return [START_TAG, node.tag, attrsToString(node.attrs), END_TAG, renderNodes(node.content), CLOSE_START_TAG, node.tag, END_TAG].join(''); | ||
} | ||
if (Array.isArray(node)) { | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node, { stripTags: stripTags }); | ||
} | ||
return ''; | ||
}; | ||
var renderNodes = function renderNodes(nodes) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$stripTags = _ref2.stripTags, | ||
stripTags = _ref2$stripTags === undefined ? false : _ref2$stripTags; | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
/** | ||
* @public | ||
* @param {String} input | ||
* @param {Object} opts | ||
* @param {Function} opts.createTokenizer | ||
* @param {Array<string>} opts.onlyAllowTags | ||
* @param {String} opts.openTag | ||
* @param {String} opts.closeTag | ||
* @param {Boolean} opts.enableEscapeTags | ||
* @return {Array} | ||
*/ | ||
return [].concat(nodes).reduce(function (r, node) { | ||
return r + renderNode(node, { stripTags: stripTags }); | ||
}, ''); | ||
}; | ||
var toHTML = function toHTML(source, plugins, options) { | ||
return bbob(plugins).process(source, _extends({}, options, { render: renderNodes })).html; | ||
}; | ||
var parse = function parse(input, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var render = renderNodes; | ||
var options = opts; | ||
var tokenizer = null; | ||
/** | ||
* Result AST of nodes | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
exports.render = render; | ||
exports.default = toHTML; | ||
var nodes = (0, utils.createList)(); | ||
/** | ||
* Temp buffer of nodes that's nested to another node | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var nestedNodes = (0, utils.createList)(); | ||
/** | ||
* Temp buffer of nodes [tag..]...[/tag] | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
var tagNodes = (0, utils.createList)(); | ||
/** | ||
* Temp buffer of tag attributes | ||
* @private | ||
* @type {ItemList} | ||
*/ | ||
var tagNodesAttrName = (0, utils.createList)(); | ||
/** | ||
* Cache for nested tags checks | ||
* @type {{}} | ||
*/ | ||
var nestedTagsMap = {}; | ||
var isTokenNested = function isTokenNested(token) { | ||
if (typeof nestedTagsMap[token.getValue()] === 'undefined') { | ||
nestedTagsMap[token.getValue()] = tokenizer.isTokenNested(token); | ||
} | ||
return nestedTagsMap[token.getValue()]; | ||
}; | ||
var isTagNested = function isTagNested(tagName) { | ||
return !!nestedTagsMap[tagName]; | ||
}; | ||
/** | ||
* Flushes temp tag nodes and its attributes buffers | ||
* @private | ||
* @return {Array} | ||
*/ | ||
var flushTagNodes = function flushTagNodes() { | ||
if (tagNodes.flushLast()) { | ||
tagNodesAttrName.flushLast(); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @return {Array} | ||
*/ | ||
var getNodes = function getNodes() { | ||
var lastNestedNode = nestedNodes.getLast(); | ||
return lastNestedNode ? lastNestedNode.content : nodes.toArray(); | ||
}; | ||
/** | ||
* @private | ||
* @param {TagNode} tag | ||
*/ | ||
var appendNodes = function appendNodes(tag) { | ||
getNodes().push(tag); | ||
}; | ||
/** | ||
* @private | ||
* @param {String} value | ||
* @return {boolean} | ||
*/ | ||
var isAllowedTag = function isAllowedTag(value) { | ||
if (options.onlyAllowTags && options.onlyAllowTags.length) { | ||
return options.onlyAllowTags.indexOf(value) >= 0; | ||
} | ||
return true; | ||
}; | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleTagStart = function handleTagStart(token) { | ||
flushTagNodes(); | ||
var tagNode = _TagNode.default.create(token.getValue()); | ||
var isNested = isTokenNested(token); | ||
tagNodes.push(tagNode); | ||
if (isNested) { | ||
nestedNodes.push(tagNode); | ||
} else { | ||
appendNodes(tagNode); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleTagEnd = function handleTagEnd(token) { | ||
flushTagNodes(); | ||
var lastNestedNode = nestedNodes.flushLast(); | ||
if (lastNestedNode) { | ||
appendNodes(lastNestedNode); | ||
} else if (options.onError) { | ||
var tag = token.getValue(); | ||
var line = token.getLine(); | ||
var column = token.getColumn(); | ||
options.onError({ | ||
message: "Inconsistent tag '" + tag + "' on line " + line + " and column " + column, | ||
tagName: tag, | ||
lineNumber: line, | ||
columnNumber: column | ||
}); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleTag = function handleTag(token) { | ||
// [tag] | ||
if (token.isStart()) { | ||
handleTagStart(token); | ||
} // [/tag] | ||
if (token.isEnd()) { | ||
handleTagEnd(token); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var handleNode = function handleNode(token) { | ||
/** | ||
* @type {TagNode} | ||
*/ | ||
var lastTagNode = tagNodes.getLast(); | ||
var tokenValue = token.getValue(); | ||
var isNested = isTagNested(token); | ||
if (lastTagNode) { | ||
if (token.isAttrName()) { | ||
tagNodesAttrName.push(tokenValue); | ||
lastTagNode.attr(tagNodesAttrName.getLast(), ''); | ||
} else if (token.isAttrValue()) { | ||
var attrName = tagNodesAttrName.getLast(); | ||
if (attrName) { | ||
lastTagNode.attr(attrName, tokenValue); | ||
tagNodesAttrName.flushLast(); | ||
} else { | ||
lastTagNode.attr(tokenValue, tokenValue); | ||
} | ||
} else if (token.isText()) { | ||
if (isNested) { | ||
lastTagNode.append(tokenValue); | ||
} else { | ||
appendNodes(tokenValue); | ||
} | ||
} else if (token.isTag()) { | ||
// if tag is not allowed, just past it as is | ||
appendNodes(token.toString()); | ||
} | ||
} else if (token.isText()) { | ||
appendNodes(tokenValue); | ||
} else if (token.isTag()) { | ||
// if tag is not allowed, just past it as is | ||
appendNodes(token.toString()); | ||
} | ||
}; | ||
/** | ||
* @private | ||
* @param {Token} token | ||
*/ | ||
var onToken = function onToken(token) { | ||
if (token.isTag() && isAllowedTag(token.getName())) { | ||
handleTag(token); | ||
} else { | ||
handleNode(token); | ||
} | ||
}; | ||
tokenizer = (opts.createTokenizer ? opts.createTokenizer : lexer.createLexer)(input, { | ||
onToken: onToken, | ||
onlyAllowTags: options.onlyAllowTags, | ||
openTag: options.openTag, | ||
closeTag: options.closeTag, | ||
enableEscapeTags: options.enableEscapeTags | ||
}); // eslint-disable-next-line no-unused-vars | ||
var tokens = tokenizer.tokenize(); | ||
return nodes.toArray(); | ||
}; | ||
exports.parse = parse; | ||
var _default = parse; | ||
exports.default = _default; | ||
}); | ||
unwrapExports(parse_1); | ||
var parse_2 = parse_1.parse; | ||
var es = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.TagNode = exports.parse = exports.default = void 0; | ||
var _parse = _interopRequireWildcard(parse_1); | ||
exports.default = _parse.default; | ||
exports.parse = _parse.parse; | ||
exports.TagNode = TagNode_1.TagNode; | ||
function _getRequireWildcardCache() { | ||
if (typeof WeakMap !== "function") return null; | ||
var cache = new WeakMap(); | ||
_getRequireWildcardCache = function _getRequireWildcardCache() { | ||
return cache; | ||
}; | ||
return cache; | ||
} | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} | ||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") { | ||
return { | ||
default: obj | ||
}; | ||
} | ||
var cache = _getRequireWildcardCache(); | ||
if (cache && cache.has(obj)) { | ||
return cache.get(obj); | ||
} | ||
var newObj = {}; | ||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; | ||
for (var key in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; | ||
if (desc && (desc.get || desc.set)) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
if (cache) { | ||
cache.set(obj, newObj); | ||
} | ||
return newObj; | ||
} | ||
}); | ||
unwrapExports(es); | ||
var es_1 = es.TagNode; | ||
var es_2 = es.parse; | ||
/* eslint-disable no-plusplus */ | ||
var isObj = function isObj(value) { | ||
return typeof value === 'object'; | ||
}; | ||
var isBool = function isBool(value) { | ||
return typeof value === 'boolean'; | ||
}; | ||
function iterate(t, cb) { | ||
var tree = t; | ||
if (Array.isArray(tree)) { | ||
for (var idx = 0; idx < tree.length; idx++) { | ||
tree[idx] = iterate(cb(tree[idx]), cb); | ||
} | ||
} else if (tree && isObj(tree) && tree.content) { | ||
iterate(tree.content, cb); | ||
} | ||
return tree; | ||
} | ||
function same(expected, actual) { | ||
if (typeof expected !== typeof actual) { | ||
return false; | ||
} | ||
if (!isObj(expected) || expected === null) { | ||
return expected === actual; | ||
} | ||
if (Array.isArray(expected)) { | ||
return expected.every(function (exp) { | ||
return [].some.call(actual, function (act) { | ||
return same(exp, act); | ||
}); | ||
}); | ||
} | ||
return Object.keys(expected).every(function (key) { | ||
var ao = actual[key]; | ||
var eo = expected[key]; | ||
if (isObj(eo) && eo !== null && ao !== null) { | ||
return same(eo, ao); | ||
} | ||
if (isBool(eo)) { | ||
return eo !== (ao === null); | ||
} | ||
return ao === eo; | ||
}); | ||
} | ||
function match(expression, cb) { | ||
return Array.isArray(expression) ? iterate(this, function (node) { | ||
for (var idx = 0; idx < expression.length; idx++) { | ||
if (same(expression[idx], node)) { | ||
return cb(node); | ||
} | ||
} | ||
return node; | ||
}) : iterate(this, function (node) { | ||
return same(expression, node) ? cb(node) : node; | ||
}); | ||
} | ||
function walk(cb) { | ||
return iterate(this, cb); | ||
} | ||
function bbob(plugs) { | ||
var plugins = typeof plugs === 'function' ? [plugs] : plugs || []; | ||
var options = { | ||
skipParse: false | ||
}; | ||
return { | ||
process: function process(input, opts) { | ||
options = opts || {}; | ||
var parseFn = options.parser || es_2; | ||
var renderFn = options.render; | ||
if (typeof parseFn !== 'function') { | ||
throw new Error('"parser" is not a function, please pass to "process(input, { parser })" right function'); | ||
} | ||
var tree = options.skipParse ? input || [] : parseFn(input, options); | ||
// raw tree before modification with plugins | ||
var raw = tree; | ||
tree.messages = []; | ||
tree.options = options; | ||
tree.walk = walk; | ||
tree.match = match; | ||
plugins.forEach(function (plugin) { | ||
tree = plugin(tree, { | ||
parse: parseFn, | ||
render: renderFn, | ||
iterate: iterate, | ||
match: match | ||
}) || tree; | ||
}); | ||
return { | ||
get html() { | ||
if (typeof renderFn !== 'function') { | ||
throw new Error('"render" function not defined, please pass to "process(input, { render })"'); | ||
} | ||
return renderFn(tree, tree.options); | ||
}, | ||
tree: tree, | ||
raw: raw, | ||
messages: tree.messages | ||
}; | ||
} | ||
}; | ||
} | ||
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$1 = createCommonjsModule(function (module, exports) { | ||
exports.__esModule = true; | ||
exports.isEOL = exports.isStringNode = exports.isTagNode = exports.getNodeLength = 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 escapeQuote = function escapeQuote(value) { | ||
return value.replace(/"/g, '"'); | ||
}; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ | ||
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 + "=\"" + escapeQuote(value) + "\""; | ||
}, | ||
object: function object() { | ||
return name + "=\"" + escapeQuote(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(' '); | ||
}; | ||
exports.attrsToString = attrsToString; | ||
}); | ||
unwrapExports(es$1); | ||
var es_1$1 = es$1.isEOL; | ||
var es_2$1 = es$1.isStringNode; | ||
var es_3 = es$1.isTagNode; | ||
var es_4 = es$1.getNodeLength; | ||
var es_5 = es$1.appendToNode; | ||
var es_6 = es$1.attrValue; | ||
var es_7 = es$1.attrsToString; | ||
var SELFCLOSE_END_TAG = '/>'; | ||
var CLOSE_START_TAG = '</'; | ||
var START_TAG = '<'; | ||
var END_TAG = '>'; | ||
var renderNode = function renderNode(node, _ref) { | ||
var _ref$stripTags = _ref.stripTags, | ||
stripTags = _ref$stripTags === void 0 ? false : _ref$stripTags; | ||
if (!node) return ''; | ||
var type = typeof node; | ||
if (type === 'string' || type === 'number') { | ||
return node; | ||
} | ||
if (type === 'object') { | ||
if (stripTags === true) { | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node.content, { | ||
stripTags: stripTags | ||
}); | ||
} | ||
if (node.content === null) { | ||
return [START_TAG, node.tag, es_7(node.attrs), SELFCLOSE_END_TAG].join(''); | ||
} // eslint-disable-next-line no-use-before-define | ||
return [START_TAG, node.tag, es_7(node.attrs), END_TAG, renderNodes(node.content), CLOSE_START_TAG, node.tag, END_TAG].join(''); | ||
} | ||
if (Array.isArray(node)) { | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node, { | ||
stripTags: stripTags | ||
}); | ||
} | ||
return ''; | ||
}; | ||
var renderNodes = function renderNodes(nodes, _temp) { | ||
var _ref2 = _temp === void 0 ? {} : _temp, | ||
_ref2$stripTags = _ref2.stripTags, | ||
stripTags = _ref2$stripTags === void 0 ? false : _ref2$stripTags; | ||
return [].concat(nodes).reduce(function (r, node) { | ||
return r + renderNode(node, { | ||
stripTags: stripTags | ||
}); | ||
}, ''); | ||
}; | ||
var toHTML = function toHTML(source, plugins, options) { | ||
return bbob(plugins).process(source, _extends({}, options, { | ||
render: renderNodes | ||
})).html; | ||
}; | ||
var render = renderNodes; | ||
exports.default = toHTML; | ||
exports.render = render; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.BbobHtml={})}(this,function(t){"use strict";function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t,n){return t(n={exports:{}},n.exports),n.exports}var a=e(function(t,n){n.__esModule=!0;n.N="\n",n.F="\f",n.R="\r",n.TAB="\t",n.EQ="=",n.QUOTEMARK='"',n.SPACE=" ",n.OPEN_BRAKET="[",n.CLOSE_BRAKET="]",n.SLASH="/",n.PLACEHOLDER_SPACE_TAB=" ",n.PLACEHOLDER_SPACE=" ",n.BACKSLASH="\\"});n(a);var N=a.N,O=a.TAB,L=a.EQ,m=a.QUOTEMARK,S=a.SPACE,k=a.OPEN_BRAKET,x=a.CLOSE_BRAKET,w=a.SLASH,C=a.BACKSLASH,o=e(function(t,n){n.__esModule=!0,n.isEOL=n.isStringNode=n.isTagNode=n.getNodeLength=n.appendToNode=n.attrValue=n.attrsToString=void 0;var r=function(t){return"object"==typeof t&&!!t.tag},o=function(t){return"string"==typeof t},i=function(t){return t.replace(/"/g,""")},u=function(t,n){var e=typeof n,r={boolean:function(){return n?""+t:""},number:function(){return t+'="'+n+'"'},string:function(){return t+'="'+i(n)+'"'},object:function(){return t+'="'+i(JSON.stringify(n))+'"'}};return r[e]?r[e]():""};n.attrsToString=function(e){return void 0===e?"":Object.keys(e).reduce(function(t,n){return[].concat(t,[u(n,e[n])])},[""]).join(" ")},n.attrValue=u,n.appendToNode=function(t,n){t.content.push(n)},n.getNodeLength=function e(t){return r(t)?t.content.reduce(function(t,n){return t+e(n)},0):o(t)?t.length:0},n.isTagNode=r,n.isStringNode=o,n.isEOL=function(t){return t===a.N}});n(o);var r=e(function(t,n){n.__esModule=!0,n.TagNode=void 0;var e=function(){function r(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,n,e){return n&&r(t.prototype,n),e&&r(t,e),t}}();var r=function(){function r(t,n,e){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,r),this.tag=t.toLowerCase(),this.attrs=n,this.content=[].concat(e)}return r.prototype.attr=function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]},r.prototype.append=function(t){return(0,o.appendToNode)(this,t)},r.prototype.toString=function(){var t=a.OPEN_BRAKET,n=a.CLOSE_BRAKET;return t+this.tag+n+this.content.reduce(function(t,n){return t+""+n},"")+t+a.SLASH+this.tag+n},e(r,[{key:"length",get:function(){return(0,o.getNodeLength)(this)}}]),r}();r.create=function(t){return new r(t,1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},2<arguments.length&&void 0!==arguments[2]?arguments[2]:[])},r.isOf=function(t,n){return t.tag===n},n.TagNode=r,n.default=r}),h=n(r);var i="type",u="value",s="line",f="word",c="attr-name",l="attr-value",p="space",g="new-line",d=function(t){return t[u]},v=function(t){return d(t).charCodeAt(0)==w.charCodeAt(0)},y=function(){function o(t,n,e,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,o),this[i]=t+"",this[u]=n+"",this[s]=+e,this.row=+r}return o.prototype.isEmpty=function(){return!!this[i]},o.prototype.isText=function(){return(t=this)[i]===p||t[i]===g||t[i]===f;var t},o.prototype.isTag=function(){return"tag"===this[i]},o.prototype.isAttrName=function(){return this[i]===c},o.prototype.isAttrValue=function(){return this[i]===l},o.prototype.isStart=function(){return!v(this)},o.prototype.isEnd=function(){return v(this)},o.prototype.getName=function(){return n=d(t=this),v(t)?n.slice(1):n;var t,n},o.prototype.getValue=function(){return d(this)},o.prototype.getLine=function(){return this[s]},o.prototype.getColumn=function(){return this.row},o.prototype.toString=function(){return t=k,t+=d(this),t+=x;var t},o}(),_=f,P=function(e,t){var r={pos:0,length:e.length},o=function(){r.pos+=1,t&&t.onSkip&&t.onSkip()},i=function(){return r.pos<r.length},u=function(){return e.substr(r.pos)},a=function(){return e[r.pos]};return{skip:o,hasNext:i,isLast:function(){return r.pos===r.length},grabWhile:function(t){var n=0;if(i())for(n=r.pos;i()&&t(a());)o();return e.substr(n,r.pos-n)},getNext:function(){return e[r.pos+1]},getPrev:function(){return e[r.pos-1]},getCurr:a,getRest:u,substrUntilChar:function(t){var n=u(),e=n.indexOf(t);return e<0?"":n.substr(0,e)}}},T=function(){var n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];return{getLast:function(){return n.length?n[n.length-1]:null},flushLast:function(){return!!n.length&&n.pop()},push:function(t){return n.push(t)},toArray:function(){return n}}},j=function(t,n){return new y(t,n,2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,3<arguments.length&&void 0!==arguments[3]?arguments[3]:0)};function A(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},f=0,c=0,r=-1,o=Array(Math.floor(e.length)),s=n.openTag||k,l=n.closeTag||x,p=n.enableEscapeTags,g=[l,s,m,C,S,O,L,N,"!"],i=[s,S,O,N],u=[S,O],h=[L,S,O],d=function(t){return 0<=u.indexOf(t)},v=function(t){return-1==i.indexOf(t)},y=function(t){return t===s||t===l||t===C},T=function(t){return t===C},A=function(t){n.onToken&&n.onToken(t),o[r+=1]=t},b=function(t){for(var u=null,a=!1,r=[],s=P(t),o=function(t){var n=t===L,e=d(t),r=s.getPrev(),o=s.getNext(),i=r===C;return null===u?!1===(n||e||s.isLast()):!(!a||h.indexOf(t)<0)||!!(t!==m||i||(a=!a)||o===L||d(o))&&!1===(n||e)},n=function(){var t=s.grabWhile(o),n=s.getCurr();if(null===u)u=t;else if(d(n)||n===m||!s.hasNext()){var e=function(t,n){for(;t.charAt(0)===n;)t=t.substring(1);for(;t.charAt(t.length-1)===n;)t=t.substring(0,t.length-1);return t}(t,m).replace(C+m,m);r.push(j("attr-value",e,f,c))}else r.push(j("attr-name",t,f,c));s.skip()};s.hasNext();)n();return{tag:u,attrs:r}},E=P(e,{onSkip:function(){c++}}),t=function(){var t=E.getCurr(),n=E.getNext();if(t===N)E.skip(),A(j("new-line",t,++f,c=0));else if(d(t)){var e=E.grabWhile(d);A(j("space",e,f,c))}else if(p&&T(t)&&y(n))E.skip(),E.skip(),A(j(_,n,f,c));else if(t===s){E.skip();var r=E.substrUntilChar(l),o=0===r.length||0<=r.indexOf(s);if(0<=g.indexOf(n)||o||E.isLast())A(j(_,t,f,c));else{var i=E.grabWhile(function(t){return t!==l});if(E.skip(),-1==i.indexOf(L)||i[0]===w)A(j("tag",i,f,c));else{var u=b(i);A(j("tag",u.tag,f,c)),u.attrs.map(A)}}}else if(t===l)E.skip(),A(j(_,t,f,c));else if(v(t))if(p&&T(t)&&!y(n))E.skip(),A(j(_,t,f,c));else{var a=E.grabWhile(function(t){return p?v(t)&&!T(t):v(t)});A(j(_,a,f,c))}};return{tokenize:function(){for(;E.hasNext();)t();return o.length=r+1,o},isTokenNested:function(t){var n=s+w+t.getValue();return-1<e.indexOf(n)}}}var b=function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=n,o=null,e=T(),u=T(),a=T(),s=T(),f={},c=function(){a.flushLast()&&s.flushLast()},l=function(t){var n;(n=u.getLast(),n?n.content:e.toArray()).push(t)},r=function(t){c();var n,e=h.create(t.getValue()),r=(void 0===f[(n=t).getValue()]&&(f[n.getValue()]=o.isTokenNested(n)),f[n.getValue()]);a.push(e),r?u.push(e):l(e)},p=function(t){t.isStart()&&r(t),t.isEnd()&&function(t){c();var n=u.flushLast();if(n)l(n);else if(i.onError){var e=t.getValue(),r=t.getLine(),o=t.getColumn();i.onError({message:"Inconsistent tag '"+e+"' on line "+r+" and column "+o,tagName:e,lineNumber:r,columnNumber:o})}}(t)},g=function(t){var n=a.getLast(),e=t.getValue(),r=!!f[t];if(n)if(t.isAttrName())s.push(e),n.attr(s.getLast(),"");else if(t.isAttrValue()){var o=s.getLast();o?(n.attr(o,e),s.flushLast()):n.attr(e,e)}else t.isText()?r?n.append(e):l(e):t.isTag()&&l(""+t);else t.isText()?l(e):t.isTag()&&l(""+t)};(o=(n.createTokenizer?n.createTokenizer:A)(t,{onToken:function(t){var n;!t.isTag()||(n=t.getName(),i.onlyAllowTags&&i.onlyAllowTags.length&&i.onlyAllowTags.indexOf(n)<0)?g(t):p(t)},onlyAllowTags:i.onlyAllowTags,openTag:i.openTag,closeTag:i.closeTag,enableEscapeTags:i.enableEscapeTags})).tokenize();return e.toArray()},E=function(t){return"object"==typeof t},B=function(t){return"boolean"==typeof t};function R(t,n){var e=t;if(Array.isArray(e))for(var r=0;r<e.length;r++)e[r]=R(n(e[r]),n);else e&&E(e)&&e.content&&R(e.content,n);return e}function V(r,o){return typeof r==typeof o&&(E(r)&&null!==r?Array.isArray(r)?r.every(function(n){return[].some.call(o,function(t){return V(n,t)})}):Object.keys(r).every(function(t){var n=o[t],e=r[t];return E(e)&&null!==e&&null!==n?V(e,n):B(e)?e!==(null===n):n===e}):r===o)}function K(e,r){return R(this,Array.isArray(e)?function(t){for(var n=0;n<e.length;n++)if(V(e[n],t))return r(t);return t}:function(t){return V(e,t)?r(t):t})}function H(t){return R(this,t)}var M=function(t){return t.replace(/"/g,""")},W=function(u){return void 0===u?"":Object.keys(u).reduce(function(t,n){return[].concat(t,[(e=n,r=u[n],o=typeof r,i={boolean:function(){return r?""+e:""},number:function(){return e+'="'+r+'"'},string:function(){return e+'="'+M(r)+'"'},object:function(){return e+'="'+M(JSON.stringify(r))+'"'}},i[o]?i[o]():"")]);var e,r,o,i},[""]).join(" ")},z=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},Q="/>",U="</",q="<",D=">",J=function(t){var n=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).stripTags,e=void 0!==n&&n;return[].concat(t).reduce(function(t,n){return t+function(t,n){var e=n.stripTags,r=void 0!==e&&e;if(!t)return"";var o=typeof t;return"string"===o||"number"===o?t:"object"===o?!0===r?J(t.content,{stripTags:r}):null===t.content?""+q+t.tag+W(t.attrs)+Q:""+q+t.tag+W(t.attrs)+D+J(t.content)+U+t.tag+D:Array.isArray(t)?J(t,{stripTags:r}):""}(n,{stripTags:e})},"")};t.render=J,t.default=function(t,n,e){return(r=n,u="function"==typeof r?[r]:r||[],a={skipParse:!1},{process:function(t,n){var e=(a=n||{}).parser||b,r=a.render;if("function"!=typeof e)throw Error('"parser" is not a function, please pass to "process(input, { parser })" right function');var o=a.skipParse?t||[]:e(t,a),i=o;return o.messages=[],o.options=a,o.walk=H,o.match=K,u.forEach(function(t){o=t(o,{parse:e,render:r,iterate:R,match:K})||o}),{get html(){if("function"!=typeof r)throw Error('"render" function not defined, please pass to "process(input, { render })"');return r(o,o.options)},tree:o,raw:i,messages:o.messages}}}).process(t,z({},e,{render:J})).html;var r,u,a},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 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 u=r((function(t,e){e.__esModule=!0,e.isEOL=e.isStringNode=e.isTagNode=e.getNodeLength=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 u=function(t){return t.replace(/"/g,""")},i=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=i;e.attrsToString=function(t){return void 0===t?"":Object.keys(t).reduce((function(e,n){return[].concat(e,[i(n,t[n])])}),[""]).join(" ")}}));n(u);var i=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)}}e.__esModule=!0,e.default=e.TagNode=void 0;var r=function(){function t(t,e,n){this.tag=t.toLowerCase(),this.attrs=e,this.content=[].concat(n)}var e,r,i,a=t.prototype;return a.attr=function(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]},a.append=function(t){return(0,u.appendToNode)(this,t)},a.toString=function(){var t=o.OPEN_BRAKET,e=o.CLOSE_BRAKET;return t+this.tag+e+this.content.reduce((function(t,e){return t+""+e}),"")+t+o.SLASH+this.tag+e},e=t,(r=[{key:"length",get:function(){return(0,u.getNodeLength)(this)}}])&&n(e.prototype,r),i&&n(e,i),t}();e.TagNode=r,r.create=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n=[]),new r(t,e,n)},r.isOf=function(t,e){return t.tag===e},e.default=r}));n(i);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.value},r=function(t){return n(t).charCodeAt(0)===o.SLASH.charCodeAt(0)},u=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"space"===(t=this).type||"new-line"===t.type||"word"===t.type;var t},e.isTag=function(){return"tag"===this.type},e.isAttrName=function(){return"attr-name"===this.type},e.isAttrValue=function(){return"attr-value"===this.type},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 this.line},e.getColumn=function(){return this.row},e.toString=function(){return t=o.OPEN_BRAKET,t+=n(this),t+=o.CLOSE_BRAKET;var t},t}();e.Token=u;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=u}));n(a);var s=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},u=function(){return t.substr(n.pos)},i=function(){return t[n.pos]};return{skip:r,hasNext:o,isLast:function(){return n.pos===n.length},grabWhile:function(e){var u=0;if(o())for(u=n.pos;o()&&e(i());)r();return t.substr(u,n.pos-u)},getNext:function(){return t[n.pos+1]},getPrev:function(){return t[n.pos-1]},getCurr:i,getRest:u,substrUntilChar:function(t){var e=u(),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 e.length?e[e.length-1]:null},flushLast:function(){return!!e.length&&e.pop()},push:function(t){return e.push(t)},toArray:function(){return e}}}}));n(s);var f=r((function(t,e){e.__esModule=!0,e.createLexer=function(t,e){void 0===e&&(e={});var r=0,u=0,i=-1,f=Array(Math.floor(t.length)),c=e.openTag||o.OPEN_BRAKET,l=e.closeTag||o.CLOSE_BRAKET,p=e.enableEscapeTags,g=[l,c,o.QUOTEMARK,o.BACKSLASH,o.SPACE,o.TAB,o.EQ,o.N,"!"],E=[c,o.SPACE,o.TAB,o.N],T=[o.SPACE,o.TAB],A=[o.EQ,o.SPACE,o.TAB],d=function(t){return T.indexOf(t)>=0},v=function(t){return-1===E.indexOf(t)},h=function(t){return t===c||t===l||t===o.BACKSLASH},_=function(t){return t===o.BACKSLASH},L=function(t){e.onToken&&e.onToken(t),f[i+=1]=t},S=function(t){for(var e=null,i=!1,f=[],c=(0,s.createCharGrabber)(t),l=function(t){var n=t===o.EQ,r=d(t),u=c.getPrev(),a=c.getNext(),s=u===o.BACKSLASH;return null===e?!1===(n||r||c.isLast()):!(!i||!function(t){return A.indexOf(t)>=0}(t))||!!(t!==o.QUOTEMARK||s||(i=!i)||a===o.EQ||d(a))&&!1===(n||r)},p=function(){var t=c.grabWhile(l),i=c.getCurr();if(null===e)e=t;else if(d(i)||i===o.QUOTEMARK||!c.hasNext()){var p=(0,s.unquote)((0,s.trimChar)(t,o.QUOTEMARK));f.push(n(a.TYPE_ATTR_VALUE,p,r,u))}else f.push(n(a.TYPE_ATTR_NAME,t,r,u));c.skip()};c.hasNext();)p();return{tag:e,attrs:f}},O=(0,s.createCharGrabber)(t,{onSkip:function(){u++}}),y=function(){var t=O.getCurr(),e=O.getNext();if(t===o.N)O.skip(),r++,L(n(a.TYPE_NEW_LINE,t,r,u=0));else if(d(t)){var i=O.grabWhile(d);L(n(a.TYPE_SPACE,i,r,u))}else if(p&&_(t)&&h(e))O.skip(),O.skip(),L(n(a.TYPE_WORD,e,r,u));else if(t===c){O.skip();var s=O.substrUntilChar(l),f=0===s.length||s.indexOf(c)>=0;if(g.indexOf(e)>=0||f||O.isLast())L(n(a.TYPE_WORD,t,r,u));else{var E=O.grabWhile((function(t){return t!==l}));if(O.skip(),-1===E.indexOf(o.EQ)||E[0]===o.SLASH)L(n(a.TYPE_TAG,E,r,u));else{var T=S(E);L(n(a.TYPE_TAG,T.tag,r,u)),T.attrs.map(L)}}}else if(t===l)O.skip(),L(n(a.TYPE_WORD,t,r,u));else if(v(t))if(p&&_(t)&&!h(e))O.skip(),L(n(a.TYPE_WORD,t,r,u));else{var A=O.grabWhile((function(t){return p?v(t)&&!_(t):v(t)}));L(n(a.TYPE_WORD,A,r,u))}};return{tokenize:function(){for(;O.hasNext();)y();return f.length=i+1,f},isTokenNested:function(e){var n=c+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 a.Token(t,e,n,r)};e.createTokenOfType=n}));n(f);var c=r((function(t,e){e.__esModule=!0,e.default=e.parse=void 0;var n,r=(n=i)&&n.__esModule?n:{default:n};var o=function(t,e){void 0===e&&(e={});var n=e,o=null,u=(0,s.createList)(),i=(0,s.createList)(),a=(0,s.createList)(),c=(0,s.createList)(),l={},p=function(){a.flushLast()&&c.flushLast()},g=function(t){var e;(e=i.getLast(),e?e.content:u.toArray()).push(t)},E=function(t){p();var e=r.default.create(t.getValue()),n=function(t){return void 0===l[t.getValue()]&&(l[t.getValue()]=o.isTokenNested(t)),l[t.getValue()]}(t);a.push(e),n?i.push(e):g(e)},T=function(t){t.isStart()&&E(t),t.isEnd()&&function(t){p();var e=i.flushLast();if(e)g(e);else if(n.onError){var r=t.getValue(),o=t.getLine(),u=t.getColumn();n.onError({message:"Inconsistent tag '"+r+"' on line "+o+" and column "+u,tagName:r,lineNumber:o,columnNumber:u})}}(t)},A=function(t){var e=a.getLast(),n=t.getValue(),r=!!l[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):g(n):t.isTag()&&g(""+t);else t.isText()?g(n):t.isTag()&&g(""+t)};(o=(e.createTokenizer?e.createTokenizer:f.createLexer)(t,{onToken:function(t){var e;!t.isTag()||(e=t.getName(),n.onlyAllowTags&&n.onlyAllowTags.length&&0>n.onlyAllowTags.indexOf(e))?A(t):T(t)},onlyAllowTags:n.onlyAllowTags,openTag:n.openTag,closeTag:n.closeTag,enableEscapeTags:n.enableEscapeTags})).tokenize();return u.toArray()};e.parse=o,e.default=o}));n(c);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={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in t)if(Object.prototype.hasOwnProperty.call(t,u)){var i=o?Object.getOwnPropertyDescriptor(t,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=t[u]}n.default=t,e&&e.set(t,n);return n}(c);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=i.TagNode}));n(l);var p=l.parse,g=function(t){return"object"==typeof t};function E(t,e){var n=t;if(Array.isArray(n))for(var r=0;n.length>r;r++)n[r]=E(e(n[r]),e);else n&&g(n)&&n.content&&E(n.content,e);return n}function T(t,e){return typeof t==typeof e&&(g(t)&&null!==t?Array.isArray(t)?t.every((function(t){return[].some.call(e,(function(e){return T(t,e)}))})):Object.keys(t).every((function(n){var r=e[n],o=t[n];return g(o)&&null!==o&&null!==r?T(o,r):"boolean"==typeof o?o!==(null===r):r===o})):t===e)}function A(t,e){return E(this,Array.isArray(t)?function(n){for(var r=0;t.length>r;r++)if(T(t[r],n))return e(n);return n}:function(n){return T(t,n)?e(n):n})}function d(t){return E(this,t)}var v=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(v);var h=r((function(t,e){e.__esModule=!0,e.isEOL=e.isStringNode=e.isTagNode=e.getNodeLength=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===v.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,""")},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 void 0===t?"":Object.keys(t).reduce((function(e,n){return[].concat(e,[u(n,t[n])])}),[""]).join(" ")}}));n(h);var _=h.attrsToString,L="/>",S="</",O="<",y=">",N=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?P(t.content,{stripTags:r}):null===t.content?""+O+t.tag+_(t.attrs)+L:""+O+t.tag+_(t.attrs)+y+P(t.content)+S+t.tag+y:Array.isArray(t)?P(t,{stripTags:r}):""},P=function(t,e){var n=(void 0===e?{}:e).stripTags,r=void 0!==n&&n;return[].concat(t).reduce((function(t,e){return t+N(e,{stripTags:r})}),"")},C=P;t.default=function(t,n,r){return function(t){var e="function"==typeof t?[t]:t||[],n={skipParse:!1};return{process:function(t,r){var o=(n=r||{}).parser||p,u=n.render;if("function"!=typeof o)throw Error('"parser" is not a function, please pass to "process(input, { parser })" right function');var i=n.skipParse?t||[]:o(t,n),a=i;return i.messages=[],i.options=n,i.walk=d,i.match=A,e.forEach((function(t){i=t(i,{parse:o,render:u,iterate:E,match:A})||i})),{get html(){if("function"!=typeof u)throw Error('"render" function not defined, please pass to "process(input, { render })"');return u(i,i.options)},tree:i,raw:a,messages:i.messages}}}}(n).process(t,e({},r,{render:P})).html},t.render=C,Object.defineProperty(t,"__esModule",{value:!0})})); |
@@ -1,6 +0,14 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
"use strict"; | ||
import core from '@bbob/core'; | ||
import { attrsToString } from '@bbob/plugin-helper'; | ||
exports.__esModule = true; | ||
exports.default = exports.render = void 0; | ||
var _core = _interopRequireDefault(require("@bbob/core")); | ||
var _pluginHelper = require("@bbob/plugin-helper"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var SELFCLOSE_END_TAG = '/>'; | ||
@@ -11,6 +19,6 @@ var CLOSE_START_TAG = '</'; | ||
var renderNode = function renderNode(node, _ref) { | ||
var _ref$stripTags = _ref.stripTags, | ||
stripTags = _ref$stripTags === undefined ? false : _ref$stripTags; | ||
var renderNode = (node, _ref) => { | ||
var { | ||
stripTags = false | ||
} = _ref; | ||
if (!node) return ''; | ||
@@ -26,11 +34,13 @@ var type = typeof node; | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node.content, { stripTags: stripTags }); | ||
return renderNodes(node.content, { | ||
stripTags | ||
}); | ||
} | ||
if (node.content === null) { | ||
return [START_TAG, node.tag, attrsToString(node.attrs), SELFCLOSE_END_TAG].join(''); | ||
} | ||
return [START_TAG, node.tag, (0, _pluginHelper.attrsToString)(node.attrs), SELFCLOSE_END_TAG].join(''); | ||
} // eslint-disable-next-line no-use-before-define | ||
// eslint-disable-next-line no-use-before-define | ||
return [START_TAG, node.tag, attrsToString(node.attrs), END_TAG, renderNodes(node.content), CLOSE_START_TAG, node.tag, END_TAG].join(''); | ||
return [START_TAG, node.tag, (0, _pluginHelper.attrsToString)(node.attrs), END_TAG, renderNodes(node.content), CLOSE_START_TAG, node.tag, END_TAG].join(''); | ||
} | ||
@@ -40,3 +50,5 @@ | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node, { stripTags: stripTags }); | ||
return renderNodes(node, { | ||
stripTags | ||
}); | ||
} | ||
@@ -47,17 +59,18 @@ | ||
var renderNodes = function renderNodes(nodes) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$stripTags = _ref2.stripTags, | ||
stripTags = _ref2$stripTags === undefined ? false : _ref2$stripTags; | ||
return [].concat(nodes).reduce(function (r, node) { | ||
return r + renderNode(node, { stripTags: stripTags }); | ||
}, ''); | ||
var renderNodes = function renderNodes(nodes, _temp) { | ||
var { | ||
stripTags = false | ||
} = _temp === void 0 ? {} : _temp; | ||
return [].concat(nodes).reduce((r, node) => r + renderNode(node, { | ||
stripTags | ||
}), ''); | ||
}; | ||
var toHTML = function toHTML(source, plugins, options) { | ||
return core(plugins).process(source, _extends({}, options, { render: renderNodes })).html; | ||
}; | ||
var toHTML = (source, plugins, options) => (0, _core.default)(plugins).process(source, _extends({}, options, { | ||
render: renderNodes | ||
})).html; | ||
export var render = renderNodes; | ||
export default toHTML; | ||
var render = renderNodes; | ||
exports.render = render; | ||
var _default = toHTML; | ||
exports.default = _default; |
@@ -1,16 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.render = undefined; | ||
exports["default"] = exports.render = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _core = _interopRequireDefault(require("@bbob/core")); | ||
var _core = require('@bbob/core'); | ||
var _pluginHelper = require("@bbob/plugin-helper"); | ||
var _core2 = _interopRequireDefault(_core); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var _pluginHelper = require('@bbob/plugin-helper'); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var SELFCLOSE_END_TAG = '/>'; | ||
@@ -23,4 +21,3 @@ var CLOSE_START_TAG = '</'; | ||
var _ref$stripTags = _ref.stripTags, | ||
stripTags = _ref$stripTags === undefined ? false : _ref$stripTags; | ||
stripTags = _ref$stripTags === void 0 ? false : _ref$stripTags; | ||
if (!node) return ''; | ||
@@ -36,3 +33,5 @@ var type = typeof node; | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node.content, { stripTags: stripTags }); | ||
return renderNodes(node.content, { | ||
stripTags: stripTags | ||
}); | ||
} | ||
@@ -42,5 +41,5 @@ | ||
return [START_TAG, node.tag, (0, _pluginHelper.attrsToString)(node.attrs), SELFCLOSE_END_TAG].join(''); | ||
} | ||
} // eslint-disable-next-line no-use-before-define | ||
// eslint-disable-next-line no-use-before-define | ||
return [START_TAG, node.tag, (0, _pluginHelper.attrsToString)(node.attrs), END_TAG, renderNodes(node.content), CLOSE_START_TAG, node.tag, END_TAG].join(''); | ||
@@ -51,3 +50,5 @@ } | ||
// eslint-disable-next-line no-use-before-define | ||
return renderNodes(node, { stripTags: stripTags }); | ||
return renderNodes(node, { | ||
stripTags: stripTags | ||
}); | ||
} | ||
@@ -58,9 +59,11 @@ | ||
var renderNodes = function renderNodes(nodes) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
var renderNodes = function renderNodes(nodes, _temp) { | ||
var _ref2 = _temp === void 0 ? {} : _temp, | ||
_ref2$stripTags = _ref2.stripTags, | ||
stripTags = _ref2$stripTags === undefined ? false : _ref2$stripTags; | ||
stripTags = _ref2$stripTags === void 0 ? false : _ref2$stripTags; | ||
return [].concat(nodes).reduce(function (r, node) { | ||
return r + renderNode(node, { stripTags: stripTags }); | ||
return r + renderNode(node, { | ||
stripTags: stripTags | ||
}); | ||
}, ''); | ||
@@ -70,6 +73,10 @@ }; | ||
var toHTML = function toHTML(source, plugins, options) { | ||
return (0, _core2.default)(plugins).process(source, _extends({}, options, { render: renderNodes })).html; | ||
return (0, _core["default"])(plugins).process(source, _extends({}, options, { | ||
render: renderNodes | ||
})).html; | ||
}; | ||
var render = exports.render = renderNodes; | ||
exports.default = toHTML; | ||
var render = renderNodes; | ||
exports.render = render; | ||
var _default = toHTML; | ||
exports["default"] = _default; |
{ | ||
"name": "@bbob/html", | ||
"version": "2.5.4", | ||
"version": "2.5.5", | ||
"description": "HTML renderer for @bbob bbcode parser", | ||
"keywords": [], | ||
"dependencies": { | ||
"@bbob/core": "^2.5.4", | ||
"@bbob/plugin-helper": "^2.5.4" | ||
"@bbob/core": "^2.5.5", | ||
"@bbob/plugin-helper": "^2.5.5" | ||
}, | ||
@@ -26,11 +26,11 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib", | ||
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es", | ||
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js", | ||
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs NODE_ENV=production ../../node_modules/.bin/babel src --out-dir lib", | ||
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es NODE_ENV=production ../../node_modules/.bin/babel src --out-dir es", | ||
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=production ../../node_modules/.bin/rollup --config ../../rollup.config.js", | ||
"build": "npm run build:commonjs && npm run build:es && npm run build:umd", | ||
"test": "../../node_modules/.bin/jest --", | ||
"test": "../../node_modules/.bin/jest --debug", | ||
"cover": "../../node_modules/.bin/jest --coverage", | ||
"lint": "../../node_modules/.bin/eslint .", | ||
"size": "../../node_modules/.bin/size-limit", | ||
"bundlesize": "../../node_modules/.bin/bundlesize" | ||
"size": "../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/size-limit", | ||
"bundlesize": "../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/bundlesize" | ||
}, | ||
@@ -45,3 +45,3 @@ "size-limit": [ | ||
"path": "./dist/index.min.js", | ||
"maxSize": "3.5 KB" | ||
"maxSize": "4.1 KB" | ||
} | ||
@@ -57,3 +57,4 @@ ], | ||
"es" | ||
] | ||
], | ||
"gitHead": "2670fc128892a48c636c5669b61af06f9824f057" | ||
} |
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
67654
9
1510
Updated@bbob/core@^2.5.5
Updated@bbob/plugin-helper@^2.5.5