Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <colinodell@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
 
14
namespace League\CommonMark\Xml;
15
 
16
use League\CommonMark\ConverterInterface;
17
use League\CommonMark\Environment\EnvironmentInterface;
18
use League\CommonMark\Output\RenderedContentInterface;
19
use League\CommonMark\Parser\MarkdownParser;
20
use League\CommonMark\Parser\MarkdownParserInterface;
21
use League\CommonMark\Renderer\DocumentRendererInterface;
22
 
23
final class MarkdownToXmlConverter implements ConverterInterface
24
{
25
    /** @psalm-readonly */
26
    private MarkdownParserInterface $parser;
27
 
28
    /** @psalm-readonly */
29
    private DocumentRendererInterface $renderer;
30
 
31
    public function __construct(EnvironmentInterface $environment)
32
    {
33
        $this->parser   = new MarkdownParser($environment);
34
        $this->renderer = new XmlRenderer($environment);
35
    }
36
 
37
    /**
38
     * Converts Markdown to XML
39
     *
40
     * @throws \RuntimeException
41
     */
42
    public function convert(string $input): RenderedContentInterface
43
    {
44
        return $this->renderer->renderDocument($this->parser->parse($input));
45
    }
46
 
47
    /**
48
     * Converts CommonMark to HTML.
49
     *
50
     * @see MarkdownToXmlConverter::convert()
51
     *
52
     * @throws \RuntimeException
53
     */
54
    public function __invoke(string $input): RenderedContentInterface
55
    {
56
        return $this->convert($input);
57
    }
58
}