![](https://github.com/storyblok/richtext/raw/HEAD/.github/repo-banner.png)
@storyblok/richtext
A custom resolver for the Storyblok Richtext field.
🚀 Usage
If you are first-time user of the Storyblok, read the Getting Started guide to get a project ready in less than 5 minutes.
Installation
npm install @storyblok/richtext
or yarn
:
yarn add @storyblok/richtext
or pnpm
:
pnpm add @storyblok/richtext
Basic
import { RichTextResolver } from '@storyblok/richtext'
const { render } = RichTextResolver()
const html = render(doc)
document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<div>
${html}
</div>
`
Overwrite resolvers
To overwrite an existing resolver, you can pass a property called resolvers available on the RichTextResolver
options.
import { MarkTypes, RichTextResolver } from '@storyblok/richtext'
const html = RichTextResolver({
resolvers: {
[MarkTypes.LINK]: (node) => {
return `<button href="${node.attrs?.href}" target="${node.attrs?.target}">${node.children}</button>`
},
},
}).render(doc)
Typing with Generics
It is possible to ensure correct typing support in a framework-agnostic way by using Typescript Generics
- Vanilla
string
- Vue
VNode
- React
React.ReactElement
This way the @storyblok/richtext
is ignorant of framework specific types, avoiding having to import them and having vue
react
etc as dependencies.
const options: SbRichtextOptions<string> = {
resolvers: {
[MarkTypes.LINK]: (node: Node<string>) => {
return `<button href="${node.attrs?.href}" target="${node.attrs?.target}">${node.children}</button>`
},
},
}
const html = RichTextResolver<string>(options).render(doc)
const options: SbRichtextOptions<VNode> = {
renderFn: h,
}
const root = () => RichTextResolver<VNode>(options).render(doc)
Setup
pnpm install
This command will install the dependencies for the workspace, including the dependencies for the playgrounds under /playground
and different framework wrappers /packages
Run Playground
To run the vanilla Typescript playground:
pnpm run playground
Vue playground:
pnpm run playground:vue
React playground:
pnpm run playground:react
Alternatively you can run the following command to run all the playgrounds:
pnpm run playground:all
Build
To build the core package:
pnpm run build
To build the wrappers under /packages
:
pnpm run build:packages
Lint
To lint the core package:
pnpm run lint
To lint the wrappers under /packages
:
pnpm run lint:packages
Alternatively, you can run the following command to fix the linting issues:
pnpm run lint:fix
Test
To run the tests for the core package:
pnpm run test
🔗 Related Links
- Storyblok Technology Hub: Storyblok integrates with every framework so that you are free to choose the best fit for your project. We prepared the technology hub so that you can find selected beginner tutorials, videos, boilerplates, and even cheatsheets all in one place.
- Getting Started: Get a project ready in less than 5 minutes.
- Storyblok CLI: A simple CLI for scaffolding Storyblok projects and fieldtypes.
ℹ️ More Resources
Support
Contributing
Please see our contributing guidelines and our code of conduct.
This project use semantic-release for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check this question about it in semantic-release FAQ