Skip to main content

Overview

CometChatMarkdownRenderer converts a markdown string to sanitized HTML using a custom TypeScript parser — no third-party markdown library is required. It is used internally by CometChatAIAssistantMessageBubble (completed messages) and CometChatStreamMessageBubble (live streaming), but can be used standalone anywhere you need markdown rendering. Key capabilities:
  • Zero dependencies — custom CometChatMarkdownParser class; no marked, remark, or highlight.js
  • Streaming-safe — when streaming is true, incomplete syntax at the end of the text is rendered as plain text rather than dropped or throwing an error
  • XSS sanitization — all raw HTML in the input is escaped before markdown rules are applied; only the supported markdown constructs produce HTML elements
  • Code block copy — each fenced code block gets a copy button; state is tracked per-block as an independent WritableSignal<boolean>
  • Image click — clicking a rendered image emits imageClick with the image URL
  • Extensible parserCometChatMarkdownParser is exported from the public API so you can extend it with custom node types

Supported Markdown Constructs

Basic Usage

Inputs

Outputs

Streaming Mode

When rendering a live AI response, set streaming to true. The parser will render any incomplete markdown at the end of the string as plain text rather than dropping it or throwing an error. This prevents visual glitches as tokens arrive incrementally.

Image Click Handling

Wire imageClick to open the full-screen viewer:

Extending the Parser

CometChatMarkdownParser is exported from the public API. Extend it to add custom node types — for example, a chart block or a video embed — without modifying the renderer component.
Then provide your custom parser to the renderer by subclassing CometChatMarkdownRenderer or by rendering the HTML yourself using the parser directly:

BEM Class Reference

All rendered elements carry BEM class names prefixed with cometchat-markdown-renderer. Use these to apply custom styles:

Example: Custom Code Block Styling

Localization Keys

Override via CometChatLocalize.updateKeys():