markdown-to-slack
v1.5.2
Published
Convert Markdown to Slack Block Kit JSON
Downloads
1,195
Maintainers
Readme
markdown-to-slack
Convert Markdown to Slack Block Kit JSON format.
Usage
CLI
Install and use as command-line tool.
npm install -g markdown-to-slack
# Using echo pipe
echo "# Hello World" | md2s
# Full command name also available
echo "# Hello World" | markdown-to-slackLibrary
Use as TypeScript/JavaScript library.
import { MarkdownToSlack } from './source/module'
const markdown = `
# Title
**Bold** and *italic* text
- Item 1
- Item 2
`
const messages = MarkdownToSlack.convert(markdown)
console.log(JSON.stringify(messages, null, 2))API
MarkdownToSlack.convert(markdown: string): SlackMessage[]- Returns array of Slack messages (split by 50-block limit or tables)
Mapping Table
| Markdown | Slack Block Kit | Notes |
|----------|----------------|-------|
| # Heading 1 | Header Block (auto-split if >150 chars) | H1 with visual separation |
| ## Heading 2 | Header Block (auto-split if >150 chars) | H2 with divider |
| ### Heading 3 | Header Block (auto-split if >150 chars) | H3 as header |
| #### Heading 4-6 | Section (bold) | H4-H6 as bold text |
| **bold** / __bold__ | Rich Text (bold) | Bold formatting |
| *italic* / _italic_ | Rich Text (italic) | Italic formatting |
| ***bold+italic*** | Rich Text (bold+italic) | Combined formatting |
| *_text_* | Rich Text (bold+italic) | Alternative combined format |
| ~~strikethrough~~ | Rich Text (strike) | Double tilde strikethrough |
| ~strikethrough~ | Rich Text (strike) | Single tilde strikethrough |
| `code` | Rich Text (code) | Inline code |
| [text](url) | Rich Text Link | Hyperlink |
| - item / * item / + item | Rich Text List (bullet) | Unordered list |
| 1. item | Rich Text List (ordered) | Ordered list |
| - nested | Rich Text List (indent) | Nested lists (multi-level) |
| 5. item | Rich Text List (offset) | Custom start number |
| - [ ] task / - [x] task | Rich Text List | Task checkboxes (stripped) |
| ```code``` | Rich Text Preformatted | Code block (no language specified) |
| ```lang``` | Context Block + Rich Text Preformatted | Code block with language context |
| > quote | Rich Text Quote | Blockquote |
| --- / *** / ___ | Divider Block | Horizontal rule |
| Markdown table | Context Block + Table Block | Context shows row count, tables (max 1 per message) |
| Table cells with markdown | Rich Text Cell | Inline formatting in cells |
| <br> / <br/> | \n | Line break (converted before parsing) |
| :emoji: | Emoji | Emoji shortcode |
|  / <img> | Image Block | Alt text as title, Slack file URL supported |
| <details><summary> | Divider section | Collapsible section with dividers |
Messages are automatically split due to Slack limitations.
- Maximum 50 blocks per message
- Maximum 1 table per message
- Tables are isolated into separate messages
- Header text exceeding 150 characters is automatically split into multiple headers
