PHPackages                             mariohuq/md-html-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mariohuq/md-html-converter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mariohuq/md-html-converter
==========================

PHP Inline Markdown ↔ HTML converter

01PHP

Since Jun 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mariohuq/md-html-converter)[ Packagist](https://packagist.org/packages/mariohuq/md-html-converter)[ RSS](/packages/mariohuq-md-html-converter/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Inline Markdown → HTML converter
====================================

[](#php-inline-markdown--html-converter)

This converter based on [PHP PEG Parser](https://github.com/wouterj/peg) by wouterj.

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

[](#installation)

Install `md-html-converter` using [Composer](https://getcomposer.org/download/):

```
$ composer require mariohuq/md-html-converter:dev-main
```

Usage
-----

[](#usage)

Use `MarkdownGrammar#parse()` to parse input strings using this grammar. The return value is *the part* of the string that matched or `null` when there is no match:

```
use Mariohuq\MarkdownGrammar;

$grammar = new MarkdownGrammar();

echo $grammar->parse('text1 **bold1 __italic1__** ~~`code1`~~');
// text1 bold1 italic1 code1
```

Try converter in action
-----------------------

[](#try-converter-in-action)

You can try this converter on test page, located at [`/web/index.php`](web/index.php).

Start local web server with root at this directory and port 8080 (or any other) and open localhost:8080.

Markdown syntax supported
-------------------------

[](#markdown-syntax-supported)

This converter supports Telegram's Markdown for users as such

```
**bold**
__italics__
~~strike~~
`code`
[link title](https://www.example.com)

```

Bold, italics and strike can be nested in various ways, link title can be bold, italic, struck or code. All syntax within backticks is ignored. Escaping characters is not supported yet.

PEG Grammmar
------------

[](#peg-grammmar)

```
BLOCK_OR_LINK_S
