PHPackages                             phpnomad/league-markdown-integration - 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. phpnomad/league-markdown-integration

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

phpnomad/league-markdown-integration
====================================

Implements PHPNomad Markdown implementations using League libraries

1.0.1(3w ago)03.1k1MITPHP

Since Jun 6Pushed 3w agoCompare

[ Source](https://github.com/phpnomad/league-markdown-integration)[ Packagist](https://packagist.org/packages/phpnomad/league-markdown-integration)[ RSS](/packages/phpnomad-league-markdown-integration/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (6)Versions (3)Used By (1)

phpnomad/league-markdown-integration
====================================

[](#phpnomadleague-markdown-integration)

[![Latest Version](https://camo.githubusercontent.com/3393bfe162659171bb3328257dfe265b7a9790804cddf25e10affff8c4057957/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f6c65616775652d6d61726b646f776e2d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/league-markdown-integration)[![Total Downloads](https://camo.githubusercontent.com/2ddd6a6ed9fbcf87073f82d0f880869eb95be025413d776b07e6c878fab7aeac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f6c65616775652d6d61726b646f776e2d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/league-markdown-integration)[![PHP Version](https://camo.githubusercontent.com/a444b75a005009697263c81b773183244fce62fab066d9efa015132fb8ce704f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f6c65616775652d6d61726b646f776e2d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/league-markdown-integration)[![License](https://camo.githubusercontent.com/72dadda8b23791b5a73cd4f14ba0b543bbfc845ec265b22c185c693635ab18c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f6c65616775652d6d61726b646f776e2d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/league-markdown-integration)

Integrates [League CommonMark](https://commonmark.thephpleague.com) and [league/html-to-markdown](https://github.com/thephpleague/html-to-markdown) with PHPNomad's `phpnomad/markdown` abstraction. It ships a single strategy class that satisfies both conversion contracts so your application can bind the interfaces in its container and stay unaware of the underlying library.

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

[](#installation)

```
composer require phpnomad/league-markdown-integration
```

Composer pulls in `phpnomad/markdown` and both League libraries as transitive dependencies.

What This Provides
------------------

[](#what-this-provides)

`PHPNomad\LeagueMarkdownIntegration\Strategies\MarkdownConversionStrategy` is the only class in the package. It does three things.

- Implements both `CanConvertMarkdownToHtml` and `CanConvertHtmlToMarkdown` from `phpnomad/markdown`, so one binding covers both directions.
- `toHtml()` delegates to `League\CommonMark\CommonMarkConverter` and rethrows `CommonMarkException` as `ConvertToHtmlException`.
- `toMarkdown()` delegates to `League\HTMLToMarkdown\HtmlConverter` and rethrows `InvalidArgumentException` and `RuntimeException` as `ConvertToMarkdownException`.

Both League converters are constructed with their defaults. If you need custom CommonMark extensions or a non-default HTML-to-markdown configuration, write your own strategy class implementing the same interfaces and bind that instead.

Requirements
------------

[](#requirements)

- `phpnomad/markdown` for the conversion interfaces and exception hierarchy.
- `league/commonmark ^2.7` and `league/html-to-markdown ^5.1` for the actual conversion work. Both come in through Composer automatically.

Usage
-----

[](#usage)

Register the strategy against both interfaces in a PHPNomad initializer so anything type-hinting `CanConvertMarkdownToHtml` or `CanConvertHtmlToMarkdown` resolves to the same implementation.

```
