@bbob/html
Advanced tools
Comparing version 2.8.2 to 2.8.3
1198
dist/index.js
@@ -7,81 +7,18 @@ (function (global, factory) { | ||
var TagNode$1 = {}; | ||
const N = '\n'; | ||
const TAB = '\t'; | ||
const EQ = '='; | ||
const QUOTEMARK = '"'; | ||
const SPACE = ' '; | ||
const OPEN_BRAKET = '['; | ||
const CLOSE_BRAKET = ']'; | ||
const SLASH = '/'; | ||
const BACKSLASH = '\\'; | ||
var char = {}; | ||
Object.defineProperty(char, "__esModule", { | ||
value: true | ||
}); | ||
var BACKSLASH_1 = char.BACKSLASH = char.PLACEHOLDER_SPACE = char.PLACEHOLDER_SPACE_TAB = SLASH_1 = char.SLASH = CLOSE_BRAKET_1 = char.CLOSE_BRAKET = OPEN_BRAKET_1 = char.OPEN_BRAKET = SPACE_1 = char.SPACE = QUOTEMARK_1 = char.QUOTEMARK = EQ_1 = char.EQ = TAB_1 = char.TAB = char.R = char.F = N_1 = char.N = void 0; | ||
var N = '\n'; | ||
var TAB = '\t'; | ||
var F = '\f'; | ||
var R = '\r'; | ||
var EQ = '='; | ||
var QUOTEMARK = '"'; | ||
var SPACE = ' '; | ||
var OPEN_BRAKET = '['; | ||
var CLOSE_BRAKET = ']'; | ||
var SLASH = '/'; | ||
var BACKSLASH = '\\'; | ||
var PLACEHOLDER_SPACE_TAB = ' '; | ||
var PLACEHOLDER_SPACE = ' '; | ||
var N_1 = char.N = N; | ||
char.F = F; | ||
char.R = R; | ||
var TAB_1 = char.TAB = TAB; | ||
var EQ_1 = char.EQ = EQ; | ||
var QUOTEMARK_1 = char.QUOTEMARK = QUOTEMARK; | ||
var SPACE_1 = char.SPACE = SPACE; | ||
var OPEN_BRAKET_1 = char.OPEN_BRAKET = OPEN_BRAKET; | ||
var CLOSE_BRAKET_1 = char.CLOSE_BRAKET = CLOSE_BRAKET; | ||
var SLASH_1 = char.SLASH = SLASH; | ||
char.PLACEHOLDER_SPACE_TAB = PLACEHOLDER_SPACE_TAB; | ||
char.PLACEHOLDER_SPACE = PLACEHOLDER_SPACE; | ||
BACKSLASH_1 = char.BACKSLASH = BACKSLASH; | ||
var lib = {}; | ||
Object.defineProperty(lib, "__esModule", { | ||
value: true | ||
}); | ||
lib.isEOL = lib.isStringNode = isTagNode_1 = lib.isTagNode = lib.getUniqAttr = lib.getNodeLength = lib.escapeHTML = lib.appendToNode = lib.attrValue = lib.attrsToString = void 0; | ||
var _char$1 = char; | ||
function _arrayWithoutHoles$1(arr) { | ||
if (Array.isArray(arr)) { | ||
for(var i = 0, arr2 = new Array(arr.length); i < arr.length; i++){ | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray$1(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread$1() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _toConsumableArray$1(arr) { | ||
return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1(); | ||
} | ||
var _typeof$3 = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var isTagNode = function(el) { | ||
return typeof el === 'object' && !!el.tag; | ||
}; | ||
var isStringNode = function(el) { | ||
return typeof el === 'string'; | ||
}; | ||
var isEOL = function(el) { | ||
return el === _char$1.N; | ||
}; | ||
var keysReduce$1 = function(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
var getNodeLength = function(node) { | ||
const isTagNode = (el)=>typeof el === 'object' && !!el.tag; | ||
const isStringNode = (el)=>typeof el === 'string'; | ||
const keysReduce = (obj, reduce, def)=>Object.keys(obj).reduce(reduce, def); | ||
const getNodeLength = (node)=>{ | ||
if (isTagNode(node)) { | ||
return node.content.reduce(function(count, contentNode) { | ||
return count + getNodeLength(contentNode); | ||
}, 0); | ||
return node.content.reduce((count, contentNode)=>count + getNodeLength(contentNode), 0); | ||
} | ||
@@ -97,3 +34,3 @@ if (isStringNode(node)) { | ||
* @param value | ||
*/ var appendToNode = function(node, value) { | ||
*/ const appendToNode = (node, value)=>{ | ||
node.content.push(value); | ||
@@ -104,6 +41,4 @@ }; | ||
* @param {String} value | ||
*/ var escapeHTML$1 = function(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')// eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
*/ const escapeHTML = (value)=>value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')// eslint-disable-next-line no-script-url | ||
.replace(/(javascript|data|vbscript):/gi, '$1%3A'); | ||
/** | ||
@@ -114,17 +49,9 @@ * Acept name and value and return valid html5 attribute string | ||
* @return {string} | ||
*/ var attrValue$1 = function(name, value) { | ||
var type = typeof value === "undefined" ? "undefined" : _typeof$3(value); | ||
var types = { | ||
boolean: function() { | ||
return value ? "".concat(name) : ''; | ||
}, | ||
number: function() { | ||
return "".concat(name, "=\"").concat(value, "\""); | ||
}, | ||
string: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML$1(value), "\""); | ||
}, | ||
object: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML$1(JSON.stringify(value)), "\""); | ||
} | ||
*/ const attrValue = (name, value)=>{ | ||
const type = typeof value; | ||
const types = { | ||
boolean: ()=>value ? `${name}` : '', | ||
number: ()=>`${name}="${value}"`, | ||
string: ()=>`${name}="${escapeHTML(value)}"`, | ||
object: ()=>`${name}="${escapeHTML(JSON.stringify(value))}"` | ||
}; | ||
@@ -136,3 +63,3 @@ return types[type] ? types[type]() : ''; | ||
* @param values | ||
*/ var attrsToString$1 = function(values) { | ||
*/ const attrsToString = (values)=>{ | ||
// To avoid some malformed attributes | ||
@@ -142,7 +69,6 @@ if (values == null) { | ||
} | ||
return keysReduce$1(values, function(arr, key) { | ||
return _toConsumableArray$1(arr).concat([ | ||
attrValue$1(key, values[key]) | ||
]); | ||
}, [ | ||
return keysReduce(values, (arr, key)=>[ | ||
...arr, | ||
attrValue(key, values[key]) | ||
], [ | ||
'' | ||
@@ -157,86 +83,59 @@ ]).join(' '); | ||
* @returns {string} | ||
*/ var getUniqAttr = function(attrs) { | ||
return keysReduce$1(attrs, function(res, key) { | ||
return attrs[key] === key ? attrs[key] : null; | ||
}, null); | ||
}; | ||
lib.attrsToString = attrsToString$1; | ||
lib.attrValue = attrValue$1; | ||
lib.appendToNode = appendToNode; | ||
lib.escapeHTML = escapeHTML$1; | ||
lib.getNodeLength = getNodeLength; | ||
lib.getUniqAttr = getUniqAttr; | ||
var isTagNode_1 = lib.isTagNode = isTagNode; | ||
lib.isStringNode = isStringNode; | ||
lib.isEOL = isEOL; | ||
*/ const getUniqAttr = (attrs)=>keysReduce(attrs, (res, key)=>attrs[key] === key ? attrs[key] : null, null); | ||
Object.defineProperty(TagNode$1, "__esModule", { | ||
value: true | ||
}); | ||
var default_1 = TagNode$1.default = TagNode$1.TagNode = void 0; | ||
var _char = char; | ||
var _index = lib; | ||
function _classCallCheck$1(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
const getTagAttrs = (tag, params)=>{ | ||
const uniqAattr = getUniqAttr(params); | ||
if (uniqAattr) { | ||
const tagAttr = attrValue(tag, uniqAattr); | ||
const attrs = { | ||
...params | ||
}; | ||
delete attrs[uniqAattr]; | ||
const attrsStr = attrsToString(attrs); | ||
return `${tagAttr}${attrsStr}`; | ||
} | ||
} | ||
function _defineProperties$1(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 `${tag}${attrsToString(params)}`; | ||
}; | ||
class TagNode { | ||
attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
} | ||
return this.attrs[name]; | ||
} | ||
} | ||
function _createClass$1(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties$1(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _defineProperty$1(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
append(value) { | ||
return appendToNode(this, value); | ||
} | ||
get length() { | ||
return getNodeLength(this); | ||
} | ||
toTagStart({ openTag =OPEN_BRAKET , closeTag =CLOSE_BRAKET } = {}) { | ||
const tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
return `${openTag}${tagAttrs}${closeTag}`; | ||
} | ||
toTagEnd({ openTag =OPEN_BRAKET , closeTag =CLOSE_BRAKET } = {}) { | ||
return `${openTag}${SLASH}${this.tag}${closeTag}`; | ||
} | ||
toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
} | ||
toString({ openTag =OPEN_BRAKET , closeTag =CLOSE_BRAKET } = {}) { | ||
const isEmpty = this.content.length === 0; | ||
const content = this.content.reduce((r, node)=>r + node.toString({ | ||
openTag, | ||
closeTag | ||
}), ''); | ||
const tagStart = this.toTagStart({ | ||
openTag, | ||
closeTag | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectSpread$1(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : { | ||
}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
if (isEmpty) { | ||
return tagStart; | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty$1(target, key, source[key]); | ||
}); | ||
return `${tagStart}${content}${this.toTagEnd({ | ||
openTag, | ||
closeTag | ||
})}`; | ||
} | ||
return target; | ||
} | ||
var getTagAttrs = function(tag, params) { | ||
var uniqAattr = (_index).getUniqAttr(params); | ||
if (uniqAattr) { | ||
var tagAttr = (_index).attrValue(tag, uniqAattr); | ||
var attrs = _objectSpread$1({ | ||
}, params); | ||
delete attrs[uniqAattr]; | ||
var attrsStr = (_index).attrsToString(attrs); | ||
return "".concat(tagAttr).concat(attrsStr); | ||
} | ||
return "".concat(tag).concat((_index).attrsToString(params)); | ||
}; | ||
var TagNode = /*#__PURE__*/ function() { | ||
function TagNode(tag, attrs, content) { | ||
_classCallCheck$1(this, TagNode); | ||
constructor(tag, attrs, content){ | ||
this.tag = tag; | ||
@@ -248,121 +147,21 @@ this.attrs = attrs; | ||
} | ||
_createClass$1(TagNode, [ | ||
{ | ||
key: "attr", | ||
value: function attr(name, value) { | ||
if (typeof value !== 'undefined') { | ||
this.attrs[name] = value; | ||
} | ||
return this.attrs[name]; | ||
} | ||
}, | ||
{ | ||
key: "append", | ||
value: function append(value) { | ||
return (_index).appendToNode(this, value); | ||
} | ||
}, | ||
{ | ||
key: "length", | ||
get: function get() { | ||
return (_index).getNodeLength(this); | ||
} | ||
}, | ||
{ | ||
key: "toTagStart", | ||
value: function toTagStart(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? _char.OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? _char.CLOSE_BRAKET : _closeTag; | ||
var tagAttrs = getTagAttrs(this.tag, this.attrs); | ||
return "".concat(openTag).concat(tagAttrs).concat(closeTag); | ||
} | ||
}, | ||
{ | ||
key: "toTagEnd", | ||
value: function toTagEnd(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? _char.OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? _char.CLOSE_BRAKET : _closeTag; | ||
return "".concat(openTag).concat(_char.SLASH).concat(this.tag).concat(closeTag); | ||
} | ||
}, | ||
{ | ||
key: "toTagNode", | ||
value: function toTagNode() { | ||
return new TagNode(this.tag.toLowerCase(), this.attrs, this.content); | ||
} | ||
}, | ||
{ | ||
key: "toString", | ||
value: function toString(param) { | ||
var ref = param === void 0 ? { | ||
} : param, _openTag = ref.openTag, openTag = _openTag === void 0 ? _char.OPEN_BRAKET : _openTag, _closeTag = ref.closeTag, closeTag = _closeTag === void 0 ? _char.CLOSE_BRAKET : _closeTag; | ||
var isEmpty = this.content.length === 0; | ||
var content = this.content.reduce(function(r, node) { | ||
return r + node.toString({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
}, ''); | ||
var tagStart = this.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
}); | ||
if (isEmpty) { | ||
return tagStart; | ||
} | ||
return "".concat(tagStart).concat(content).concat(this.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
})); | ||
} | ||
} | ||
]); | ||
return TagNode; | ||
}(); | ||
TagNode.create = function(tag, param, param1) { | ||
var attrs = param === void 0 ? { | ||
} : param, content = param1 === void 0 ? [] : param1; | ||
return new TagNode(tag, attrs, content); | ||
}; | ||
TagNode.isOf = function(node, type) { | ||
return node.tag === type; | ||
}; | ||
TagNode$1.TagNode = TagNode; | ||
var _default = TagNode; | ||
default_1 = TagNode$1.default = _default; | ||
} | ||
TagNode.create = (tag, attrs = {}, content = [])=>new TagNode(tag, attrs, content); | ||
TagNode.isOf = (node, type)=>node.tag === type; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a 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); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
// 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; | ||
var TOKEN_TYPE_WORD = 1; // 'word'; | ||
var TOKEN_TYPE_TAG = 2; // 'tag'; | ||
var TOKEN_TYPE_ATTR_NAME = 3; // 'attr-name'; | ||
var TOKEN_TYPE_ATTR_VALUE = 4; // 'attr-value'; | ||
var TOKEN_TYPE_SPACE = 5; // 'space'; | ||
var TOKEN_TYPE_NEW_LINE = 6; // 'new-line'; | ||
const TOKEN_TYPE_ID = 'type'; // 0; | ||
const TOKEN_VALUE_ID = 'value'; // 1; | ||
const TOKEN_COLUMN_ID = 'row'; // 2; | ||
const TOKEN_LINE_ID = 'line'; // 3; | ||
const TOKEN_TYPE_WORD = 1; // 'word'; | ||
const TOKEN_TYPE_TAG = 2; // 'tag'; | ||
const TOKEN_TYPE_ATTR_NAME = 3; // 'attr-name'; | ||
const TOKEN_TYPE_ATTR_VALUE = 4; // 'attr-value'; | ||
const TOKEN_TYPE_SPACE = 5; // 'space'; | ||
const TOKEN_TYPE_NEW_LINE = 6; // 'new-line'; | ||
/** | ||
* @param {Token} token | ||
* @returns {string} | ||
*/ var getTokenValue = function(token) { | ||
*/ const getTokenValue = (token)=>{ | ||
if (token && typeof token[TOKEN_VALUE_ID] !== 'undefined') { | ||
@@ -376,12 +175,8 @@ return token[TOKEN_VALUE_ID]; | ||
* @returns {number} | ||
*/ var getTokenLine = function(token) { | ||
return token && token[TOKEN_LINE_ID] || 0; | ||
}; | ||
var getTokenColumn = function(token) { | ||
return token && token[TOKEN_COLUMN_ID] || 0; | ||
}; | ||
*/ const getTokenLine = (token)=>token && token[TOKEN_LINE_ID] || 0; | ||
const getTokenColumn = (token)=>token && token[TOKEN_COLUMN_ID] || 0; | ||
/** | ||
* @param {Token} token | ||
* @returns {boolean} | ||
*/ var isTextToken = function(token) { | ||
*/ const isTextToken = (token)=>{ | ||
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { | ||
@@ -395,3 +190,3 @@ return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD; | ||
* @returns {boolean} | ||
*/ var isTagToken = function(token) { | ||
*/ const isTagToken = (token)=>{ | ||
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { | ||
@@ -402,9 +197,5 @@ return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; | ||
}; | ||
var isTagEnd = function(token) { | ||
return getTokenValue(token).charCodeAt(0) === SLASH_1.charCodeAt(0); | ||
}; | ||
var isTagStart = function(token) { | ||
return !isTagEnd(token); | ||
}; | ||
var isAttrNameToken = function(token) { | ||
const isTagEnd = (token)=>getTokenValue(token).charCodeAt(0) === SLASH.charCodeAt(0); | ||
const isTagStart = (token)=>!isTagEnd(token); | ||
const isAttrNameToken = (token)=>{ | ||
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { | ||
@@ -418,3 +209,3 @@ return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; | ||
* @returns {boolean} | ||
*/ var isAttrValueToken = function(token) { | ||
*/ const isAttrValueToken = (token)=>{ | ||
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { | ||
@@ -425,15 +216,56 @@ return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; | ||
}; | ||
var getTagName = function(token) { | ||
var value = getTokenValue(token); | ||
const getTagName = (token)=>{ | ||
const value = getTokenValue(token); | ||
return isTagEnd(token) ? value.slice(1) : value; | ||
}; | ||
var convertTagToText = function(token) { | ||
var text = OPEN_BRAKET_1; | ||
const convertTagToText = (token)=>{ | ||
let text = OPEN_BRAKET; | ||
text += getTokenValue(token); | ||
text += CLOSE_BRAKET_1; | ||
text += CLOSE_BRAKET; | ||
return text; | ||
}; | ||
var Token = /*#__PURE__*/ function() { | ||
function Token(type, value, line, row) { | ||
_classCallCheck(this, Token); | ||
class Token { | ||
isEmpty() { | ||
// eslint-disable-next-line no-restricted-globals | ||
return isNaN(this[TOKEN_TYPE_ID]); | ||
} | ||
isText() { | ||
return isTextToken(this); | ||
} | ||
isTag() { | ||
return isTagToken(this); | ||
} | ||
isAttrName() { | ||
return isAttrNameToken(this); | ||
} | ||
isAttrValue() { | ||
return isAttrValueToken(this); | ||
} | ||
isStart() { | ||
return isTagStart(this); | ||
} | ||
isEnd() { | ||
return isTagEnd(this); | ||
} | ||
getName() { | ||
return getTagName(this); | ||
} | ||
getValue() { | ||
return getTokenValue(this); | ||
} | ||
getLine() { | ||
return getTokenLine(this); | ||
} | ||
getColumn() { | ||
return getTokenColumn(this); | ||
} | ||
toString() { | ||
return convertTagToText(this); | ||
} | ||
/** | ||
* @param {String} type | ||
* @param {String} value | ||
* @param line | ||
* @param row | ||
*/ constructor(type, value, line, row){ | ||
this[TOKEN_TYPE_ID] = Number(type); | ||
@@ -444,107 +276,24 @@ this[TOKEN_VALUE_ID] = String(value); | ||
} | ||
_createClass(Token, [ | ||
{ | ||
key: "isEmpty", | ||
value: function isEmpty() { | ||
// eslint-disable-next-line no-restricted-globals | ||
return isNaN(this[TOKEN_TYPE_ID]); | ||
} | ||
}, | ||
{ | ||
key: "isText", | ||
value: function isText() { | ||
return isTextToken(this); | ||
} | ||
}, | ||
{ | ||
key: "isTag", | ||
value: function isTag() { | ||
return isTagToken(this); | ||
} | ||
}, | ||
{ | ||
key: "isAttrName", | ||
value: function isAttrName() { | ||
return isAttrNameToken(this); | ||
} | ||
}, | ||
{ | ||
key: "isAttrValue", | ||
value: function isAttrValue() { | ||
return isAttrValueToken(this); | ||
} | ||
}, | ||
{ | ||
key: "isStart", | ||
value: function isStart() { | ||
return isTagStart(this); | ||
} | ||
}, | ||
{ | ||
key: "isEnd", | ||
value: function isEnd() { | ||
return isTagEnd(this); | ||
} | ||
}, | ||
{ | ||
key: "getName", | ||
value: function getName() { | ||
return getTagName(this); | ||
} | ||
}, | ||
{ | ||
key: "getValue", | ||
value: function getValue() { | ||
return getTokenValue(this); | ||
} | ||
}, | ||
{ | ||
key: "getLine", | ||
value: function getLine() { | ||
return getTokenLine(this); | ||
} | ||
}, | ||
{ | ||
key: "getColumn", | ||
value: function getColumn() { | ||
return getTokenColumn(this); | ||
} | ||
}, | ||
{ | ||
key: "toString", | ||
value: function toString() { | ||
return convertTagToText(this); | ||
} | ||
} | ||
]); | ||
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; | ||
} | ||
const TYPE_WORD = TOKEN_TYPE_WORD; | ||
const TYPE_TAG = TOKEN_TYPE_TAG; | ||
const TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME; | ||
const TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE; | ||
const TYPE_SPACE = TOKEN_TYPE_SPACE; | ||
const TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE; | ||
function CharGrabber(source, options) { | ||
var cursor = { | ||
const cursor = { | ||
pos: 0, | ||
len: source.length | ||
}; | ||
var substrUntilChar = function(char) { | ||
var pos = cursor.pos; | ||
var idx = source.indexOf(char, pos); | ||
const substrUntilChar = (char)=>{ | ||
const { pos } = cursor; | ||
const idx = source.indexOf(char, pos); | ||
return idx >= 0 ? source.substr(pos, idx - pos) : ''; | ||
}; | ||
var includes = function(val) { | ||
return source.indexOf(val, cursor.pos) >= 0; | ||
}; | ||
var hasNext = function() { | ||
return cursor.len > cursor.pos; | ||
}; | ||
var isLast = function() { | ||
return cursor.pos === cursor.len; | ||
}; | ||
var skip = function(param, silent) { | ||
var num = param === void 0 ? 1 : param; | ||
const includes = (val)=>source.indexOf(val, cursor.pos) >= 0; | ||
const hasNext = ()=>cursor.len > cursor.pos; | ||
const isLast = ()=>cursor.pos === cursor.len; | ||
const skip = (num = 1, silent)=>{ | ||
cursor.pos += num; | ||
@@ -555,18 +304,14 @@ if (options && options.onSkip && !silent) { | ||
}; | ||
var rest = function() { | ||
return source.substr(cursor.pos); | ||
}; | ||
var curr = function() { | ||
return source[cursor.pos]; | ||
}; | ||
var prev = function() { | ||
var prevPos = cursor.pos - 1; | ||
const rest = ()=>source.substr(cursor.pos); | ||
const curr = ()=>source[cursor.pos]; | ||
const prev = ()=>{ | ||
const prevPos = cursor.pos - 1; | ||
return typeof source[prevPos] !== 'undefined' ? source[prevPos] : null; | ||
}; | ||
var next = function() { | ||
var nextPos = cursor.pos + 1; | ||
const next = ()=>{ | ||
const nextPos = cursor.pos + 1; | ||
return nextPos <= source.length - 1 ? source[nextPos] : null; | ||
}; | ||
var grabWhile = function(cond, silent) { | ||
var start = 0; | ||
const grabWhile = (cond, silent)=>{ | ||
let start = 0; | ||
if (hasNext()) { | ||
@@ -621,5 +366,3 @@ start = cursor.pos; | ||
* @return CharGrabber | ||
*/ var createCharGrabber = function(source, options) { | ||
return new CharGrabber(source, options); | ||
}; | ||
*/ const createCharGrabber = (source, options)=>new CharGrabber(source, options); | ||
/** | ||
@@ -632,3 +375,3 @@ * Trims string from start and end by char | ||
* @returns {String} | ||
*/ var trimChar = function(str, charToRemove) { | ||
*/ const trimChar = (str, charToRemove)=>{ | ||
while(str.charAt(0) === charToRemove){ | ||
@@ -648,20 +391,9 @@ // eslint-disable-next-line no-param-reassign | ||
* @return {String} | ||
*/ var unquote = function(str) { | ||
return str.replace(BACKSLASH_1 + QUOTEMARK_1, QUOTEMARK_1); | ||
}; | ||
function NodeList(param) { | ||
var values = param === void 0 ? [] : param; | ||
var nodes = values; | ||
var getLast = function() { | ||
return Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined' ? nodes[nodes.length - 1] : null; | ||
}; | ||
var flushLast = function() { | ||
return nodes.length ? nodes.pop() : false; | ||
}; | ||
var push = function(value) { | ||
return nodes.push(value); | ||
}; | ||
var toArray = function() { | ||
return nodes; | ||
}; | ||
*/ const unquote = (str)=>str.replace(BACKSLASH + QUOTEMARK, QUOTEMARK); | ||
function NodeList(values = []) { | ||
const nodes = values; | ||
const getLast = ()=>Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined' ? nodes[nodes.length - 1] : null; | ||
const flushLast = ()=>nodes.length ? nodes.pop() : false; | ||
const push = (value)=>nodes.push(value); | ||
const toArray = ()=>nodes; | ||
this.push = push; | ||
@@ -676,9 +408,6 @@ this.toArray = toArray; | ||
* @return {NodeList} | ||
*/ var createList = function(param) { | ||
var values = param === void 0 ? [] : param; | ||
return new NodeList(values); | ||
}; | ||
*/ const createList = (values = [])=>new NodeList(values); | ||
// for cases <!-- --> | ||
var EM = '!'; | ||
const EM = '!'; | ||
/** | ||
@@ -690,6 +419,3 @@ * Creates a Token entity class | ||
* @param {Number} cl char number in line | ||
*/ var createToken = function(type, value, param, param1) { | ||
var r = param === void 0 ? 0 : param, cl = param1 === void 0 ? 0 : param1; | ||
return new Token(type, value, r, cl); | ||
}; | ||
*/ const createToken = (type, value, r = 0, cl = 0)=>new Token(type, value, r, cl); | ||
/** | ||
@@ -707,6 +433,61 @@ * @typedef {Object} Lexer | ||
* @return {Lexer} | ||
*/ function createLexer(buffer, param) { | ||
var options = param === void 0 ? { | ||
} : param; | ||
var emitToken = /** | ||
*/ function createLexer(buffer, options = {}) { | ||
const STATE_WORD = 0; | ||
const STATE_TAG = 1; | ||
const STATE_TAG_ATTRS = 2; | ||
const TAG_STATE_NAME = 0; | ||
const TAG_STATE_ATTR = 1; | ||
const TAG_STATE_VALUE = 2; | ||
let row = 0; | ||
let col = 0; | ||
let tokenIndex = -1; | ||
let stateMode = STATE_WORD; | ||
let tagMode = TAG_STATE_NAME; | ||
const tokens = new Array(Math.floor(buffer.length)); | ||
const openTag = options.openTag || OPEN_BRAKET; | ||
const closeTag = options.closeTag || CLOSE_BRAKET; | ||
const escapeTags = !!options.enableEscapeTags; | ||
const onToken = options.onToken || (()=>{}); | ||
const RESERVED_CHARS = [ | ||
closeTag, | ||
openTag, | ||
QUOTEMARK, | ||
BACKSLASH, | ||
SPACE, | ||
TAB, | ||
EQ, | ||
N, | ||
EM | ||
]; | ||
const NOT_CHAR_TOKENS = [ | ||
// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, | ||
SPACE, | ||
TAB, | ||
N | ||
]; | ||
const WHITESPACES = [ | ||
SPACE, | ||
TAB | ||
]; | ||
const SPECIAL_CHARS = [ | ||
EQ, | ||
SPACE, | ||
TAB | ||
]; | ||
const isCharReserved = (char)=>RESERVED_CHARS.indexOf(char) >= 0; | ||
const isNewLine = (char)=>char === N; | ||
const isWhiteSpace = (char)=>WHITESPACES.indexOf(char) >= 0; | ||
const isCharToken = (char)=>NOT_CHAR_TOKENS.indexOf(char) === -1; | ||
const isSpecialChar = (char)=>SPECIAL_CHARS.indexOf(char) >= 0; | ||
const isEscapableChar = (char)=>char === openTag || char === closeTag || char === BACKSLASH; | ||
const isEscapeChar = (char)=>char === BACKSLASH; | ||
const onSkip = ()=>{ | ||
col++; | ||
}; | ||
const unq = (val)=>unquote(trimChar(val, QUOTEMARK)); | ||
const chars = createCharGrabber(buffer, { | ||
onSkip | ||
}); | ||
/** | ||
* Emits newly created token to subscriber | ||
@@ -716,15 +497,13 @@ * @param {Number} type | ||
*/ function emitToken(type, value) { | ||
var token = createToken(type, value, row, col); | ||
const token = createToken(type, value, row, col); | ||
onToken(token); | ||
tokenIndex += 1; | ||
tokens[tokenIndex] = token; | ||
}; | ||
var nextTagState = function nextTagState(tagChars, isSingleValueTag) { | ||
} | ||
function nextTagState(tagChars, isSingleValueTag) { | ||
if (tagMode === TAG_STATE_ATTR) { | ||
var validAttrName = function(char) { | ||
return !(char === EQ_1 || isWhiteSpace(char)); | ||
}; | ||
var name = tagChars.grabWhile(validAttrName); | ||
var isEnd = tagChars.isLast(); | ||
var isValue = tagChars.getCurr() !== EQ_1; | ||
const validAttrName = (char)=>!(char === EQ || isWhiteSpace(char)); | ||
const name = tagChars.grabWhile(validAttrName); | ||
const isEnd = tagChars.isLast(); | ||
const isValue = tagChars.getCurr() !== EQ; | ||
tagChars.skip(); | ||
@@ -745,13 +524,13 @@ if (isEnd || isValue) { | ||
if (tagMode === TAG_STATE_VALUE) { | ||
var stateSpecial = false; | ||
var validAttrValue = function(char) { | ||
let stateSpecial = false; | ||
const validAttrValue = (char)=>{ | ||
// const isEQ = char === EQ; | ||
var isQM = char === QUOTEMARK_1; | ||
var prevChar = tagChars.getPrev(); | ||
var nextChar = tagChars.getNext(); | ||
var isPrevSLASH = prevChar === BACKSLASH_1; | ||
var isNextEQ = nextChar === EQ_1; | ||
var isWS = isWhiteSpace(char); | ||
const isQM = char === QUOTEMARK; | ||
const prevChar = tagChars.getPrev(); | ||
const nextChar = tagChars.getNext(); | ||
const isPrevSLASH = prevChar === BACKSLASH; | ||
const isNextEQ = nextChar === EQ; | ||
const isWS = isWhiteSpace(char); | ||
// const isPrevWS = isWhiteSpace(prevChar); | ||
var isNextWS = isWhiteSpace(nextChar); | ||
const isNextWS = isWhiteSpace(nextChar); | ||
if (stateSpecial && isSpecialChar(char)) { | ||
@@ -772,5 +551,5 @@ return true; | ||
}; | ||
var name = tagChars.grabWhile(validAttrValue); | ||
const name1 = tagChars.grabWhile(validAttrValue); | ||
tagChars.skip(); | ||
emitToken(TYPE_ATTR_VALUE, unq(name)); | ||
emitToken(TYPE_ATTR_VALUE, unq(name1)); | ||
if (tagChars.isLast()) { | ||
@@ -781,7 +560,5 @@ return TAG_STATE_NAME; | ||
} | ||
var validName = function(char) { | ||
return !(char === EQ_1 || isWhiteSpace(char) || tagChars.isLast()); | ||
}; | ||
var name = tagChars.grabWhile(validName); | ||
emitToken(TYPE_TAG, name); | ||
const validName = (char)=>!(char === EQ || isWhiteSpace(char) || tagChars.isLast()); | ||
const name2 = tagChars.grabWhile(validName); | ||
emitToken(TYPE_TAG, name2); | ||
tagChars.skip(); | ||
@@ -792,13 +569,13 @@ // in cases when we has [url=someval]GET[/url] and we dont need to parse all | ||
} | ||
var hasEQ = tagChars.includes(EQ_1); | ||
const hasEQ = tagChars.includes(EQ); | ||
return hasEQ ? TAG_STATE_ATTR : TAG_STATE_VALUE; | ||
}; | ||
var stateTag = function stateTag() { | ||
var currChar = chars.getCurr(); | ||
} | ||
function stateTag() { | ||
const currChar = chars.getCurr(); | ||
if (currChar === openTag) { | ||
var nextChar = chars.getNext(); | ||
const nextChar = chars.getNext(); | ||
chars.skip(); | ||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word' | ||
var substr = chars.substrUntilChar(closeTag); | ||
var hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
const substr = chars.substrUntilChar(closeTag); | ||
const hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0; | ||
if (isCharReserved(nextChar) || hasInvalidChars || chars.isLast()) { | ||
@@ -809,9 +586,7 @@ emitToken(TYPE_WORD, currChar); | ||
// [myTag ] | ||
var isNoAttrsInTag = substr.indexOf(EQ_1) === -1; | ||
const isNoAttrsInTag = substr.indexOf(EQ) === -1; | ||
// [/myTag] | ||
var isClosingTag = substr[0] === SLASH_1; | ||
const isClosingTag = substr[0] === SLASH; | ||
if (isNoAttrsInTag || isClosingTag) { | ||
var name = chars.grabWhile(function(char) { | ||
return char !== closeTag; | ||
}); | ||
const name = chars.grabWhile((char)=>char !== closeTag); | ||
chars.skip(); // skip closeTag | ||
@@ -824,12 +599,10 @@ emitToken(TYPE_TAG, name); | ||
return STATE_WORD; | ||
}; | ||
var stateAttrs = function stateAttrs() { | ||
var silent = true; | ||
var tagStr = chars.grabWhile(function(char) { | ||
return char !== closeTag; | ||
}, silent); | ||
var tagGrabber = createCharGrabber(tagStr, { | ||
onSkip: onSkip | ||
} | ||
function stateAttrs() { | ||
const silent = true; | ||
const tagStr = chars.grabWhile((char)=>char !== closeTag, silent); | ||
const tagGrabber = createCharGrabber(tagStr, { | ||
onSkip | ||
}); | ||
var hasSpace = tagGrabber.includes(SPACE_1); | ||
const hasSpace = tagGrabber.includes(SPACE); | ||
tagMode = TAG_STATE_NAME; | ||
@@ -841,4 +614,4 @@ while(tagGrabber.hasNext()){ | ||
return STATE_WORD; | ||
}; | ||
var stateWord = function stateWord() { | ||
} | ||
function stateWord() { | ||
if (isNewLine(chars.getCurr())) { | ||
@@ -865,4 +638,4 @@ emitToken(TYPE_NEW_LINE, chars.getCurr()); | ||
if (isEscapeChar(chars.getCurr())) { | ||
var currChar = chars.getCurr(); | ||
var nextChar = chars.getNext(); | ||
const currChar = chars.getCurr(); | ||
const nextChar = chars.getNext(); | ||
chars.skip(); // skip the \ without emitting anything | ||
@@ -877,5 +650,3 @@ if (isEscapableChar(nextChar)) { | ||
} | ||
var isChar = function(char) { | ||
return isCharToken(char) && !isEscapeChar(char); | ||
}; | ||
const isChar = (char)=>isCharToken(char) && !isEscapeChar(char); | ||
emitToken(TYPE_WORD, chars.grabWhile(isChar)); | ||
@@ -886,4 +657,4 @@ return STATE_WORD; | ||
return STATE_WORD; | ||
}; | ||
var tokenize = function tokenize() { | ||
} | ||
function tokenize() { | ||
stateMode = STATE_WORD; | ||
@@ -908,85 +679,11 @@ while(chars.hasNext()){ | ||
return tokens; | ||
}; | ||
var isTokenNested = function isTokenNested(token) { | ||
var value = openTag + SLASH_1 + token.getValue(); | ||
} | ||
function isTokenNested(token) { | ||
const value = openTag + SLASH + token.getValue(); | ||
// potential bottleneck | ||
return buffer.indexOf(value) > -1; | ||
}; | ||
var STATE_WORD = 0; | ||
var STATE_TAG = 1; | ||
var STATE_TAG_ATTRS = 2; | ||
var TAG_STATE_NAME = 0; | ||
var TAG_STATE_ATTR = 1; | ||
var TAG_STATE_VALUE = 2; | ||
var row = 0; | ||
var col = 0; | ||
var tokenIndex = -1; | ||
var stateMode = STATE_WORD; | ||
var tagMode = TAG_STATE_NAME; | ||
var tokens = new Array(Math.floor(buffer.length)); | ||
var openTag = options.openTag || OPEN_BRAKET_1; | ||
var closeTag = options.closeTag || CLOSE_BRAKET_1; | ||
var escapeTags = !!options.enableEscapeTags; | ||
var onToken = options.onToken || function() { | ||
}; | ||
var RESERVED_CHARS = [ | ||
closeTag, | ||
openTag, | ||
QUOTEMARK_1, | ||
BACKSLASH_1, | ||
SPACE_1, | ||
TAB_1, | ||
EQ_1, | ||
N_1, | ||
EM | ||
]; | ||
var NOT_CHAR_TOKENS = [ | ||
// ...(options.enableEscapeTags ? [BACKSLASH] : []), | ||
openTag, | ||
SPACE_1, | ||
TAB_1, | ||
N_1, | ||
]; | ||
var WHITESPACES = [ | ||
SPACE_1, | ||
TAB_1 | ||
]; | ||
var SPECIAL_CHARS = [ | ||
EQ_1, | ||
SPACE_1, | ||
TAB_1 | ||
]; | ||
var isCharReserved = function(char) { | ||
return RESERVED_CHARS.indexOf(char) >= 0; | ||
}; | ||
var isNewLine = function(char) { | ||
return char === N_1; | ||
}; | ||
var isWhiteSpace = function(char) { | ||
return WHITESPACES.indexOf(char) >= 0; | ||
}; | ||
var isCharToken = function(char) { | ||
return NOT_CHAR_TOKENS.indexOf(char) === -1; | ||
}; | ||
var isSpecialChar = function(char) { | ||
return SPECIAL_CHARS.indexOf(char) >= 0; | ||
}; | ||
var isEscapableChar = function(char) { | ||
return char === openTag || char === closeTag || char === BACKSLASH_1; | ||
}; | ||
var isEscapeChar = function(char) { | ||
return char === BACKSLASH_1; | ||
}; | ||
var onSkip = function() { | ||
col++; | ||
}; | ||
var unq = function(val) { | ||
return unquote(trimChar(val, QUOTEMARK_1)); | ||
}; | ||
var chars = createCharGrabber(buffer, { | ||
onSkip: onSkip | ||
}); | ||
} | ||
return { | ||
tokenize: tokenize, | ||
isTokenNested: isTokenNested | ||
tokenize, | ||
isTokenNested | ||
}; | ||
@@ -1005,9 +702,7 @@ } | ||
* @return {Array} | ||
*/ var parse = function(input, param) { | ||
var opts = param === void 0 ? { | ||
} : param; | ||
var options = opts; | ||
var openTag = options.openTag || OPEN_BRAKET_1; | ||
var closeTag = options.closeTag || CLOSE_BRAKET_1; | ||
var tokenizer = null; | ||
*/ const parse = (input, opts = {})=>{ | ||
const options = opts; | ||
const openTag = options.openTag || OPEN_BRAKET; | ||
const closeTag = options.closeTag || CLOSE_BRAKET; | ||
let tokenizer = null; | ||
/** | ||
@@ -1017,3 +712,3 @@ * Result AST of nodes | ||
* @type {NodeList} | ||
*/ var nodes = createList(); | ||
*/ const nodes = createList(); | ||
/** | ||
@@ -1023,3 +718,3 @@ * Temp buffer of nodes that's nested to another node | ||
* @type {NodeList} | ||
*/ var nestedNodes = createList(); | ||
*/ const nestedNodes = createList(); | ||
/** | ||
@@ -1029,3 +724,3 @@ * Temp buffer of nodes [tag..]...[/tag] | ||
* @type {NodeList} | ||
*/ var tagNodes = createList(); | ||
*/ const tagNodes = createList(); | ||
/** | ||
@@ -1035,6 +730,6 @@ * Temp buffer of tag attributes | ||
* @type {NodeList} | ||
*/ var tagNodesAttrName = createList(); | ||
*/ const tagNodesAttrName = createList(); | ||
/** | ||
* Cache for nested tags checks | ||
*/ var nestedTagsMap = new Set(); | ||
*/ const nestedTagsMap = new Set(); | ||
/** | ||
@@ -1044,4 +739,4 @@ * | ||
* @returns {boolean} | ||
*/ var isTokenNested = function(token) { | ||
var value = token.getValue(); | ||
*/ const isTokenNested = (token)=>{ | ||
const value = token.getValue(); | ||
if (!nestedTagsMap.has(value) && tokenizer.isTokenNested && tokenizer.isTokenNested(token)) { | ||
@@ -1056,5 +751,3 @@ nestedTagsMap.add(value); | ||
* @returns {boolean} | ||
*/ var isTagNested = function(tagName) { | ||
return Boolean(nestedTagsMap.has(tagName)); | ||
}; | ||
*/ const isTagNested = (tagName)=>Boolean(nestedTagsMap.has(tagName)); | ||
/** | ||
@@ -1064,3 +757,3 @@ * @private | ||
* @return {boolean} | ||
*/ var isAllowedTag = function(value) { | ||
*/ const isAllowedTag = (value)=>{ | ||
if (options.onlyAllowTags && options.onlyAllowTags.length) { | ||
@@ -1075,3 +768,3 @@ return options.onlyAllowTags.indexOf(value) >= 0; | ||
* @return {Array} | ||
*/ var flushTagNodes = function() { | ||
*/ const flushTagNodes = ()=>{ | ||
if (tagNodes.flushLast()) { | ||
@@ -1084,4 +777,4 @@ tagNodesAttrName.flushLast(); | ||
* @return {Array} | ||
*/ var getNodes = function() { | ||
var lastNestedNode = nestedNodes.getLast(); | ||
*/ const getNodes = ()=>{ | ||
const lastNestedNode = nestedNodes.getLast(); | ||
if (lastNestedNode && Array.isArray(lastNestedNode.content)) { | ||
@@ -1095,6 +788,6 @@ return lastNestedNode.content; | ||
* @param {string|TagNode} node | ||
*/ var appendNodes = function(node) { | ||
var items = getNodes(); | ||
*/ const appendNodes = (node)=>{ | ||
const items = getNodes(); | ||
if (Array.isArray(items)) { | ||
if (isTagNode_1(node)) { | ||
if (isTagNode(node)) { | ||
if (isAllowedTag(node.tag)) { | ||
@@ -1104,12 +797,12 @@ items.push(node.toTagNode()); | ||
items.push(node.toTagStart({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
openTag, | ||
closeTag | ||
})); | ||
if (node.content.length) { | ||
node.content.forEach(function(item) { | ||
node.content.forEach((item)=>{ | ||
items.push(item); | ||
}); | ||
items.push(node.toTagEnd({ | ||
openTag: openTag, | ||
closeTag: closeTag | ||
openTag, | ||
closeTag | ||
})); | ||
@@ -1126,6 +819,6 @@ } | ||
* @param {Token} token | ||
*/ var handleTagStart = function(token) { | ||
*/ const handleTagStart = (token)=>{ | ||
flushTagNodes(); | ||
var tagNode = default_1.create(token.getValue()); | ||
var isNested = isTokenNested(token); | ||
const tagNode = TagNode.create(token.getValue()); | ||
const isNested = isTokenNested(token); | ||
tagNodes.push(tagNode); | ||
@@ -1141,13 +834,13 @@ if (isNested) { | ||
* @param {Token} token | ||
*/ var handleTagEnd = function(token) { | ||
*/ const handleTagEnd = (token)=>{ | ||
flushTagNodes(); | ||
var lastNestedNode = nestedNodes.flushLast(); | ||
const lastNestedNode = nestedNodes.flushLast(); | ||
if (lastNestedNode) { | ||
appendNodes(lastNestedNode); | ||
} else if (typeof options.onError === 'function') { | ||
var tag = token.getValue(); | ||
var line = token.getLine(); | ||
var column = token.getColumn(); | ||
const tag = token.getValue(); | ||
const line = token.getLine(); | ||
const column = token.getColumn(); | ||
options.onError({ | ||
message: "Inconsistent tag '".concat(tag, "' on line ").concat(line, " and column ").concat(column), | ||
message: `Inconsistent tag '${tag}' on line ${line} and column ${column}`, | ||
tagName: tag, | ||
@@ -1162,3 +855,3 @@ lineNumber: line, | ||
* @param {Token} token | ||
*/ var handleTag = function(token) { | ||
*/ const handleTag = (token)=>{ | ||
// [tag] | ||
@@ -1176,8 +869,8 @@ if (token.isStart()) { | ||
* @param {Token} token | ||
*/ var handleNode = function(token) { | ||
*/ const handleNode = (token)=>{ | ||
/** | ||
* @type {TagNode} | ||
*/ var lastTagNode = tagNodes.getLast(); | ||
var tokenValue = token.getValue(); | ||
var isNested = isTagNested(token); | ||
*/ const lastTagNode = tagNodes.getLast(); | ||
const tokenValue = token.getValue(); | ||
const isNested = isTagNested(token); | ||
if (lastTagNode) { | ||
@@ -1188,3 +881,3 @@ if (token.isAttrName()) { | ||
} else if (token.isAttrValue()) { | ||
var attrName = tagNodesAttrName.getLast(); | ||
const attrName = tagNodesAttrName.getLast(); | ||
if (attrName) { | ||
@@ -1216,3 +909,3 @@ lastTagNode.attr(attrName, tokenValue); | ||
* @param {Token} token | ||
*/ var onToken = function(token) { | ||
*/ const onToken = (token)=>{ | ||
if (token.isTag()) { | ||
@@ -1225,6 +918,6 @@ handleTag(token); | ||
tokenizer = (opts.createTokenizer ? opts.createTokenizer : createLexer)(input, { | ||
onToken: onToken, | ||
onToken, | ||
onlyAllowTags: options.onlyAllowTags, | ||
openTag: openTag, | ||
closeTag: closeTag, | ||
openTag, | ||
closeTag, | ||
enableEscapeTags: options.enableEscapeTags | ||
@@ -1237,15 +930,8 @@ }); | ||
var _typeof$2 = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
/* eslint-disable no-plusplus */ var isObj = function(value) { | ||
return typeof value === 'object'; | ||
}; | ||
var isBool = function(value) { | ||
return typeof value === 'boolean'; | ||
}; | ||
/* eslint-disable no-plusplus */ const isObj = (value)=>typeof value === 'object'; | ||
const isBool = (value)=>typeof value === 'boolean'; | ||
function iterate(t, cb) { | ||
var tree = t; | ||
const tree = t; | ||
if (Array.isArray(tree)) { | ||
for(var idx = 0; idx < tree.length; idx++){ | ||
for(let idx = 0; idx < tree.length; idx++){ | ||
tree[idx] = iterate(cb(tree[idx]), cb); | ||
@@ -1259,3 +945,3 @@ } | ||
function same(expected, actual) { | ||
if ((typeof expected === "undefined" ? "undefined" : _typeof$2(expected)) !== (typeof actual === "undefined" ? "undefined" : _typeof$2(actual))) { | ||
if (typeof expected !== typeof actual) { | ||
return false; | ||
@@ -1267,11 +953,7 @@ } | ||
if (Array.isArray(expected)) { | ||
return expected.every(function(exp) { | ||
return [].some.call(actual, function(act) { | ||
return same(exp, act); | ||
}); | ||
}); | ||
return expected.every((exp)=>[].some.call(actual, (act)=>same(exp, act))); | ||
} | ||
return Object.keys(expected).every(function(key) { | ||
var ao = actual[key]; | ||
var eo = expected[key]; | ||
return Object.keys(expected).every((key)=>{ | ||
const ao = actual[key]; | ||
const eo = expected[key]; | ||
if (isObj(eo) && eo !== null && ao !== null) { | ||
@@ -1287,4 +969,4 @@ return same(eo, ao); | ||
function match(expression, cb) { | ||
return Array.isArray(expression) ? iterate(this, function(node) { | ||
for(var idx = 0; idx < expression.length; idx++){ | ||
return Array.isArray(expression) ? iterate(this, (node)=>{ | ||
for(let idx = 0; idx < expression.length; idx++){ | ||
if (same(expression[idx], node)) { | ||
@@ -1295,5 +977,3 @@ return cb(node); | ||
return node; | ||
}) : iterate(this, function(node) { | ||
return same(expression, node) ? cb(node) : node; | ||
}); | ||
}) : iterate(this, (node)=>same(expression, node) ? cb(node) : node); | ||
} | ||
@@ -1305,21 +985,20 @@ | ||
function bbob(plugs) { | ||
var plugins = typeof plugs === 'function' ? [ | ||
const plugins = typeof plugs === 'function' ? [ | ||
plugs | ||
] : plugs || []; | ||
var options = { | ||
let options = { | ||
skipParse: false | ||
}; | ||
return { | ||
process: function(input, opts) { | ||
options = opts || { | ||
}; | ||
var parseFn = options.parser || parse; | ||
var renderFn = options.render; | ||
var data = options.data || null; | ||
process (input, opts) { | ||
options = opts || {}; | ||
const parseFn = options.parser || parse; | ||
const renderFn = options.render; | ||
const data = options.data || null; | ||
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); | ||
let tree = options.skipParse ? input || [] : parseFn(input, options); | ||
// raw tree before modification with plugins | ||
var raw = tree; | ||
const raw = tree; | ||
tree.messages = []; | ||
@@ -1329,9 +1008,9 @@ tree.options = options; | ||
tree.match = match; | ||
plugins.forEach(function(plugin) { | ||
plugins.forEach((plugin)=>{ | ||
tree = plugin(tree, { | ||
parse: parseFn, | ||
render: renderFn, | ||
iterate: iterate, | ||
match: match, | ||
data: data | ||
iterate, | ||
match, | ||
data | ||
}) || tree; | ||
@@ -1346,4 +1025,4 @@ }); | ||
}, | ||
tree: tree, | ||
raw: raw, | ||
tree, | ||
raw, | ||
messages: tree.messages | ||
@@ -1355,112 +1034,9 @@ }; | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for(var i = 0, arr2 = new Array(arr.length); i < arr.length; i++){ | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
var _typeof$1 = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var keysReduce = function(obj, reduce, def) { | ||
return Object.keys(obj).reduce(reduce, def); | ||
}; | ||
/** | ||
* Replaces " to &qquot; | ||
* @param {String} value | ||
*/ var escapeHTML = function(value) { | ||
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')// eslint-disable-next-line no-script-url | ||
.replace(/(javascript):/gi, '$1%3A'); | ||
}; | ||
/** | ||
* Acept name and value and return valid html5 attribute string | ||
* @param {String} name | ||
* @param {String} value | ||
* @return {string} | ||
*/ var attrValue = function(name, value) { | ||
var type = typeof value === "undefined" ? "undefined" : _typeof$1(value); | ||
var types = { | ||
boolean: function() { | ||
return value ? "".concat(name) : ''; | ||
}, | ||
number: function() { | ||
return "".concat(name, "=\"").concat(value, "\""); | ||
}, | ||
string: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(value), "\""); | ||
}, | ||
object: function() { | ||
return "".concat(name, "=\"").concat(escapeHTML(JSON.stringify(value)), "\""); | ||
} | ||
}; | ||
return types[type] ? types[type]() : ''; | ||
}; | ||
/** | ||
* Transforms attrs to html params string | ||
* @param values | ||
*/ var attrsToString = function(values) { | ||
// To avoid some malformed attributes | ||
if (values == null) { | ||
return ''; | ||
} | ||
return keysReduce(values, function(arr, key) { | ||
return _toConsumableArray(arr).concat([ | ||
attrValue(key, values[key]) | ||
]); | ||
}, [ | ||
'' | ||
]).join(' '); | ||
}; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectSpread(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : { | ||
}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
var _typeof = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var SELFCLOSE_END_TAG = '/>'; | ||
var CLOSE_START_TAG = '</'; | ||
var START_TAG = '<'; | ||
var END_TAG = '>'; | ||
var renderNode = function(node, param) { | ||
var _stripTags = param.stripTags, stripTags = _stripTags === void 0 ? false : _stripTags; | ||
const SELFCLOSE_END_TAG = '/>'; | ||
const CLOSE_START_TAG = '</'; | ||
const START_TAG = '<'; | ||
const END_TAG = '>'; | ||
const renderNode = (node, { stripTags =false })=>{ | ||
if (!node) return ''; | ||
var type = typeof node === "undefined" ? "undefined" : _typeof(node); | ||
const type = typeof node; | ||
if (type === 'string' || type === 'number') { | ||
@@ -1473,3 +1049,3 @@ return node; | ||
return renderNodes(node.content, { | ||
stripTags: stripTags | ||
stripTags | ||
}); | ||
@@ -1500,3 +1076,3 @@ } | ||
return renderNodes(node, { | ||
stripTags: stripTags | ||
stripTags | ||
}); | ||
@@ -1506,20 +1082,12 @@ } | ||
}; | ||
var renderNodes = function(nodes, param) { | ||
var ref = param === void 0 ? { | ||
} : param, _stripTags = ref.stripTags, stripTags = _stripTags === void 0 ? false : _stripTags; | ||
return [].concat(nodes).reduce(function(r, node) { | ||
return r + renderNode(node, { | ||
stripTags: stripTags | ||
}); | ||
}, ''); | ||
}; | ||
var toHTML = function(source, plugins, options) { | ||
return bbob(plugins).process(source, _objectSpread({ | ||
}, options, { | ||
const renderNodes = (nodes, { stripTags =false } = {})=>[].concat(nodes).reduce((r, node)=>r + renderNode(node, { | ||
stripTags | ||
}), ''); | ||
const toHTML = (source, plugins, options)=>bbob(plugins).process(source, { | ||
...options, | ||
render: renderNodes | ||
})).html; | ||
}; | ||
var render = renderNodes; | ||
}).html; | ||
const render = renderNodes; | ||
exports["default"] = toHTML; | ||
exports.default = toHTML; | ||
exports.render = render; | ||
@@ -1526,0 +1094,0 @@ |
@@ -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="undefined"!=typeof globalThis?globalThis:t||self).BbobHtml={})}(this,(function(t){"use strict";var n={},e={};Object.defineProperty(e,"__esModule",{value:!0});var r=e.BACKSLASH=e.PLACEHOLDER_SPACE=e.PLACEHOLDER_SPACE_TAB=l=e.SLASH=e.CLOSE_BRAKET=e.OPEN_BRAKET=e.SPACE=e.QUOTEMARK=e.EQ=e.TAB=e.R=e.F=e.N=void 0,o=e.N="\n";e.F="\f",e.R="\r";var i=e.TAB="\t",u=e.EQ="=",a=e.QUOTEMARK='"',c=e.SPACE=" ",s=e.OPEN_BRAKET="[",f=e.CLOSE_BRAKET="]",l=e.SLASH="/";e.PLACEHOLDER_SPACE_TAB=" ",e.PLACEHOLDER_SPACE=" ",r=e.BACKSLASH="\\";var g={};Object.defineProperty(g,"__esModule",{value:!0}),g.isEOL=g.isStringNode=m=g.isTagNode=g.getUniqAttr=g.getNodeLength=g.escapeHTML=g.appendToNode=g.attrValue=g.attrsToString=void 0;var p=e;function v(t){return function(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);t.length>n;n++)e[n]=t[n];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var d=function(t){return"object"==typeof t&&!!t.tag},y=function(t){return"string"==typeof t},h=function(t,n,e){return Object.keys(t).reduce(n,e)},b=function(t){return d(t)?t.content.reduce((function(t,n){return t+b(n)}),0):y(t)?t.length:0},T=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")},A=function(t,n){var e,r=void 0===n?"undefined":(e=n)&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e,o={boolean:function(){return n?"".concat(t):""},number:function(){return"".concat(t,'="').concat(n,'"')},string:function(){return"".concat(t,'="').concat(T(n),'"')},object:function(){return"".concat(t,'="').concat(T(JSON.stringify(n)),'"')}};return o[r]?o[r]():""};g.attrsToString=function(t){return null==t?"":h(t,(function(n,e){return v(n).concat([A(e,t[e])])}),[""]).join(" ")},g.attrValue=A,g.appendToNode=function(t,n){t.content.push(n)},g.escapeHTML=T,g.getNodeLength=b,g.getUniqAttr=function(t){return h(t,(function(n,e){return t[e]===e?t[e]:null}),null)};var m=g.isTagNode=d;g.isStringNode=y,g.isEOL=function(t){return t===p.N},Object.defineProperty(n,"__esModule",{value:!0});var E=n.default=n.TagNode=void 0,O=e,S=g;function k(t,n){for(var e=0;n.length>e;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)}}function N(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}var L=function(t,n){var e=S.getUniqAttr(n);if(e){var r=S.attrValue(t,e),o=function(t){for(var n=1;arguments.length>n;n++){var e=null!=arguments[n]?arguments[n]:{},r=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(e).filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})))),r.forEach((function(n){N(t,n,e[n])}))}return t}({},n);delete o[e];var i=S.attrsToString(o);return"".concat(r).concat(i)}return"".concat(t).concat(S.attrsToString(n))},w=function(){function t(n,e,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.tag=n,this.attrs=e,this.content=Array.isArray(r)?r:[r]}var n,e,r;return n=t,(e=[{key:"attr",value:function(t,n){return void 0!==n&&(this.attrs[t]=n),this.attrs[t]}},{key:"append",value:function(t){return S.appendToNode(this,t)}},{key:"length",get:function(){return S.getNodeLength(this)}},{key:"toTagStart",value:function(t){var n=void 0===t?{}:t,e=n.openTag,r=void 0===e?O.OPEN_BRAKET:e,o=n.closeTag,i=void 0===o?O.CLOSE_BRAKET:o,u=L(this.tag,this.attrs);return"".concat(r).concat(u).concat(i)}},{key:"toTagEnd",value:function(t){var n=void 0===t?{}:t,e=n.openTag,r=n.closeTag,o=void 0===r?O.CLOSE_BRAKET:r;return"".concat(void 0===e?O.OPEN_BRAKET:e).concat(O.SLASH).concat(this.tag).concat(o)}},{key:"toTagNode",value:function(){return new t(this.tag.toLowerCase(),this.attrs,this.content)}},{key:"toString",value:function(t){var n=void 0===t?{}:t,e=n.openTag,r=void 0===e?O.OPEN_BRAKET:e,o=n.closeTag,i=void 0===o?O.CLOSE_BRAKET:o,u=0===this.content.length,a=this.content.reduce((function(t,n){return t+n.toString({openTag:r,closeTag:i})}),""),c=this.toTagStart({openTag:r,closeTag:i});return u?c:"".concat(c).concat(a).concat(this.toTagEnd({openTag:r,closeTag:i}))}}])&&k(n.prototype,e),r&&k(n,r),t}();function C(t,n){for(var e=0;n.length>e;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)}}w.create=function(t,n,e){return new w(t,void 0===n?{}:n,void 0===e?[]:e)},w.isOf=function(t,n){return t.tag===n},n.TagNode=w,E=n.default=w;var j=function(t){return t&&void 0!==t.value?t.value:""},P=function(t){return j(t).charCodeAt(0)===l.charCodeAt(0)},_=function(){function t(n,e,r,o){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.type=Number(n),this.value=e+"",this.line=Number(r),this.row=Number(o)}var n,e,r;return n=t,(e=[{key:"isEmpty",value:function(){return isNaN(this.type)}},{key:"isText",value:function(){return!(!(t=this)||void 0===t.type||5!==t.type&&6!==t.type&&1!==t.type);var t}},{key:"isTag",value:function(){return!(!(t=this)||void 0===t.type)&&2===t.type;var t}},{key:"isAttrName",value:function(){return!(!(t=this)||void 0===t.type)&&3===t.type;var t}},{key:"isAttrValue",value:function(){return!(!(t=this)||void 0===t.type)&&4===t.type;var t}},{key:"isStart",value:function(){return!P(this)}},{key:"isEnd",value:function(){return P(this)}},{key:"getName",value:function(){return n=j(t=this),P(t)?n.slice(1):n;var t,n}},{key:"getValue",value:function(){return j(this)}},{key:"getLine",value:function(){return(t=this)&&t.line||0;var t}},{key:"getColumn",value:function(){return(t=this)&&t.row||0;var t}},{key:"toString",value:function(){return t=s,(t+=j(this))+f;var t}}])&&C(n.prototype,e),r&&C(n,r),t}();function x(t,n){var e={pos:0,len:t.length},r=function(){return e.len>e.pos},o=function(t,r){e.pos+=void 0===t?1:t,n&&n.onSkip&&!r&&n.onSkip()},i=function(){return t[e.pos]};this.skip=o,this.hasNext=r,this.getCurr=i,this.getRest=function(){return t.substr(e.pos)},this.getNext=function(){var n=e.pos+1;return n>t.length-1?null:t[n]},this.getPrev=function(){var n=e.pos-1;return void 0!==t[n]?t[n]:null},this.isLast=function(){return e.pos===e.len},this.includes=function(n){return t.indexOf(n,e.pos)>=0},this.grabWhile=function(n,u){var a=0;if(r())for(a=e.pos;r()&&n(i());)o(1,u);return t.substr(a,e.pos-a)},this.substrUntilChar=function(n){var r=e.pos,o=t.indexOf(n,r);return 0>o?"":t.substr(r,o-r)}}var R=function(t,n){return new x(t,n)};function B(t){var n=void 0===t?[]:t;this.push=function(t){return n.push(t)},this.toArray=function(){return n},this.getLast=function(){return Array.isArray(n)&&n.length>0&&void 0!==n[n.length-1]?n[n.length-1]:null},this.flushLast=function(){return!!n.length&&n.pop()}}var K=function(t){return new B(void 0===t?[]:t)};function H(t,n){var e=void 0===n?{}:n,g=function(t,n){var e=function(t,n,e,r){return new _(t,n,void 0===e?0:e,void 0===r?0:r)}(t,n,O,S);x(e),w[k+=1]=e},p=function(t,n){if(L===m){var e=t.grabWhile((function(t){return!(t===u||U(t))})),o=t.isLast(),i=t.getCurr()!==u;return t.skip(),o||i?g(4,F(e)):g(3,e),o?A:i?m:E}if(L===E){var c=!1;e=t.grabWhile((function(e){var o=e===a,i=t.getPrev(),s=t.getNext(),f=i===r,l=s===u,g=U(e),p=U(s);return!(!c||!q(e))||!!(!o||f||(c=!c)||l||p)&&(!!n||!1===g)}));return t.skip(),g(4,F(e)),t.isLast()?A:m}e=t.grabWhile((function(n){return!(n===u||U(n)||t.isLast())}));return g(2,e),t.skip(),n?E:t.includes(u)?m:E},v=function(){var t=J.getCurr();if(t===C){var n=J.getNext();J.skip();var e=J.substrUntilChar(j),r=0===e.length||e.indexOf(C)>=0;if(M(n)||r||J.isLast())return g(1,t),h;if(-1===e.indexOf(u)||e[0]===l){var o=J.grabWhile((function(t){return t!==j}));return J.skip(),g(2,o),h}return T}return h},d=function(){var t=J.grabWhile((function(t){return t!==j}),!0),n=R(t,{onSkip:I}),e=n.includes(c);for(L=A;n.hasNext();)L=p(n,!e);return J.skip(),h},y=function(){if(W(J.getCurr()))return g(6,J.getCurr()),J.skip(),S=0,O++,h;if(U(J.getCurr()))return g(5,J.grabWhile(U)),h;if(J.getCurr()===C)return J.includes(j)?b:(g(1,J.getCurr()),J.skip(),h);if(P){if(Q(J.getCurr())){var t=J.getCurr(),n=J.getNext();return J.skip(),z(n)?(J.skip(),g(1,n),h):(g(1,t),h)}return g(1,J.grabWhile((function(t){return D(t)&&!Q(t)}))),h}return g(1,J.grabWhile(D)),h},h=0,b=1,T=2,A=0,m=1,E=2,O=0,S=0,k=-1,N=h,L=A,w=Array(Math.floor(t.length)),C=e.openTag||s,j=e.closeTag||f,P=!!e.enableEscapeTags,x=e.onToken||function(){},B=[j,C,a,r,c,i,u,o,"!"],K=[C,c,i,o],H=[c,i],V=[u,c,i],M=function(t){return B.indexOf(t)>=0},W=function(t){return t===o},U=function(t){return H.indexOf(t)>=0},D=function(t){return-1===K.indexOf(t)},q=function(t){return V.indexOf(t)>=0},z=function(t){return t===C||t===j||t===r},Q=function(t){return t===r},I=function(){S++},F=function(t){return 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,a).replace(r+a,a)},J=R(t,{onSkip:I});return{tokenize:function(){for(N=h;J.hasNext();)switch(N){case b:N=v();break;case T:N=d();break;case h:N=y();break;default:N=h}return w.length=k+1,w},isTokenNested:function(n){var e=C+l+n.getValue();return t.indexOf(e)>-1}}}var V=function(t,n){var e=void 0===n?{}:n,r=e,o=r.openTag||s,i=r.closeTag||f,u=null,a=K(),c=K(),l=K(),g=K(),p=new Set,v=function(){l.flushLast()&&g.flushLast()},d=function(t){var n,e,u=(n=c.getLast())&&Array.isArray(n.content)?n.content:a.toArray();Array.isArray(u)&&(m(t)?(e=t.tag,r.onlyAllowTags&&r.onlyAllowTags.length&&0>r.onlyAllowTags.indexOf(e)?(u.push(t.toTagStart({openTag:o,closeTag:i})),t.content.length&&(t.content.forEach((function(t){u.push(t)})),u.push(t.toTagEnd({openTag:o,closeTag:i})))):u.push(t.toTagNode())):u.push(t))},y=function(t){v();var n=E.create(t.getValue()),e=function(t){var n=t.getValue();return!p.has(n)&&u.isTokenNested&&u.isTokenNested(t)?(p.add(n),!0):p.has(n)}(t);l.push(n),e?c.push(n):d(n)},h=function(t){t.isStart()&&y(t),t.isEnd()&&function(t){v();var n=c.flushLast();if(n)d(n);else if("function"==typeof r.onError){var e=t.getValue(),o=t.getLine(),i=t.getColumn();r.onError({message:"Inconsistent tag '".concat(e,"' on line ").concat(o," and column ").concat(i),tagName:e,lineNumber:o,columnNumber:i})}}(t)},b=function(t){var n=l.getLast(),e=t.getValue(),r=!!p.has(t);if(n)if(t.isAttrName())g.push(e),n.attr(g.getLast(),"");else if(t.isAttrValue()){var o=g.getLast();o?(n.attr(o,e),g.flushLast()):n.attr(e,e)}else t.isText()?r?n.append(e):d(e):t.isTag()&&d(""+t);else t.isText()?d(e):t.isTag()&&d(""+t)};return(u=(e.createTokenizer?e.createTokenizer:H)(t,{onToken:function(t){t.isTag()?h(t):b(t)},onlyAllowTags:r.onlyAllowTags,openTag:o,closeTag:i,enableEscapeTags:r.enableEscapeTags})).tokenize(),a.toArray()},M=function(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},W=function(t){return"object"==typeof t};function U(t,n){var e=t;if(Array.isArray(e))for(var r=0;e.length>r;r++)e[r]=U(n(e[r]),n);else e&&W(e)&&e.content&&U(e.content,n);return e}function D(t,n){return(void 0===t?"undefined":M(t))===(void 0===n?"undefined":M(n))&&(W(t)&&null!==t?Array.isArray(t)?t.every((function(t){return[].some.call(n,(function(n){return D(t,n)}))})):Object.keys(t).every((function(e){var r=n[e],o=t[e];return W(o)&&null!==o&&null!==r?D(o,r):"boolean"==typeof o?o!==(null===r):r===o})):t===n)}function q(t,n){return U(this,Array.isArray(t)?function(e){for(var r=0;t.length>r;r++)if(D(t[r],e))return n(e);return e}:function(e){return D(t,e)?n(e):e})}function z(t){return U(this,t)}function Q(t){return function(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);t.length>n;n++)e[n]=t[n];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var I=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript):/gi,"$1%3A")},F=function(t,n){var e,r=void 0===n?"undefined":(e=n)&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e,o={boolean:function(){return n?"".concat(t):""},number:function(){return"".concat(t,'="').concat(n,'"')},string:function(){return"".concat(t,'="').concat(I(n),'"')},object:function(){return"".concat(t,'="').concat(I(JSON.stringify(n)),'"')}};return o[r]?o[r]():""},J=function(t){return null==t?"":(n=t,e=function(n,e){return Q(n).concat([F(e,t[e])])},r=[""],Object.keys(n).reduce(e,r)).join(" ");var n,e,r};function $(t,n,e){return n in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}var G="/>",X="</",Y="<",Z=">",tt=function(t,n){var e=n.stripTags,r=void 0!==e&&e;if(!t)return"";var o,i=void 0===t?"undefined":(o=t)&&"undefined"!=typeof Symbol&&o.constructor===Symbol?"symbol":typeof o;return"string"===i||"number"===i?t:"object"===i?!0===r?nt(t.content,{stripTags:r}):null===t.content?""+Y+t.tag+J(t.attrs)+G:""+Y+t.tag+J(t.attrs)+Z+nt(t.content)+X+t.tag+Z:Array.isArray(t)?nt(t,{stripTags:r}):""},nt=function(t,n){var e=(void 0===n?{}:n).stripTags,r=void 0!==e&&e;return[].concat(t).reduce((function(t,n){return t+tt(n,{stripTags:r})}),"")},et=nt;t.default=function(t,n,e){return function(t){var n="function"==typeof t?[t]:t||[],e={skipParse:!1};return{process:function(t,r){var o=(e=r||{}).parser||V,i=e.render,u=e.data||null;if("function"!=typeof o)throw Error('"parser" is not a function, please pass to "process(input, { parser })" right function');var a=e.skipParse?t||[]:o(t,e),c=a;return a.messages=[],a.options=e,a.walk=z,a.match=q,n.forEach((function(t){a=t(a,{parse:o,render:i,iterate:U,match:q,data:u})||a})),{get html(){if("function"!=typeof i)throw Error('"render" function not defined, please pass to "process(input, { render })"');return i(a,a.options)},tree:a,raw:c,messages:a.messages}}}}(n).process(t,function(t){for(var n=1;arguments.length>n;n++){var e=null!=arguments[n]?arguments[n]:{},r=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(e).filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})))),r.forEach((function(n){$(t,n,e[n])}))}return t}({},e,{render:nt})).html},t.render=et,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="undefined"!=typeof globalThis?globalThis:t||self).BbobHtml={})}(this,function(t){"use strict";let e=t=>"object"==typeof t&&!!t.tag,r=t=>"string"==typeof t,n=(t,e,r)=>Object.keys(t).reduce(e,r),s=t=>e(t)?t.content.reduce((t,e)=>t+s(e),0):r(t)?t.length:0,i=(t,e)=>{t.content.push(e)},l=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/(javascript|data|vbscript):/gi,"$1%3A"),o=(t,e)=>{let r=typeof e,n={boolean:()=>e?""+t:"",number:()=>`${t}="${e}"`,string:()=>`${t}="${l(e)}"`,object:()=>`${t}="${l(JSON.stringify(e))}"`};return n[r]?n[r]():""},a=t=>null==t?"":n(t,(e,r)=>[...e,o(r,t[r])],[""]).join(" "),u=t=>n(t,(e,r)=>t[r]===r?t[r]:null,null),g=(t,e)=>{let r=u(e);if(r){let n=o(t,r),s={...e};delete s[r];let i=a(s);return`${n}${i}`}return`${t}${a(e)}`};class h{attr(t,e){return void 0!==e&&(this.attrs[t]=e),this.attrs[t]}append(t){return i(this,t)}get length(){return s(this)}toTagStart({openTag:t="[",closeTag:e="]"}={}){let r=g(this.tag,this.attrs);return`${t}${r}${e}`}toTagEnd({openTag:t="[",closeTag:e="]"}={}){return`${t}/${this.tag}${e}`}toTagNode(){return new h(this.tag.toLowerCase(),this.attrs,this.content)}toString({openTag:t="[",closeTag:e="]"}={}){let r=0===this.content.length,n=this.content.reduce((r,n)=>r+n.toString({openTag:t,closeTag:e}),""),s=this.toTagStart({openTag:t,closeTag:e});return r?s:`${s}${n}${this.toTagEnd({openTag:t,closeTag:e})}`}constructor(t,e,r){this.tag=t,this.attrs=e,this.content=Array.isArray(r)?r:[r]}}h.create=(t,e={},r=[])=>new h(t,e,r),h.isOf=(t,e)=>t.tag===e;let c="type",f="value",p="line",d=t=>t&&void 0!==t[f]?t[f]:"",y=t=>t&&t[p]||0,b=t=>t&&t.row||0,T=t=>!!t&&void 0!==t[c]&&(5===t[c]||6===t[c]||1===t[c]),A=t=>!!t&&void 0!==t[c]&&2===t[c],k=t=>47===d(t).charCodeAt(0),m=t=>!k(t),N=t=>!!t&&void 0!==t[c]&&3===t[c],x=t=>!!t&&void 0!==t[c]&&4===t[c],$=t=>{let e=d(t);return k(t)?e.slice(1):e},w=t=>d(t)+"]";class L{isEmpty(){return isNaN(this[c])}isText(){return T(this)}isTag(){return A(this)}isAttrName(){return N(this)}isAttrValue(){return x(this)}isStart(){return m(this)}isEnd(){return k(this)}getName(){return $(this)}getValue(){return d(this)}getLine(){return y(this)}getColumn(){return b(this)}toString(){return w(this)}constructor(t,e,r,n){this[c]=Number(t),this[f]=String(e),this[p]=Number(r),this.row=Number(n)}}function v(t,e){let r={pos:0,len:t.length},n=e=>{let{pos:n}=r,s=t.indexOf(e,n);return s>=0?t.substr(n,s-n):""},s=e=>t.indexOf(e,r.pos)>=0,i=()=>r.len>r.pos,l=(t=1,n)=>{r.pos+=t,e&&e.onSkip&&!n&&e.onSkip()},o=()=>t.substr(r.pos),a=()=>t[r.pos],u=()=>{let e=r.pos-1;return void 0!==t[e]?t[e]:null},g=()=>{let e=r.pos+1;return e<=t.length-1?t[e]:null},h=(e,n)=>{let s=0;if(i())for(s=r.pos;i()&&e(a());)l(1,n);return t.substr(s,r.pos-s)};this.skip=l,this.hasNext=i,this.getCurr=a,this.getRest=o,this.getNext=g,this.getPrev=u,this.isLast=()=>r.pos===r.len,this.includes=s,this.grabWhile=h,this.substrUntilChar=n}let C=(t,e)=>new v(t,e),E=(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},O=t=>t.replace('\\"','"');function S(t=[]){let e=()=>Array.isArray(t)&&t.length>0&&void 0!==t[t.length-1]?t[t.length-1]:null,r=()=>!!t.length&&t.pop(),n=e=>t.push(e);this.push=n,this.toArray=()=>t,this.getLast=e,this.flushLast=r}let j=(t=[])=>new S(t),W=(t,e,r=0,n=0)=>new L(t,e,r,n);function V(t,e={}){let r=0,n=0,s=-1,i=0,l=0,o=Array(Math.floor(t.length)),a=e.openTag||"[",u=e.closeTag||"]",g=!!e.enableEscapeTags,h=e.onToken||(()=>{}),c=[u,a,'"',"\\"," "," ","=","\n","!"],f=[a," "," ","\n"],p=[" "," "],d=["="," "," "],y=t=>c.indexOf(t)>=0,b=t=>"\n"===t,T=t=>p.indexOf(t)>=0,A=t=>-1===f.indexOf(t),k=t=>d.indexOf(t)>=0,m=t=>t===a||t===u||"\\"===t,N=t=>"\\"===t,x=()=>{n++},$=t=>O(E(t,'"')),w=C(t,{onSkip:x});function L(t,e){let i=W(t,e,r,n);h(i),o[s+=1]=i}return{tokenize:function(){for(i=0;w.hasNext();)switch(i){case 1:i=function(){let t=w.getCurr();if(t===a){let e=w.getNext();w.skip();let r=w.substrUntilChar(u),n=0===r.length||r.indexOf(a)>=0;if(y(e)||n||w.isLast())return L(1,t),0;let s=-1===r.indexOf("="),i="/"===r[0];if(s||i){let l=w.grabWhile(t=>t!==u);return w.skip(),L(2,l),0}return 2}return 0}();break;case 2:i=function(){let t=w.grabWhile(t=>t!==u,!0),e=C(t,{onSkip:x}),r=e.includes(" ");for(l=0;e.hasNext();)l=function(t,e){if(1===l){let r=t=>!("="===t||T(t)),n=t.grabWhile(r),s=t.isLast(),i="="!==t.getCurr();return(t.skip(),s||i?L(4,$(n)):L(3,n),s)?0:i?1:2}if(2===l){let o=!1,a=r=>{let n=t.getPrev(),s=t.getNext(),i=T(r),l=T(s);return!!(o&&k(r))||('"'!==r||"\\"===n||!!(o=!o)||"="===s||!!l)&&(!!e||!1===i)},u=t.grabWhile(a);return(t.skip(),L(4,$(u)),t.isLast())?0:1}let g=e=>!("="===e||T(e)||t.isLast()),h=t.grabWhile(g);if(L(2,h),t.skip(),e)return 2;let c=t.includes("=");return c?1:2}(e,!r);return w.skip(),0}();break;case 0:i=function(){if(b(w.getCurr()))return L(6,w.getCurr()),w.skip(),n=0,r++,0;if(T(w.getCurr()))return L(5,w.grabWhile(T)),0;if(w.getCurr()===a)return w.includes(u)?1:(L(1,w.getCurr()),w.skip(),0);if(g){if(N(w.getCurr())){let t=w.getCurr(),e=w.getNext();return(w.skip(),m(e))?(w.skip(),L(1,e),0):(L(1,t),0)}let s=t=>A(t)&&!N(t);return L(1,w.grabWhile(s)),0}return L(1,w.grabWhile(A)),0}();break;default:i=0}return o.length=s+1,o},isTokenNested:function(e){let r=a+"/"+e.getValue();return t.indexOf(r)>-1}}}let P=(t,r={})=>{let n=r.openTag||"[",s=r.closeTag||"]",i=null,l=j(),o=j(),a=j(),u=j(),g=new Set,c=t=>{let e=t.getValue();return!g.has(e)&&i.isTokenNested&&i.isTokenNested(t)?(g.add(e),!0):g.has(e)},f=t=>Boolean(g.has(t)),p=t=>!r.onlyAllowTags||!r.onlyAllowTags.length||r.onlyAllowTags.indexOf(t)>=0,d=()=>{a.flushLast()&&u.flushLast()},y=()=>{let t=o.getLast();return t&&Array.isArray(t.content)?t.content:l.toArray()},b=t=>{let r=y();Array.isArray(r)&&(e(t)?p(t.tag)?r.push(t.toTagNode()):(r.push(t.toTagStart({openTag:n,closeTag:s})),t.content.length&&(t.content.forEach(t=>{r.push(t)}),r.push(t.toTagEnd({openTag:n,closeTag:s})))):r.push(t))},T=t=>{d();let e=h.create(t.getValue()),r=c(t);a.push(e),r?o.push(e):b(e)},A=t=>{d();let e=o.flushLast();if(e)b(e);else if("function"==typeof r.onError){let n=t.getValue(),s=t.getLine(),i=t.getColumn();r.onError({message:`Inconsistent tag '${n}' on line ${s} and column ${i}`,tagName:n,lineNumber:s,columnNumber:i})}},k=t=>{t.isStart()&&T(t),t.isEnd()&&A(t)},m=t=>{let e=a.getLast(),r=t.getValue(),n=f(t);if(e){if(t.isAttrName())u.push(r),e.attr(u.getLast(),"");else if(t.isAttrValue()){let s=u.getLast();s?(e.attr(s,r),u.flushLast()):e.attr(r,r)}else t.isText()?n?e.append(r):b(r):t.isTag()&&b(t.toString())}else t.isText()?b(r):t.isTag()&&b(t.toString())},N=t=>{t.isTag()?k(t):m(t)};return(i=(r.createTokenizer?r.createTokenizer:V)(t,{onToken:N,onlyAllowTags:r.onlyAllowTags,openTag:n,closeTag:s,enableEscapeTags:r.enableEscapeTags})).tokenize(),l.toArray()},z=t=>"object"==typeof t,B=t=>"boolean"==typeof t;function M(t,e){let r=t;if(Array.isArray(r))for(let n=0;n<r.length;n++)r[n]=M(e(r[n]),e);else r&&z(r)&&r.content&&M(r.content,e);return r}function U(t,e){return typeof t==typeof e&&(z(t)&&null!==t?Array.isArray(t)?t.every(t=>[].some.call(e,e=>U(t,e))):Object.keys(t).every(r=>{let n=e[r],s=t[r];return z(s)&&null!==s&&null!==n?U(s,n):B(s)?s!==(null===n):n===s}):t===e)}function _(t,e){return Array.isArray(t)?M(this,r=>{for(let n=0;n<t.length;n++)if(U(t[n],r))return e(r);return r}):M(this,r=>U(t,r)?e(r):r)}function q(t){return M(this,t)}let H=(t,{stripTags:e=!1})=>{if(!t)return"";let r=typeof t;return"string"===r||"number"===r?t:"object"===r?!0===e?I(t.content,{stripTags:e}):null===t.content?["<",t.tag,a(t.attrs),"/>"].join(""):["<",t.tag,a(t.attrs),">",I(t.content),"</",t.tag,">"].join(""):Array.isArray(t)?I(t,{stripTags:e}):""},I=(t,{stripTags:e=!1}={})=>[].concat(t).reduce((t,r)=>t+H(r,{stripTags:e}),"");t.default=(t,e,r)=>(function(t){let e="function"==typeof t?[t]:t||[],r={skipParse:!1};return{process(t,n){r=n||{};let s=r.parser||P,i=r.render,l=r.data||null;if("function"!=typeof s)throw Error('"parser" is not a function, please pass to "process(input, { parser })" right function');let o=r.skipParse?t||[]:s(t,r),a=o;return o.messages=[],o.options=r,o.walk=q,o.match=_,e.forEach(t=>{o=t(o,{parse:s,render:i,iterate:M,match:_,data:l})||o}),{get html(){if("function"!=typeof i)throw Error('"render" function not defined, please pass to "process(input, { render })"');return i(o,o.options)},tree:o,raw:a,messages:o.messages}}}})(e).process(t,{...r,render:I}).html,t.render=I,Object.defineProperty(t,"__esModule",{value:!0})}); |
import core from '@bbob/core'; | ||
import { attrsToString } from '@bbob/plugin-helper'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectSpread(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : { | ||
}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
var _typeof = function(obj) { | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var SELFCLOSE_END_TAG = '/>'; | ||
var CLOSE_START_TAG = '</'; | ||
var START_TAG = '<'; | ||
var END_TAG = '>'; | ||
var renderNode = function(node, param) { | ||
var _stripTags = param.stripTags, stripTags = _stripTags === void 0 ? false : _stripTags; | ||
const SELFCLOSE_END_TAG = '/>'; | ||
const CLOSE_START_TAG = '</'; | ||
const START_TAG = '<'; | ||
const END_TAG = '>'; | ||
const renderNode = (node, { stripTags =false })=>{ | ||
if (!node) return ''; | ||
var type = typeof node === "undefined" ? "undefined" : _typeof(node); | ||
const type = typeof node; | ||
if (type === 'string' || type === 'number') { | ||
@@ -50,3 +17,3 @@ return node; | ||
return renderNodes(node.content, { | ||
stripTags: stripTags | ||
stripTags | ||
}); | ||
@@ -77,3 +44,3 @@ } | ||
return renderNodes(node, { | ||
stripTags: stripTags | ||
stripTags | ||
}); | ||
@@ -83,18 +50,10 @@ } | ||
}; | ||
var renderNodes = function(nodes, param) { | ||
var ref = param === void 0 ? { | ||
} : param, _stripTags = ref.stripTags, stripTags = _stripTags === void 0 ? false : _stripTags; | ||
return [].concat(nodes).reduce(function(r, node) { | ||
return r + renderNode(node, { | ||
stripTags: stripTags | ||
}); | ||
}, ''); | ||
}; | ||
var toHTML = function(source, plugins, options) { | ||
return core(plugins).process(source, _objectSpread({ | ||
}, options, { | ||
const renderNodes = (nodes, { stripTags =false } = {})=>[].concat(nodes).reduce((r, node)=>r + renderNode(node, { | ||
stripTags | ||
}), ''); | ||
const toHTML = (source, plugins, options)=>core(plugins).process(source, { | ||
...options, | ||
render: renderNodes | ||
})).html; | ||
}; | ||
export var render = renderNodes; | ||
}).html; | ||
export const render = renderNodes; | ||
export default toHTML; |
@@ -5,17 +5,31 @@ "use strict"; | ||
}); | ||
exports.default = exports.render = void 0; | ||
var _core = _interopRequireDefault(require("@bbob/core")); | ||
function _export(target, all) { | ||
for(var name in all)Object.defineProperty(target, name, { | ||
enumerable: true, | ||
get: all[name] | ||
}); | ||
} | ||
_export(exports, { | ||
render: function() { | ||
return render; | ||
}, | ||
default: function() { | ||
return _default; | ||
} | ||
}); | ||
var _core = /*#__PURE__*/ _interopRequireDefault(require("@bbob/core")); | ||
var _pluginHelper = require("@bbob/plugin-helper"); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return 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); | ||
} | ||
@@ -27,33 +41,18 @@ function _interopRequireDefault(obj) { | ||
} | ||
function _objectSpread(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : { | ||
}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
var _typeof = function(obj) { | ||
"@swc/helpers - typeof"; | ||
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var SELFCLOSE_END_TAG = '/>'; | ||
var CLOSE_START_TAG = '</'; | ||
var START_TAG = '<'; | ||
var END_TAG = '>'; | ||
var SELFCLOSE_END_TAG = "/>"; | ||
var CLOSE_START_TAG = "</"; | ||
var START_TAG = "<"; | ||
var END_TAG = ">"; | ||
var renderNode = function(node, param) { | ||
var _stripTags = param.stripTags, stripTags = _stripTags === void 0 ? false : _stripTags; | ||
if (!node) return ''; | ||
var _param_stripTags = param.stripTags, stripTags = _param_stripTags === void 0 ? false : _param_stripTags; | ||
if (!node) return ""; | ||
var type = typeof node === "undefined" ? "undefined" : _typeof(node); | ||
if (type === 'string' || type === 'number') { | ||
if (type === "string" || type === "number") { | ||
return node; | ||
} | ||
if (type === 'object') { | ||
if (type === "object") { | ||
if (stripTags === true) { | ||
@@ -69,5 +68,5 @@ // eslint-disable-next-line no-use-before-define | ||
node.tag, | ||
(0, _pluginHelper).attrsToString(node.attrs), | ||
(0, _pluginHelper.attrsToString)(node.attrs), | ||
SELFCLOSE_END_TAG | ||
].join(''); | ||
].join(""); | ||
} | ||
@@ -78,3 +77,3 @@ // eslint-disable-next-line no-use-before-define | ||
node.tag, | ||
(0, _pluginHelper).attrsToString(node.attrs), | ||
(0, _pluginHelper.attrsToString)(node.attrs), | ||
END_TAG, | ||
@@ -85,3 +84,3 @@ renderNodes(node.content), | ||
END_TAG | ||
].join(''); | ||
].join(""); | ||
} | ||
@@ -94,7 +93,6 @@ if (Array.isArray(node)) { | ||
} | ||
return ''; | ||
return ""; | ||
}; | ||
var renderNodes = function(nodes, param) { | ||
var ref = param === void 0 ? { | ||
} : param, _stripTags = ref.stripTags, stripTags = _stripTags === void 0 ? false : _stripTags; | ||
var _ref = param === void 0 ? {} : param, _ref_stripTags = _ref.stripTags, stripTags = _ref_stripTags === void 0 ? false : _ref_stripTags; | ||
return [].concat(nodes).reduce(function(r, node) { | ||
@@ -104,7 +102,6 @@ return r + renderNode(node, { | ||
}); | ||
}, ''); | ||
}, ""); | ||
}; | ||
var toHTML = function(source, plugins, options) { | ||
return (0, _core).default(plugins).process(source, _objectSpread({ | ||
}, options, { | ||
return (0, _core.default)(plugins).process(source, _extends({}, options, { | ||
render: renderNodes | ||
@@ -114,4 +111,2 @@ })).html; | ||
var render = renderNodes; | ||
exports.render = render; | ||
var _default = toHTML; | ||
exports.default = _default; |
{ | ||
"name": "@bbob/html", | ||
"version": "2.8.2", | ||
"version": "2.8.3", | ||
"description": "A BBCode to HTML Renderer part of @bbob", | ||
@@ -12,4 +12,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@bbob/core": "^2.8.2", | ||
"@bbob/plugin-helper": "^2.8.2" | ||
"@bbob/core": "^2.8.3", | ||
"@bbob/plugin-helper": "^2.8.3" | ||
}, | ||
@@ -62,3 +62,3 @@ "main": "lib/index.js", | ||
], | ||
"gitHead": "b2cfc23ee991330c4acc29484333b619c2d2a302" | ||
"gitHead": "0d9da27af8810756cac3a59dae421a19e7848cc7" | ||
} |
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
53708
1250
Updated@bbob/core@^2.8.3
Updated@bbob/plugin-helper@^2.8.3