daux.io/libs/ContentTypes/Markdown/CommonMarkConverter.php

46 lines
1.5 KiB
PHP
Raw Normal View History

2015-07-29 22:31:41 +02:00
<?php namespace Todaymade\Daux\ContentTypes\Markdown;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
2019-11-28 22:36:26 +01:00
use League\CommonMark\Ext\Table\TableExtension;
use League\CommonMark\Inline\Element as InlineElement;
use Todaymade\Daux\Config;
class CommonMarkConverter extends \League\CommonMark\CommonMarkConverter
{
/**
* Create a new commonmark converter instance.
*
* @param array $config
*/
2016-07-27 21:32:51 +02:00
public function __construct(array $config = [])
{
$environment = Environment::createCommonMarkEnvironment();
$environment->mergeConfig($config);
2015-10-21 23:26:42 +02:00
$environment->addExtension(new TableExtension());
2016-04-12 08:38:52 +02:00
// Table of Contents
$environment->addBlockParser(new TableOfContentsParser());
2016-04-12 08:38:52 +02:00
$this->extendEnvironment($environment, $config['daux']);
if (array_key_exists('processor_instance', $config['daux'])) {
$config['daux']['processor_instance']->extendCommonMarkEnvironment($environment);
}
2015-07-17 18:34:00 +02:00
$this->docParser = new DocParser($environment);
$this->htmlRenderer = new HtmlRenderer($environment);
}
2015-06-29 16:16:39 +02:00
protected function getLinkRenderer(Environment $environment)
{
2015-07-17 23:38:06 +02:00
return new LinkRenderer($environment->getConfig('daux'));
2015-06-29 16:16:39 +02:00
}
protected function extendEnvironment(Environment $environment, Config $config)
2015-06-29 16:16:39 +02:00
{
2019-11-28 22:36:26 +01:00
$environment->addInlineRenderer(InlineElement\Link::class, $this->getLinkRenderer($environment));
2015-06-29 16:16:39 +02:00
}
}