PHPackages                             blockshiftnetwork/chat-markdown-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. blockshiftnetwork/chat-markdown-converter

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

blockshiftnetwork/chat-markdown-converter
=========================================

Convert AI-generated Markdown to WhatsApp, Telegram, Discord and Slack compatible formats using an Intermediate Representation (IR).

v0.0.1(3mo ago)712[1 PRs](https://github.com/blockshiftnetwork/chat-markdown-converter/pulls)MITPHPPHP ^8.3CI passing

Since Feb 3Pushed 1mo agoCompare

[ Source](https://github.com/blockshiftnetwork/chat-markdown-converter)[ Packagist](https://packagist.org/packages/blockshiftnetwork/chat-markdown-converter)[ Docs](https://github.com/blockshiftnetwork/chat-markdown-converter)[ GitHub Sponsors](https://github.com/blockshiftnetwork)[ RSS](/packages/blockshiftnetwork-chat-markdown-converter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Chat Markdown Converter
=======================

[](#chat-markdown-converter)

 [![Chat Markdown Converter Card](assets/card.png)](assets/card.png)

|[![Latest Version on Packagist](https://camo.githubusercontent.com/e5b65fac0fdc43117d9cb62f241be7d76f09d3fef0713be4aa94ada35170b83d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626c6f636b73686966746e6574776f726b2f636861742d6d61726b646f776e2d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blockshiftnetwork/chat-markdown-converter)|[![Tests](https://camo.githubusercontent.com/dfdf9882f1665e950ba9acba4fa546f0fc775319c13f56643847f30961085dbd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f626c6f636b73686966746e6574776f726b2f636861742d6d61726b646f776e2d636f6e7665727465722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/blockshiftnetwork/chat-markdown-converter/actions/workflows/run-tests.yml)|[![Total Downloads](https://camo.githubusercontent.com/83c69f24606c083b188dbd35a40b569c55c8a85c10fd0e30110c906d99af3065/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626c6f636b73686966746e6574776f726b2f636861742d6d61726b646f776e2d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/blockshiftnetwork/chat-markdown-converter)

Convert AI-generated Markdown to WhatsApp, Telegram, Discord and Slack formats using an Intermediate Representation (IR). Perfect for converting LLM responses to chat-friendly formats.

This PHP library transforms ChatGPT, Claude, GPT-5, and other AI model outputs into platform-specific markup. It handles code blocks, tables, lists, links, and rich text formatting while maintaining readability across all supported platforms.

Features
--------

[](#features)

- Fluent API with chainable method calls
- Clean architecture using the Intermediate Representation pattern for extensibility
- Comprehensive test coverage with 168 passing tests (Pest)
- Platform-specific rendering optimized for each chat platform
- Smart message chunking that splits text at safe breakpoints
- Zero external dependencies, lightweight implementation

Use Cases
---------

[](#use-cases)

### AI Chatbots &amp; Virtual Assistants

[](#ai-chatbots--virtual-assistants)

Send formatted responses from OpenAI, Anthropic, or other LLM APIs directly to users via their preferred messaging platform. Ensure code blocks, tables, and lists render correctly across Telegram, WhatsApp, Discord, and Slack.

### Customer Support Automation

[](#customer-support-automation)

Automate support workflows by converting AI-generated help articles and documentation into chat-friendly formats. Preserve formatting while delivering concise, readable responses in your customers' channels.

### Developer Tools &amp; DevOps

[](#developer-tools--devops)

Integrate with CI/CD pipelines, monitoring systems, or alerting platforms to send formatted logs, error messages, or status updates to team channels. Convert Markdown reports to platform-appropriate syntax automatically.

### Content Distribution Systems

[](#content-distribution-systems)

Distribute newsletters, summaries, or generated content across multiple platforms simultaneously. Write once in Markdown and automatically convert to Telegram HTML, WhatsApp text, Discord markdown, or Slack mrkdwn.

### Educational Platforms

[](#educational-platforms)

Convert AI-generated tutorials, code examples, and learning materials into appropriate formats for students across different communication channels. Keep code snippets and syntax highlighting functional.

### Knowledge Base Integration

[](#knowledge-base-integration)

Transform documentation and wiki content from Markdown sources into chat-appropriate formats for quick distribution via messaging apps. Maintain structure and readability without manual reformatting.

### Notification Systems

[](#notification-systems)

Build notification services that send formatted alerts, summaries, and reports from AI analysis tools. Convert complex data presentations into simple, readable messages on any platform.

### Multi-Platform Content Management

[](#multi-platform-content-management)

Manage content in a single Markdown format while automatically adapting output for different chat platforms' unique formatting requirements and limitations.

### Internal Communication Tools

[](#internal-communication-tools)

Streamline internal updates, announcements, and reports by converting Markdown-based company communications to team messaging platforms with proper formatting.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require blockshiftnetwork/chat-markdown-converter
```

Why Choose This Library?
------------------------

[](#why-choose-this-library)

### Platform-Aware Formatting

[](#platform-aware-formatting)

Unlike naive Markdown-to-text converters, this library understands each platform's unique limitations and formatting rules. Telegram uses HTML tags, WhatsApp uses asterisk-based formatting, Discord and Slack have their own markdown variants - we handle all these differences automatically.

### Intermediate Representation Architecture

[](#intermediate-representation-architecture)

By parsing Markdown into an abstract IR first, we ensure consistent behavior across all platforms. This clean architecture makes it easy to add new platforms or customize rendering logic without modifying the core parser.

### Intelligent Feature Adaptation

[](#intelligent-feature-adaptation)

Automatically converts complex Markdown features to platform-compatible formats:

- Tables become bullet lists on platforms without native table support
- Code blocks are preserved with proper language tags
- Task lists adapt to each platform's checkbox syntax or emoji alternatives
- Links transform to each platform's expected format

### Production-Ready Reliability

[](#production-ready-reliability)

Comprehensive test coverage (168+ tests) ensures consistent behavior across edge cases. Handle special characters, nested formatting, mixed content types, and Unicode/emoji support with confidence.

### Developer Experience

[](#developer-experience)

Simple, intuitive API with fluent method chaining. Convert in one line with static methods or take full control with the flexible parser options. Zero learning curve for Markdown developers.

### Performance Optimized

[](#performance-optimized)

Lightweight implementation with no external dependencies. Fast parsing and rendering suitable for high-volume applications and real-time chat systems.

### AI-Response Ready

[](#ai-response-ready)

Specifically designed for LLM outputs that often include code blocks, tables, lists, and mixed formatting. Preserve the intelligence of AI responses while making them platform-appropriate.

### Open Source &amp; Extensible

[](#open-source--extensible)

MIT license, active development, and contribution-friendly architecture. Easily create custom renderers for proprietary platforms or specialized use cases.

Alternative Approaches
----------------------

[](#alternative-approaches)

### Direct Markdown-to-Text Conversion

[](#direct-markdown-to-text-conversion)

Simple converters often strip all formatting or produce unreadable output. Our platform-specific renderers preserve structure and readability while respecting each platform's formatting capabilities.

### Multiple Separate Libraries

[](#multiple-separate-libraries)

Using different libraries for each platform adds complexity and dependencies. Our unified solution provides consistent behavior across all platforms with a single, well-tested codebase.

### Manual Reformatting

[](#manual-reformatting)

Manually writing separate responses for each platform is time-consuming and error-prone. Automate with our converter and maintain content consistency while reaching users everywhere.

### Regular Expression Replacements

[](#regular-expression-replacements)

Naive regex-based converters fail with nested formatting, special characters, and complex structures. Our parser handles all edge cases correctly with proper state management.

Usage
-----

[](#usage)

### Quick Conversion

[](#quick-conversion)

```
use Blockshift\ChatMarkdown\MarkdownConverter;

// Telegram (HTML format)
$telegram = MarkdownConverter::toTelegram($markdown);

// WhatsApp (Markdown format)
$whatsapp = MarkdownConverter::toWhatsApp($markdown);

// Discord (Markdown format)
$discord = MarkdownConverter::toDiscord($markdown);

// Slack (mrkdwn format)
$slack = MarkdownConverter::toSlack($markdown);
```

### Fluent API

[](#fluent-api)

```
use Blockshift\ChatMarkdown\MarkdownConverter;
use Blockshift\ChatMarkdown\Renderers\TelegramRenderer;

$result = MarkdownConverter::parse($markdown)
    ->withOptions([
        'table_mode' => 'bullets',
        'parse_tables' => true,
    ])
    ->using(new TelegramRenderer)
    ->render();
```

### With Message Chunking

[](#with-message-chunking)

```
use Blockshift\ChatMarkdown\MarkdownConverter;

$longText = str_repeat('This is a long message. ', 500);

$chunks = MarkdownConverter::toTelegram($longText, maxLength: 4096);
// Returns array of chunks, each under 4096 characters
```

### Custom Renderer

[](#custom-renderer)

```
use Blockshift\ChatMarkdown\MarkdownConverter;
use Blockshift\ChatMarkdown\Renderers\AbstractRenderer;
use Blockshift\ChatMarkdown\Support\IntermediateRepresentation;

class CustomRenderer extends AbstractRenderer
{
    protected function renderBlock(array $block): string
    {
        return match ($block['type']) {
            'paragraph' => 'PARA: '.$block['content'],
            'code' => 'CODE: '.$block['content'],
            default => '',
        };
    }
}

$result = MarkdownConverter::parse($markdown)
    ->using(new CustomRenderer)
    ->render();
```

### Parser Options

[](#parser-options)

```
MarkdownConverter::parse($markdown)->withOptions([
    'table_mode' => 'bullets',  // 'bullets' (default) or 'off'
    'parse_tables' => true,
    'parse_code_blocks' => true,
    'parse_links' => true,
    'parse_styles' => true,
    'parse_blockquotes' => true,
    'parse_horizontal_rules' => true,
    'parse_headers' => true,
]);
```

Supported Features
------------------

[](#supported-features)

### Currently Supported

[](#currently-supported)

- Text Formatting: Bold, italic, strikethrough, inline code, highlight
- Headers: Markdown headings (# ## ###)
- Code Blocks: Code blocks with language preservation
- Task Lists: Checkbox support with emoji conversion (WhatsApp)
- Links: Markdown link formatting
- Images: Image formatting
- Lists: Numbered and bullet lists
- Blockquotes: Quote blocks
- Tables: Auto-converted to bullet lists for non-table platforms
- Message Chunking: Smart text splitting with safe breakpoints
- Unicode Support: Full UTF-8 support including emojis
- Multiple Platforms: Telegram, WhatsApp, Discord, Slack

### Platform-Specific Features

[](#platform-specific-features)

#### Telegram (HTML Mode)

[](#telegram-html-mode)

- Bold: `text`
- Italic: `text`
- Strikethrough: `text`
- Highlight: `text`
- Inline Code: `text`
- Code Blocks: `code`
- Headers: `text` (bold)
- Links: `text`
- Images: `text` (without !)
- Task Lists: `- [x]` and `- [ ]` (native support)

#### WhatsApp

[](#whatsapp)

- Bold: `*text*` (single asterisk)
- Italic: `_text_` (underscore)
- Strikethrough: `~text~` (single tilde)
- Highlight: `*text*` (bold)
- Inline Code: ``text`` (backticks)
- Code Blocks: Triple backticks
- Headers: `*text*` (bold, replaces # syntax)
- Links: `text: url` (colon separator)
- Images: `text: url` (without !)
- Task Lists: `✅ task` (completed) and `⬜ task` (pending) with emojis

#### Discord

[](#discord)

- Bold: `**text**`
- Italic: `*text*` (asterisks only, not underscores)
- Strikethrough: `~~text~~`
- Highlight: `**text**` (bold)
- Inline Code: ``text`` (backticks)
- Code Blocks: Triple backticks with language
- Headers: `**text**` (bold, replaces # syntax)
- Links: `[text](url)` (markdown format)
- Images: `[text](url)` (without !)
- Task Lists: `- [x]` and `- [ ]` (native support)

#### Slack

[](#slack)

- Bold: `*text*` (single asterisk)
- Strikethrough: `~text~` (single tilde)
- Highlight: `*text*` (bold)
- Inline Code: ``text`` (backticks)
- Code Blocks: Triple backticks with language
- Headers: `*text*` (bold, replaces # syntax)
- Links: `` (Slack format)
- Images: `` (without !)
- Task Lists: `- [x]` and `- [ ]` (native support)

### Roadmap

[](#roadmap)

**Completed**

- Platform-specific link formatting
- Table to bullet conversion
- Headers support
- Highlight syntax
- Image formatting improvements
- Nested/complex formatting

**Planned**

- Telegram MarkdownV2 support
- Additional platforms (Teams, Mattermost, Signal)

Platform Comparison
-------------------

[](#platform-comparison)

FeatureTelegramWhatsAppDiscordSlackFormat TypeHTMLTextMarkdownmrkdwnBold```*text*``**text**``*text*`Italic```_text_``*text*``_text_`Code```````````Code Blocks``Triple backticksTriple backticksTriple backticksStrikethrough```~text~``~~text~~``~text~`Links```text: url``[text](url)```TablesNot supportedNot supportedNative supportNot supportedMax Message Length4096 chars4096 chars2000 chars40000 charsTesting
-------

[](#testing)

```
composer test
```

```
composer test-coverage
```

**Current Test Status**: 168 passed, 1 skipped

Architecture
------------

[](#architecture)

The package uses an Intermediate Representation (IR) pattern:

```
Markdown → Parser → IR → Renderer → Platform-Specific Format

```

### Components

[](#components)

- Parser: Converts Markdown to IR
- HeaderParser: Detects and parses markdown headers (# ## ###)
- Parsers: Specialized parsers for code blocks, tables, links, styles, blockquotes, horizontal rules
- Renderers: Platform-specific renderers (Telegram, WhatsApp, Discord, Slack)
- Support: IR, TextChunker

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

### Development Setup

[](#development-setup)

```
# Install dependencies
composer install

# Run tests
composer test

# Format code
composer format
```

Credits
-------

[](#credits)

- [Blockshift Network](https://github.com/blockshiftnetwork)
- [All Contributors](../../contributors)

FAQ
---

[](#faq)

### Why use an Intermediate Representation instead of direct conversion?

[](#why-use-an-intermediate-representation-instead-of-direct-conversion)

The IR pattern provides better separation of concerns and extensibility. Parse once, render many times. This makes it easy to add new platforms without modifying the parser logic, and ensures consistent behavior across all renderers.

### Can I customize the rendering behavior?

[](#can-i-customize-the-rendering-behavior)

Yes! Extend the `AbstractRenderer` class to create custom renderers. The parser provides a structured IR that you can transform into any format you need.

### How does table conversion work?

[](#how-does-table-conversion-work)

For platforms without native table support (Telegram, WhatsApp, Slack), tables are automatically converted to hierarchical bullet lists, preserving the structure and readability.

### Does this library support all Markdown features?

[](#does-this-library-support-all-markdown-features)

We support the most common Markdown features used in AI responses: headings, code blocks, lists, links, images, blockquotes, horizontal rules, and text formatting. See the Supported Features section for details.

### What about message length limits?

[](#what-about-message-length-limits)

The `TextChunker` intelligently splits long messages at safe breakpoints (after sentences, paragraphs, or list items) while preserving formatting and avoiding broken markup.

### Can I use this with any PHP version?

[](#can-i-use-this-with-any-php-version)

This library requires PHP 8.3 or higher, taking advantage of modern PHP features like match expressions and readonly properties.

### Is this suitable for production use?

[](#is-this-suitable-for-production-use)

Yes! The library has comprehensive test coverage (168+ tests) and is actively maintained. It's designed for performance and reliability in production environments.

Optimization Tips
-----------------

[](#optimization-tips)

- Reuse parsers: Create a single parser instance and reuse it for multiple conversions
- Batch operations: Process multiple messages in a single request when possible
- Cache rendered output: Store converted results for frequently used content
- Disable unnecessary features: Use parser options to skip parsing for content that doesn't need certain features

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance87

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

96d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/13807d18c3251d3f5b8eebf5341dc03d273dbf17ddc159203ee76333133f1ec1?d=identicon)[alexr1712](/maintainers/alexr1712)

---

Top Contributors

[![AlexR1712](https://avatars.githubusercontent.com/u/8460736?v=4)](https://github.com/AlexR1712 "AlexR1712 (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

aiai-agentsanthropicchatgptgeminipackagephpslacktelegramwhatsappBlockshiftNetworkchat-markdown-converter

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/blockshiftnetwork-chat-markdown-converter/health.svg)

```
[![Health](https://phpackages.com/badges/blockshiftnetwork-chat-markdown-converter/health.svg)](https://phpackages.com/packages/blockshiftnetwork-chat-markdown-converter)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M227](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
