PHP code example of daryledesilva / markdown-to-mrkdwn-php

1. Go to this page and download the library: Download daryledesilva/markdown-to-mrkdwn-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

daryledesilva / markdown-to-mrkdwn-php example snippets


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!");

// 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'
);

use DaryleDeSilva\MarkdownToMrkdwn\Converter;

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