| 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 |
* Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js)
|
|
|
11 |
* - (c) John MacFarlane
|
|
|
12 |
*
|
|
|
13 |
* For the full copyright and license information, please view the LICENSE
|
|
|
14 |
* file that was distributed with this source code.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
namespace League\CommonMark\Extension\SmartPunct;
|
|
|
18 |
|
|
|
19 |
use League\CommonMark\Environment\EnvironmentBuilderInterface;
|
|
|
20 |
use League\CommonMark\Event\DocumentParsedEvent;
|
|
|
21 |
use League\CommonMark\Extension\ConfigurableExtensionInterface;
|
|
|
22 |
use League\CommonMark\Node\Block\Document;
|
|
|
23 |
use League\CommonMark\Node\Block\Paragraph;
|
|
|
24 |
use League\CommonMark\Node\Inline\Text;
|
|
|
25 |
use League\CommonMark\Renderer\Block as CoreBlockRenderer;
|
|
|
26 |
use League\CommonMark\Renderer\Inline as CoreInlineRenderer;
|
|
|
27 |
use League\Config\ConfigurationBuilderInterface;
|
|
|
28 |
use Nette\Schema\Expect;
|
|
|
29 |
|
|
|
30 |
final class SmartPunctExtension implements ConfigurableExtensionInterface
|
|
|
31 |
{
|
|
|
32 |
public function configureSchema(ConfigurationBuilderInterface $builder): void
|
|
|
33 |
{
|
|
|
34 |
$builder->addSchema('smartpunct', Expect::structure([
|
|
|
35 |
'double_quote_opener' => Expect::string(Quote::DOUBLE_QUOTE_OPENER),
|
|
|
36 |
'double_quote_closer' => Expect::string(Quote::DOUBLE_QUOTE_CLOSER),
|
|
|
37 |
'single_quote_opener' => Expect::string(Quote::SINGLE_QUOTE_OPENER),
|
|
|
38 |
'single_quote_closer' => Expect::string(Quote::SINGLE_QUOTE_CLOSER),
|
|
|
39 |
]));
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public function register(EnvironmentBuilderInterface $environment): void
|
|
|
43 |
{
|
|
|
44 |
$environment
|
|
|
45 |
->addInlineParser(new QuoteParser(), 10)
|
|
|
46 |
->addInlineParser(new DashParser(), 0)
|
|
|
47 |
->addInlineParser(new EllipsesParser(), 0)
|
|
|
48 |
|
|
|
49 |
->addDelimiterProcessor(QuoteProcessor::createDoubleQuoteProcessor(
|
|
|
50 |
$environment->getConfiguration()->get('smartpunct/double_quote_opener'),
|
|
|
51 |
$environment->getConfiguration()->get('smartpunct/double_quote_closer')
|
|
|
52 |
))
|
|
|
53 |
->addDelimiterProcessor(QuoteProcessor::createSingleQuoteProcessor(
|
|
|
54 |
$environment->getConfiguration()->get('smartpunct/single_quote_opener'),
|
|
|
55 |
$environment->getConfiguration()->get('smartpunct/single_quote_closer')
|
|
|
56 |
))
|
|
|
57 |
|
|
|
58 |
->addEventListener(DocumentParsedEvent::class, new ReplaceUnpairedQuotesListener())
|
|
|
59 |
|
|
|
60 |
->addRenderer(Document::class, new CoreBlockRenderer\DocumentRenderer(), 0)
|
|
|
61 |
->addRenderer(Paragraph::class, new CoreBlockRenderer\ParagraphRenderer(), 0)
|
|
|
62 |
->addRenderer(Text::class, new CoreInlineRenderer\TextRenderer(), 0);
|
|
|
63 |
}
|
|
|
64 |
}
|