承接 daryledesilva/markdown-to-mrkdwn-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

daryledesilva/markdown-to-mrkdwn-php

最新稳定版本:v1.2.0

Composer 安装命令:

composer require daryledesilva/markdown-to-mrkdwn-php

包简介

Convert standard Markdown to Slack's mrkdwn format

README 文档

README

Packagist Version License: MIT

A lightweight, dependency-free PHP library for converting Markdown into Slack-compatible mrkdwn. It preserves code blocks, handles tables, blockquotes, lists, and more for seamless Slack messaging.

💡 What is this?

An easy-to-use, dependency-free PHP 7.4+ library that converts Markdown—headings, text formatting, lists, tables, blockquotes, and code blocks—into Slack’s mrkdwn format. Ideal for bots, integrations, or any app sending rich text to Slack.

✨ Features

- Headings (H1–H6 → `*Heading*`)
- Text formatting:
  - Bold (`**bold**``*bold*`)
  - Italic (`*italic*` or `_italic_``_italic_`)
  - Strikethrough (`~~strike~~``~strike~`)
- Lists:
  - Unordered & ordered (with nesting)
  - Task lists (`- [ ]` / `- [x]``• ☐` / `• ☑`)
- Tables (simple text tables with bold headers)
- Links & images:
  - `[text](url)``<url|text>`
  - `![alt](url)``<url>`
- Code:
  - Inline `` `code` ``
  - Fenced code blocks (``````), preserving language hint
- Blockquotes (`> quote`)
- Horizontal rules (`---`, `***`, `___``──────────`)

📋 Supported Conversions

Markdown Slack mrkdwn
# Heading *Heading*
**Bold** *Bold*
*Italic* / _Italic_ _Italic_
~~Strike~~ ~Strike~
- [ ] Task • ☐ Task
- [x] Task • ☑ Task
- Item / 1. Item • Item / 1. Item
`Inline code` `Inline code`
```lang ```lang
code code
``` ```
> Quote > Quote
--- / *** / ___ ──────────

🔌 Plugin System

You can extend the converter with custom plugins (global, line or block scope):

use DaryleDeSilva\MarkdownToMrkdwn\Converter;

$converter = new Converter();

// Global plugin (runs on full text)
$converter->registerPlugin(
    'addQuotes',
    fn(string $text) => "\"{$text}\"",
    priority: 10,
    scope: 'global'
);

// Line plugin (before standard conversion)
$converter->registerPlugin(
    'linePrefix',
    fn(string $line) => "[LINE] {$line}",
    priority: 20,
    scope: 'line',
    timing: 'before'
);

echo $converter->convert("**Hello**, world!");

Advanced plugin examples

// Function plugin: convert entire text to uppercase
$converter->registerPlugin(
    name: 'toUpper',
    converter_func: fn(string $text) => strtoupper($text),
    priority: 10,
    scope: 'line',
    timing: 'after'
);

// Regex plugin: mask email addresses
$converter->registerRegexPlugin(
    name: 'maskEmails',
    pattern: '/[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+/',
    replacement: '[EMAIL]',
    priority: 20,
    timing: 'after'
);

Error handling

If an error occurs during conversion, the original Markdown text is returned unmodified.

🛠 Requirements

  • PHP 7.4 or higher

📦 Installation

composer require daryledesilva/markdown-to-mrkdwn-php

🚀 Usage

use DaryleDeSilva\MarkdownToMrkdwn\Converter;

$converter = new Converter();
echo $converter->convert("**Hello**, [Slack](https://slack.com)!");

🧪 Testing

composer install
composer test

🔗 Testing in Slack

You can preview the converted mrkdwn in Slack’s Block Kit Builder:
https://app.slack.com/block-kit-builder/

📄 License

MIT

Inspired by the original Python package markdown_to_mrkdwn.

Created by @daryledesilva

统计信息

  • 总下载量: 6.35k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-14