Skip to main content
The Chat SDK uses mdast (Markdown Abstract Syntax Tree) as the canonical format for message formatting. This enables consistent cross-platform formatting and programmatic content manipulation.

Parsing and Stringifying

parseMarkdown

Parse markdown string into an mdast AST.
Example:

stringifyMarkdown

Stringify an mdast AST back to markdown.
Example:

Text Extraction

toPlainText

Extract plain text from an AST (strips all formatting).
Example:

markdownToPlainText

Extract plain text from a markdown string.
Example:

AST Node Builders

Helper functions for creating mdast nodes programmatically.

root

Create a root node (top-level AST container).

paragraph

Create a paragraph node.

text

Create a text node.

strong

Create a strong (bold) node.

emphasis

Create an emphasis (italic) node.

strikethrough

Create a delete (strikethrough) node.

inlineCode

Create an inline code node.

codeBlock

Create a code block node.
Create a link node.

blockquote

Create a blockquote node.
Example:

AST Manipulation

walkAst

Walk the AST and transform nodes.
The visitor function receives each node and can:
  • Return the node unchanged
  • Return a modified node
  • Return null to remove the node
Example - Remove all links:
Example - Transform code blocks:

Type Guards

Type guards for identifying node types.
Example:

Node Property Helpers

getNodeChildren

Get children from a content node that has children. Returns empty array for nodes without children.

getNodeValue

Get value from a content node that has a value property. Returns empty string for nodes without value.
Example:

Table Utilities

tableToAscii

Render an mdast table node as a padded ASCII table string.
Output format:

tableElementToAscii

Render a table from headers and string rows as a padded ASCII table.
Example:

FormatConverter

Interface for platform-specific format converters. Each adapter implements this to convert between platform format and mdast AST.

BaseFormatConverter

Base class for format converters with default implementations.
Example - Custom Converter:

Complete Example