2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-30 15:24:05 +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
+14 -3
View File
@@ -1,4 +1,5 @@
import TagNode from '@bbob/plugin-helper/lib/TagNode';
import { CLOSE_BRAKET, OPEN_BRAKET } from '@bbob/plugin-helper/lib/char';
import { isTagNode } from '@bbob/plugin-helper/lib/index';
import { createLexer } from './lexer';
import { createList } from './utils';
@@ -16,6 +17,8 @@ import { createList } from './utils';
*/
const parse = (input, opts = {}) => {
const options = opts;
const openTag = options.openTag || OPEN_BRAKET;
const closeTag = options.closeTag || CLOSE_BRAKET;
let tokenizer = null;
@@ -114,7 +117,15 @@ const parse = (input, opts = {}) => {
if (isAllowedTag(node.tag)) {
items.push(node.toTagNode());
} else {
items.push(node.toString());
items.push(node.toTagStart({ openTag, closeTag }));
if (node.content.length) {
node.content.forEach((item) => {
items.push(item);
});
items.push(node.toTagEnd({ openTag, closeTag }));
}
}
} else {
items.push(node);
@@ -240,8 +251,8 @@ const parse = (input, opts = {}) => {
tokenizer = (opts.createTokenizer ? opts.createTokenizer : createLexer)(input, {
onToken,
onlyAllowTags: options.onlyAllowTags,
openTag: options.openTag,
closeTag: options.closeTag,
openTag,
closeTag,
enableEscapeTags: options.enableEscapeTags,
});