diff --git a/packages/bbob-parser/lib/parse.js b/packages/bbob-parser/lib/parse.js index a42a545..3bcb8b2 100644 --- a/packages/bbob-parser/lib/parse.js +++ b/packages/bbob-parser/lib/parse.js @@ -1,5 +1,5 @@ const { - convertTokenToText, + convertTagToText, getTagName, getTokenColumn, getTokenLine, @@ -187,7 +187,7 @@ const handleTagToken = (token) => { // [/tag] handleTagEnd(token); } else { - appendNode(convertTokenToText(token)); + appendNode(convertTagToText(token)); } } }; diff --git a/packages/bbob-parser/test/parse.test.js b/packages/bbob-parser/test/parse.test.js index be4ff85..c3fc07a 100644 --- a/packages/bbob-parser/test/parse.test.js +++ b/packages/bbob-parser/test/parse.test.js @@ -20,6 +20,28 @@ describe('Parser', () => { ]); }); + test('parse only allowed tags', () => { + const ast = parse('[h1 name=value]Foo [Bar] [/h1]', { + onlyAllowTags: ['h1'] + }); + + expect(ast).toBeInstanceOf(Array); + expect(ast).toEqual([ + { + tag: 'h1', + attrs: { + name: 'value', + }, + content: [ + 'Foo', + ' ', + '[Bar]', + ' ' + ], + }, + ]); + }); + test('parse tag with value param', () => { const ast = parse('[url=https://github.com/jilizart/bbob]BBob[/url]');