Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | 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;
991 lars 18
use League\CommonMark\Exception\CommonMarkException;
148 lars 19
use League\CommonMark\Output\RenderedContentInterface;
20
use League\CommonMark\Parser\MarkdownParser;
21
use League\CommonMark\Parser\MarkdownParserInterface;
22
use League\CommonMark\Renderer\DocumentRendererInterface;
23
 
24
final class MarkdownToXmlConverter implements ConverterInterface
25
{
26
    /** @psalm-readonly */
27
    private MarkdownParserInterface $parser;
28
 
29
    /** @psalm-readonly */
30
    private DocumentRendererInterface $renderer;
31
 
32
    public function __construct(EnvironmentInterface $environment)
33
    {
34
        $this->parser   = new MarkdownParser($environment);
35
        $this->renderer = new XmlRenderer($environment);
36
    }
37
 
38
    /**
39
     * Converts Markdown to XML
40
     *
991 lars 41
     * @throws CommonMarkException
148 lars 42
     */
43
    public function convert(string $input): RenderedContentInterface
44
    {
45
        return $this->renderer->renderDocument($this->parser->parse($input));
46
    }
47
 
48
    /**
49
     * Converts CommonMark to HTML.
50
     *
51
     * @see MarkdownToXmlConverter::convert()
52
     *
991 lars 53
     * @throws CommonMarkException
148 lars 54
     */
55
    public function __invoke(string $input): RenderedContentInterface
56
    {
57
        return $this->convert($input);
58
    }
59
}