A simple plugin for rendering markdown messages in React ChatBotify.
npm install @rcb-plugins/markdown-renderer
bash
npm install @rcb-plugins/markdown-renderer
`
2. Import the plugin:
`javascript
import MarkdownRenderer from "@rcb-plugins/markdown-renderer";
`
3. Initialize the plugin within the plugins prop of ChatBot:
`javascript
import ChatBot from "react-chatbotify";
import MarkdownRenderer from "@rcb-plugins/markdown-renderer";
const MyComponent = () => {
return (
);
};
`
4. Add the renderMarkdown attribute to the Block that requires markdown rendering:
`javascript
import ChatBot from "react-chatbotify";
import MarkdownRenderer, { MarkdownRendererBlock } from "@rcb-plugins/markdown-renderer";
const MyComponent = () => {
const flow = {
start: {
message: "### What is your age?",
renderMarkdown: ["BOT", "USER"]
} as MarkdownRendererBlock
}
return (
);
};
`
The quickstart above shows how rendering of markdown can be done for both bot and user messages within the start block. The documentation website for the React ChatBotify Core Library also contains a live markdown renderer example that uses this plugin. You may wish to check it out!
$3
Markdown Renderer is a lightweight plugin that provides the following features to your chatbot:
- Render markdown in bot chat messages
- Render markdown in user chat messages
- Optionally pass in your own custom markdown component to render markdown your way
$3
#### Plugin Configuration
The MarkdownRenderer plugin accepts a configuration object that allows you to customize its behavior and appearance. An example configuration is passed in below to initialize the plugin:
`javascript
import ChatBot from "react-chatbotify";
import MarkdownRenderer from "@rcb-plugins/markdown-renderer";
const MyComponent = () => {
const pluginConfig = {
// defaults to true, auto enable events required for plugin to work
autoConfig: true,
}
return (
)
}
`
As you may be able to tell from above, there are 5 configurable sections within the plugin configuration which are autoConfig, promptBaseColors, promptHoveredColors, textAreaHighlightColors and advancedStyles. These are described in the table below:
| Configuration Option | Type | Default Value | Description |
|------------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| autoConfig | boolean | true | Enables automatic configuration of required events for markdown rendering. Recommended to keep as true. If set to false, you need to configure events manually. |
| markdownComponent | React.ComponentType<{ children: React.ReactNode }> | null | A React component to wrap around the message's content to customize its styling, layout, or behavior. The component will receive the message's content as its children prop, so you can design it to add custom formatting, animations, or other UI enhancements. If not provided, a default wrapper from react-markdown will be used. |
#### Rendering Markdown
To render markdown in messages, add the renderMarkdown attribute to any Block that requires markdown rendering. The renderMarkdown attribute is an array that accepts senders such as "USER" and/or "BOT". An example can be seen below:
`javascript
import ChatBot from "react-chatbotify";
import MarkdownRenderer from "@rcb-plugins/markdown-renderer";
const MyComponent = () => {
const flow = {
start: {
message: "What is your age?",
renderMarkdown: ["USER", "BOT"],
},
// ... other blocks
};
return (
)
}
`
As you can see from the example above containing a start block, renderMarkdown contains both "USER" and "BOT", which means it will render markdown messages for both user and bot messages within the start` block.