react-whatsapp-text-formatter
v0.1.0
Published
A React component to render text with Whatsapp formatting
Maintainers
Readme
Whatsapp Text Message Formatter
WhatsApp uses a markdown-like syntax in defining its formatting. This library provides an easy-to-use widget that renders WhatsApp-style message string into a formatted format that handles WhatsApp inline styles *bold* _italics_ `monospace` ~strikethrough~ and multiline codeblock (triple backtick - ```).
The default renderers for each formatting components doesn't implement any additional styling apart from its HTML tags in order not to interfere with styling, and the library does not have any dependencies apart from react.
Usage
Call the widget in your code,
import WhatsAppTextMsgFormatter from 'react-whatsapp-text-formatter'
const MyComponent = () => {
const text =
'This is an example text with *bold* and _italics_ formatting, with _some nested ~text~ inbetween_ the formatting.'
return <WhatsAppTextMsgFormatter text={text} />
}For additional flexibility (such as usage in React Native), these props can be used to further customize the component:
boldRender: renderer for*bold text*, defaults to HTMLstrongitalicsRender: renderer for_italics text_, defaults to HTMLemstrikethroughRender: renderer for~strikethrough text~, defaults to HTMLsmonoRender: renderer for`mono text`, defaults to HTMLcodemonoBlockRender: renderer for```codeblock text```, defaults to HTMLprelineBreakElement: renderer for new lines, defaults to<br/>
Attribution
This widget is authored with assistence of Gemini/AI.
