mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
fix(293): [color] tag doesn't work in React (#294)
* fix: react color preset * chore: changeset great-beds-shop.md * fix: tests * chore: text fixes
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
"react"
|
||||
],
|
||||
"dependencies": {
|
||||
"@bbob/plugin-helper": "*",
|
||||
"@bbob/preset-html5": "*",
|
||||
"@bbob/types": "*"
|
||||
},
|
||||
@@ -15,6 +16,7 @@
|
||||
"react": "> 15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bbob/core": "*",
|
||||
"react": "18.x",
|
||||
"react-dom": "18.x",
|
||||
"@types/react": "18.x"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import presetHTML5 from '@bbob/preset-html5';
|
||||
import { getUniqAttr } from "@bbob/plugin-helper";
|
||||
|
||||
import type { PresetTagsDefinition } from '@bbob/types';
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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' })]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user