Introduction
CometChatTextFormatter is an abstract utility class that provides the foundation for enabling rich text formatting in message composers and message bubbles. It can be extended to create custom formatter classes, allowing for specific text formatting such as mentions, hashtags, markdown, or any other custom styles within chat interfaces.
Prerequisites
Before implementing custom text formatters, ensure you have the following:- An active CometChat account and application.
- Basic understanding of JavaScript and web development.
- Knowledge of regular expressions and their implementation in JavaScript.
Text Formatter Fields
Text formatters have several fields to manage the formatting state and behavior:The
getFormattedText function of all formatters is invoked upon calling reRender, maintaining the order in which they were received as props.Custom Formatter Implementation
To create a custom formatter, extend theCometChatTextFormatter class and override the necessary methods. Ensure to handle text matching, formatting, and event listening as per your requirements.