ceus-media/markdown

0.1.2 2021-01-31 06:55 UTC

This package is auto-updated.

Last update: 2022-01-06 01:03:17 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