ceus-media / markdown
Requires
- php: ^8.1
- kzykhys/ciconia: v1.0.3
- league/commonmark: 2.6.0
- league/html-to-markdown: 5.1.1
- michelf/php-markdown: 2.0.0
Requires (Dev)
- cebe/markdown: 1.2.1
- erusev/parsedown: 2.0.x-dev
- phpunit/phpunit: ^10
- picas/markdown-extended: *
Suggests
- cebe/markdown: A super fast, highly extensible markdown parser for PHP
- erusev/parsedown: Better Markdown Parser in PHP
- picas/markdown-extended: A PHP parser for the Markdown Extended syntax
README
Abstraction layer for using several Markdown converters, mostly written in PHP.
Description
Use Cases
Allows to convert Markdown to other formats (HTML only at the moment).
Within this library this process will be done using a Renderer
, since a Markdown code will be rendered into another format.
Since there are several Markdown flavors and implementations, this library is providing an abstraction layer to easily switch between flavors.
Allows to convert other formats (HTML only at the moment) to Markdown.
Within this library this process will be done using a Parser
, since other formats will be parsed to be understood as Markdown.
Aim
This library aims to provide an abstraction layer for existing implementations for convert Markdown into and from other formats. This will be done by maintaining a list of Open Source packages and providing this collection easily using composer
.
Installation
Using composer:
composer require ceus-media/markdown
Usage
After loading the libraries or using autoloading, e.G. using composer
, you can use this library the following ways.
Rendering
To render Markdown code into HTML, using the PHP implementation of Commonmark syntax:
use \CeusMedia\Markdown\Renderer\Html;
$renderer = new Html();
//$renderer->setRenderer( Html::RENDERER_PARSEDOWN );
$html = $renderer->convert( "## Heading 2" );
You can change the used renderer, for example to support tables and fenced code by switching to Parsedown
:
$renderer->setRenderer( Html::RENDERER_PARSEDOWN );
Parsing
Trying to convert HTML to Markdown can be done like this:
use \CeusMedia\Markdown\Parser\Html;
$parser = new Html();
$markdown = $parser->convert( "<h2>Heading</h2>" );
Outlook
The next versions will include other output formats (like PDF or Open Document) and input formats (like DokuWiki and other Wiki syntaxes).
Todos
Add DokuWiki Parser
- use titledk/dokuwiki-to-markdown-converter
- call
convert
on DocuwikiToMarkdownExtra