0.1.0 • Published 6 months ago
react-whatsapp-text-formatter v0.1.0
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 HTMLstrong
italicsRender
: renderer for_italics text_
, defaults to HTMLem
strikethroughRender
: renderer for~strikethrough text~
, defaults to HTMLs
monoRender
: renderer for`mono text`
, defaults to HTMLcode
monoBlockRender
: renderer for```codeblock text```
, defaults to HTMLpre
lineBreakElement
: renderer for new lines, defaults to<br/>
Attribution
This widget is authored with assistence of Gemini/AI.
0.1.0
6 months ago