2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-08 17:22:26 +03:00

fix(parser): dont process nested tags as string if parent is not allowed (#84)

* fix(parser): dont process nested tags as string if parent is not allowed

* fix(plugin-helper): toString method with default params
This commit is contained in:
Nikolay Kostyurin
2020-12-16 23:51:28 +02:00
committed by GitHub
parent 0d839fa947
commit 70ff2e6660
3 changed files with 128 additions and 56 deletions
+15 -7
View File
@@ -43,22 +43,30 @@ class TagNode {
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() {
const OB = OPEN_BRAKET;
const CB = CLOSE_BRAKET;
toString({ openTag = OPEN_BRAKET, closeTag = CLOSE_BRAKET } = {}) {
const isEmpty = this.content.length === 0;
const content = this.content.reduce((r, node) => r + node.toString(), '');
const tagAttrs = getTagAttrs(this.tag, this.attrs);
const content = this.content.reduce((r, node) => r + node.toString({ openTag, closeTag }), '');
const tagStart = this.toTagStart({ openTag, closeTag });
if (isEmpty) {
return `${OB}${tagAttrs}${CB}`;
return tagStart;
}
return `${OB}${tagAttrs}${CB}${content}${OB}${SLASH}${this.tag}${CB}`;
return `${tagStart}${content}${this.toTagEnd({ openTag, closeTag })}`;
}
}