Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
flushTag() {
if (this.inTag()) {
// [] and [=] tag case
if (this.tagToken[Token.VALUE_ID] === '') {
const value = this.inAttrValue() ? getChar(EQ) : '';
const word = getChar(OPEN_BRAKET) + value + getChar(CLOSE_BRAKET);
this.createWord('', 0, 0);
this.wordToken[Token.VALUE_ID] += word;
this.tagToken = this.dummyToken;
if (this.inAttrValue()) {
this.attrValueToken = this.dummyToken;
}
return;
}
if (this.inAttrName() && !this.inAttrValue()) {
this.tagToken[Token.VALUE_ID] += PLACEHOLDER_SPACE + this.attrNameToken[Token.VALUE_ID];
this.attrNameToken = this.dummyToken;
flushTag() {
if (this.inTag()) {
// [] and [=] tag case
if (this.tagToken[Token.VALUE_ID] === '') {
const value = this.inAttrValue() ? getChar(EQ) : '';
const word = getChar(OPEN_BRAKET) + value + getChar(CLOSE_BRAKET);
this.createWord('', 0, 0);
this.wordToken[Token.VALUE_ID] += word;
this.tagToken = this.dummyToken;
if (this.inAttrValue()) {
this.attrValueToken = this.dummyToken;
}
return;
}
if (this.inAttrName() && !this.inAttrValue()) {
this.tagToken[Token.VALUE_ID] += PLACEHOLDER_SPACE + this.attrNameToken[Token.VALUE_ID];
const renderNode = (node, { stripTags = false }) => {
if (!node) return '';
const 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 });
}
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 });
}
return '';
};
charWORD(charCode) {
if (this.inTag()) {
if (this.inAttrValue()) {
this.attrValueToken[Token.VALUE_ID] += getChar(charCode);
} else if (this.inAttrName()) {
this.attrNameToken[Token.VALUE_ID] += getChar(charCode);
} else {
this.tagToken[Token.VALUE_ID] += getChar(charCode);
}
} else {
this.createWord();
this.wordToken[Token.VALUE_ID] += getChar(charCode);
}
this.nextCol();
}
flushUnclosedTag() {
if (this.inTag()) {
const value = this.tagToken[Token.VALUE_ID] + (this.attrValueToken && this.attrValueToken[Token.VALUE_ID] ? getChar(EQ) : '');
this.tagToken[Token.TYPE_ID] = Token.TYPE_WORD;
this.tagToken[Token.VALUE_ID] = getChar(OPEN_BRAKET) + value;
this.appendToken(this.tagToken);
this.tagToken = this.dummyToken;
if (this.inAttrValue()) {
this.attrValueToken = this.dummyToken;
}
}
}
charEQ(charCode) {
const nextCharCode = this.seekChar(1);
const isNextQuotemark = nextCharCode === QUOTEMARK;
if (this.inTag()) {
this.attrValueToken = this.createAttrValueToken('');
if (isNextQuotemark) {
this.attrValueToken.quoted = true;
this.skipChar(1);
}
} else {
this.wordToken[Token.VALUE_ID] += getChar(charCode);
}
this.nextCol();
}
charN(charCode) {
this.flushWord();
this.appendToken(this.createNewLineToken(getChar(charCode)));
this.nextLine();
this.colPos = 0;
}
charCLOSEBRAKET(charCode) {
const prevCharCode = this.seekChar(-1);
const isPrevSpace = prevCharCode === SPACE || prevCharCode === TAB;
if (isPrevSpace) {
this.wordToken[Token.VALUE_ID] += getChar(charCode);
}
this.nextCol();
this.flushTag();
this.flushAttrNames();
this.flushAttrs();
}
content.forEach((el) => {
if (isStringNode(el) && isStartsWith(el, '*')) {
if (listItems[listIdx]) {
listIdx++;
}
ensureListItem(createItemNode());
addItem(el.substr(1));
} else if (isTagNode(el) && TagNode.isOf(el, '*')) {
if (listItems[listIdx]) {
listIdx++;
}
ensureListItem(createItemNode());
} else if (!isTagNode(listItems[listIdx])) {
listIdx++;
ensureListItem(el);
} else if (listItems[listIdx]) {
addItem(el);
} else {
ensureListItem(el);
}
});
tree.walk(node => (isTagNode(node) && tags[node.tag]
? tags[node.tag](node, core)
: node));
}