1<?php
2
3/*
4 * This file is part of the league/commonmark package.
5 *
6 * (c) Colin O'Dell <colinodell@gmail.com>
7 *
8 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js)
9 *  - (c) John MacFarlane
10 *
11 * For the full copyright and license information, please view the LICENSE
12 * file that was distributed with this source code.
13 */
14
15namespace League\CommonMark\Extension\SmartPunct;
16
17use League\CommonMark\Block\Element\Document;
18use League\CommonMark\Block\Element\Paragraph;
19use League\CommonMark\Block\Renderer as CoreBlockRenderer;
20use League\CommonMark\ConfigurableEnvironmentInterface;
21use League\CommonMark\Extension\ExtensionInterface;
22use League\CommonMark\Inline\Element\Text;
23use League\CommonMark\Inline\Renderer as CoreInlineRenderer;
24
25final class SmartPunctExtension implements ExtensionInterface
26{
27    public function register(ConfigurableEnvironmentInterface $environment)
28    {
29        $environment
30            ->addInlineParser(new QuoteParser(), 10)
31            ->addInlineParser(new PunctuationParser(), 0)
32
33            ->addDelimiterProcessor(QuoteProcessor::createDoubleQuoteProcessor(
34                $environment->getConfig('smartpunct/double_quote_opener', Quote::DOUBLE_QUOTE_OPENER),
35                $environment->getConfig('smartpunct/double_quote_closer', Quote::DOUBLE_QUOTE_CLOSER)
36            ))
37            ->addDelimiterProcessor(QuoteProcessor::createSingleQuoteProcessor(
38                $environment->getConfig('smartpunct/single_quote_opener', Quote::SINGLE_QUOTE_OPENER),
39                $environment->getConfig('smartpunct/single_quote_closer', Quote::SINGLE_QUOTE_CLOSER)
40            ))
41
42            ->addBlockRenderer(Document::class, new CoreBlockRenderer\DocumentRenderer(), 0)
43            ->addBlockRenderer(Paragraph::class, new CoreBlockRenderer\ParagraphRenderer(), 0)
44
45            ->addInlineRenderer(Quote::class, new QuoteRenderer(), 100)
46            ->addInlineRenderer(Text::class, new CoreInlineRenderer\TextRenderer(), 0)
47        ;
48    }
49}
50