forked from bcremer/sculpin-commonmark-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonMarkConverter.php
42 lines (36 loc) · 1008 Bytes
/
CommonMarkConverter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Bcremer\Sculpin\Bundle\CommonMarkBundle;
use League\CommonMark\DocParser;
use League\CommonMark\HtmlRendererInterface;
use Sculpin\Core\Converter\ConverterContextInterface;
use Sculpin\Core\Converter\ConverterInterface;
class CommonMarkConverter implements ConverterInterface
{
/**
* @var DocParser
*/
private $parser;
/**
* @var HtmlRendererInterface
*/
private $renderer;
/**
* @param DocParser $parser
* @param HtmlRendererInterface $renderer
*/
public function __construct(DocParser $parser, HtmlRendererInterface $renderer)
{
$this->parser = $parser;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public function convert(ConverterContextInterface $converterContext)
{
$documentAST = $this->parser->parse($converterContext->content());
$converterContext->setContent(
$this->renderer->renderBlock($documentAST)
);
}
}