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;
15
 
16
use League\CommonMark\Environment\EnvironmentInterface;
17
use League\CommonMark\Output\RenderedContentInterface;
18
use League\CommonMark\Parser\MarkdownParser;
19
use League\CommonMark\Parser\MarkdownParserInterface;
20
use League\CommonMark\Renderer\HtmlRenderer;
21
use League\CommonMark\Renderer\MarkdownRendererInterface;
22
 
23
class MarkdownConverter implements ConverterInterface, MarkdownConverterInterface
24
{
25
    /** @psalm-readonly */
26
    protected EnvironmentInterface $environment;
27
 
28
    /** @psalm-readonly */
29
    protected MarkdownParserInterface $markdownParser;
30
 
31
    /** @psalm-readonly */
32
    protected MarkdownRendererInterface $htmlRenderer;
33
 
34
    public function __construct(EnvironmentInterface $environment)
35
    {
36
        $this->environment = $environment;
37
 
38
        $this->markdownParser = new MarkdownParser($environment);
39
        $this->htmlRenderer   = new HtmlRenderer($environment);
40
    }
41
 
42
    public function getEnvironment(): EnvironmentInterface
43
    {
44
        return $this->environment;
45
    }
46
 
47
    /**
48
     * Converts Markdown to HTML.
49
     *
50
     * @param string $input The Markdown to convert
51
     *
52
     * @return RenderedContentInterface Rendered HTML
53
     *
54
     * @throws \RuntimeException
55
     */
56
    public function convert(string $input): RenderedContentInterface
57
    {
58
        $documentAST = $this->markdownParser->parse($input);
59
 
60
        return $this->htmlRenderer->renderDocument($documentAST);
61
    }
62
 
63
    /**
64
     * Converts Markdown to HTML.
65
     *
66
     * @deprecated since 2.2; use {@link convert()} instead
67
     *
68
     * @param string $markdown The Markdown to convert
69
     *
70
     * @return RenderedContentInterface Rendered HTML
71
     *
72
     * @throws \RuntimeException
73
     */
74
    public function convertToHtml(string $markdown): RenderedContentInterface
75
    {
76
        \trigger_deprecation('league/commonmark', '2.2.0', 'Calling "convertToHtml()" on a %s class is deprecated, use "convert()" instead.', self::class);
77
 
78
        return $this->convert($markdown);
79
    }
80
 
81
    /**
82
     * Converts CommonMark to HTML.
83
     *
84
     * @see MarkdownConverter::convert()
85
     *
86
     * @throws \RuntimeException
87
     */
88
    public function __invoke(string $markdown): RenderedContentInterface
89
    {
90
        return $this->convert($markdown);
91
    }
92
}