ceus-media / markdown
Requires
- php: >=7.2
- cebe/markdown: ~1.1.1
- erusev/parsedown: ^1.7
- kzykhys/ciconia: ~1.0.0
- league/commonmark: ^1
- league/html-to-markdown: ^4
- michelf/php-markdown: ^1.7
- picas/markdown-extended: dev-master
This package is auto-updated.
Last update: 2024-11-04 00:33:08 UTC
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 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 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