diff --git a/.changeset/silly-frogs-live.md b/.changeset/silly-frogs-live.md new file mode 100644 index 00000000..25328ce1 --- /dev/null +++ b/.changeset/silly-frogs-live.md @@ -0,0 +1,23 @@ +--- +"@bbob/cli": patch +"@bbob/core": patch +"@bbob/html": patch +"@bbob/parser": patch +"@bbob/plugin-helper": patch +"@bbob/preset": patch +"@bbob/preset-html5": patch +"@bbob/preset-react": patch +"@bbob/preset-vue": patch +"@bbob/react": patch +"@bbob/vue2": patch +"@bbob/vue3": patch +--- + +Now HTML5 Preset supports `color` tag + +``` +[color="red"]Red Text[/color] +``` + +Also fixes bug with case insensitive tags in `onlyAllowTags` +Now you can pas `h1` and `H1` and they will be treated as same tags diff --git a/packages/bbob-parser/src/parse.js b/packages/bbob-parser/src/parse.js index be7145a6..3d3eba10 100644 --- a/packages/bbob-parser/src/parse.js +++ b/packages/bbob-parser/src/parse.js @@ -20,6 +20,9 @@ const parse = (input, opts = {}) => { const options = opts; const openTag = options.openTag || OPEN_BRAKET; const closeTag = options.closeTag || CLOSE_BRAKET; + const onlyAllowTags = (options.onlyAllowTags || []) + .filter(Boolean) + .map((tag) => tag.toLowerCase()); let tokenizer = null; @@ -83,8 +86,8 @@ const parse = (input, opts = {}) => { * @return {boolean} */ const isAllowedTag = (value) => { - if (options.onlyAllowTags && options.onlyAllowTags.length) { - return options.onlyAllowTags.indexOf(value) >= 0; + if (onlyAllowTags.length) { + return onlyAllowTags.indexOf(value.toLowerCase()) >= 0; } return true; diff --git a/packages/bbob-parser/test/parse.test.js b/packages/bbob-parser/test/parse.test.js index cb206a21..96c5c170 100644 --- a/packages/bbob-parser/test/parse.test.js +++ b/packages/bbob-parser/test/parse.test.js @@ -141,6 +141,28 @@ describe('Parser', () => { expectOutput(ast, output); }); + + test('parse only allowed tags case insensitive', () => { + const ast = parse('[h1 name=value]Foo [Bar] [/h1]', { + onlyAllowTags: ['H1'] + }); + const output = [ + { + tag: 'h1', + attrs: { + name: 'value', + }, + content: [ + 'Foo', + ' ', + '[Bar]', + ' ' + ], + }, + ]; + + expectOutput(ast, output); + }); }) describe('contextFreeTags', () => { diff --git a/packages/bbob-preset-html5/src/defaultTags.js b/packages/bbob-preset-html5/src/defaultTags.js index cc7c943b..9931f87a 100644 --- a/packages/bbob-preset-html5/src/defaultTags.js +++ b/packages/bbob-preset-html5/src/defaultTags.js @@ -87,4 +87,5 @@ export default { return toNode(type ? 'ol' : 'ul', type ? { type } : {}, asListItems(node.content)); }, + color: (node) => toNode('span', toStyle(`color: ${getUniqAttr(node.attrs)};`), node.content), }; diff --git a/packages/bbob-preset-html5/test/index.test.js b/packages/bbob-preset-html5/test/index.test.js index 7e2d6c0b..3a30f492 100644 --- a/packages/bbob-preset-html5/test/index.test.js +++ b/packages/bbob-preset-html5/test/index.test.js @@ -77,6 +77,13 @@ describe('@bbob/preset-html5', () => { expect(parse(input)).toBe(result); }); + test('[color="red"]Red Text[/color]', () => { + const input = '[color="red"]Red Text[/color]'; + const result = 'Red Text'; + + expect(parse(input)).toBe(result); + }); + test(`[list][*]Entry 1[/list]`, () => { const input = `[list][*]Entry 1[*]Entry 2[/list]`; const result = '';