Skip to main content
Text formatters detect patterns in message text and transform them into formatted HTML for display in bubbles. They run as a pipeline — each formatter receives the output of the previous one, sorted by priority (lower number = runs first). The Text plugin provides three built-in formatters, and you can add your own.

Built-in Formatters

FormatterPriorityDetectsOutput
CometChatMarkdownFormatter10**bold**, _italic_, `code`, > quote, lists, linksHTML tags (<b>, <i>, <code>, etc.)
CometChatMentionsFormatter50<@uid:xxx> tokensStyled @DisplayName chips
CometChatUrlFormatter100https://..., www.Clickable <a> links

The Formatter Interface

All formatters extend the abstract CometChatTextFormatter class:

Creating a Custom Formatter

Here’s a hashtag formatter that wraps #word patterns in a styled span:
src/formatters/HashtagFormatter.ts

Registering Custom Formatters

Custom formatters are registered by creating a custom text plugin that provides them:
src/plugins/CustomTextPlugin.ts
Then pass it in your provider’s plugins prop:
Since user plugins are prepended before the defaults in the registry, your custom text plugin takes precedence over the built-in one (first match wins)

Formatter Details

CometChatMarkdownFormatter

Converts markdown syntax to HTML. Runs first (priority 10) so subsequent formatters operate on HTML output.
  • **bold**<b>bold</b>
  • _italic_<i>italic</i>
  • __underline__ or ++underline++<u>underline</u>
  • ~~strikethrough~~<s>strikethrough</s>
  • `inline code`<code>inline code</code>
  • ```code block```<pre><code>code block</code></pre>
  • > blockquote<blockquote>blockquote</blockquote>
  • [text](url)<a href="url">text</a>
  • 1. item → ordered list; • item / - item → unordered list

CometChatMentionsFormatter

Resolves SDK mention tokens (<@uid:xxx> and <@all:label>) into styled mention chips. Requires the mentioned-users list from the message to resolve UIDs to display names.

CometChatUrlFormatter

Detects bare URLs (https://... and www.) and wraps them in clickable <a> tags with target="_blank" and rel="noopener noreferrer". Protects existing markdown links and <a> tags from double-processing.

Tips

  • Priority matters — markdown must run before mentions/URLs so it doesn’t break HTML tags
  • Protect code blocks — formatters should skip content inside <code> and <pre> tags
  • Keep it fast — formatters run on every text message render; avoid expensive operations
  • Use shouldFormat() — override to skip formatting for specific messages
  • Store metadata — use this.metadata to expose extracted data (URLs, hashtags, mentions) to consumers