Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .changeset/great-beds-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
"@bbob/parser": patch
"@bbob/types": patch
"@bbob/cli": patch
"@bbob/core": patch
"@bbob/html": 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 `React` preset `@bbob/preset-react` supports `color` tag

```js
import preset from '@bbob/preset-react'
import { render } from '@bbob/react'

const html = render('[color=#ff0000]This text should be red[/color]', preset());
```
2 changes: 2 additions & 0 deletions packages/bbob-preset-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"react"
],
"dependencies": {
"@bbob/plugin-helper": "*",
"@bbob/preset-html5": "*",
"@bbob/types": "*"
},
"peerDependencies": {
"react": "> 15.0"
},
"devDependencies": {
"@bbob/core": "*",
"react": "18.x",
"react-dom": "18.x",
"@types/react": "18.x"
Expand Down
6 changes: 6 additions & 0 deletions packages/bbob-preset-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import presetHTML5 from '@bbob/preset-html5';
import { getUniqAttr } from "@bbob/plugin-helper";

import type { PresetTagsDefinition } from '@bbob/types';

Expand Down Expand Up @@ -30,6 +31,11 @@ const presetReact = presetHTML5.extend<PresetTagsDefinition>((tags) => ({
...tags.s(...args),
...tagAttr({ textDecoration: 'line-through' }),
}),

color: (...args) => ({
...tags.color(...args),
...tagAttr({ color: String(getUniqAttr(args[0].attrs)) }),
})
}));

export default presetReact;
44 changes: 44 additions & 0 deletions packages/bbob-preset-react/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
import bbob from '@bbob/core';
import preset from '../src'

const instance = bbob(preset())

const createTag = (content: string[], style: Record<string, string>) => {
return {
"attrs": { "style": style },
"content": content,
"tag": "span",
"end": undefined,
"start": undefined,
}
}

describe('@bbob/preset-react', () => {
test('is a function', () => {
expect(preset).toBeInstanceOf(Function)
})

test('is parses [b] tag correctly', () => {
const res = instance.process('[b]bold[/b]')
const tags = [...res.tree]

expect(tags).toEqual([createTag(["bold"], { fontWeight: 'bold' })]);
});
test('is parses [i] tag correctly', () => {
const res = instance.process('[i]italic[/i]')
const tags = [...res.tree]

expect(tags).toEqual([createTag(["italic"], { fontStyle: 'italic' })]);
});
test('is parses [u] tag correctly', () => {
const res = instance.process('[u]underline[/u]')
const tags = [...res.tree]

expect(tags).toEqual([createTag(["underline"], { textDecoration: 'underline' })]);
});
test('is parses [s] tag correctly', () => {
const res = instance.process('[s]strike[/s]')
const tags = [...res.tree]

expect(tags).toEqual([createTag(["strike"], { textDecoration: 'line-through' })]);
});
test('is parses [color] tag correctly', () => {
const res = instance.process('[color=#ff0000]This text should be red[/color]')
const tags = [...res.tree]

expect(tags).toEqual([createTag(["This", " ", "text", " ", "should", " ", "be", " ", "red"], { color: '#ff0000' })]);
});
});
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading