forked from kaoken/markdown-it-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParserCore.php
70 lines (62 loc) · 1.79 KB
/
ParserCore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/** internal
* class Core
*
* Top-level rules executor. Glues block/inline parsers and does intermediate
* transformations.
**/
namespace Kaoken\MarkdownIt;
use Exception;
use Kaoken\MarkdownIt\Ruler;
use \Kaoken\MarkdownIt\RulesCore\StateCore;
class ParserCore
{
protected array $_rules = [
'normalize' => \Kaoken\MarkdownIt\RulesCore\Normalize::class,
'block' => \Kaoken\MarkdownIt\RulesCore\Block::class,
'inline' => \Kaoken\MarkdownIt\RulesCore\Inline::class,
'linkify' => \Kaoken\MarkdownIt\RulesCore\Linkify::class,
'replacements' => \Kaoken\MarkdownIt\RulesCore\ReplaceMents::class,
'smartquotes' => \Kaoken\MarkdownIt\RulesCore\SmartQuotes::class,
// `text_join` finds `text_special` tokens (for escape sequences)
// and joins them with the rest of the text
'text_join' => \Kaoken\MarkdownIt\RulesCore\TextJoin::class
];
/**
* [[Ruler]] instance. Keep configuration of core rules.
* @var Ruler
*/
public Ruler $ruler;
/**
* new Core()
*
* @throws Exception
*/
public function __construct()
{
$this->ruler = new Ruler();
foreach ($this->_rules as $key => &$val) {
$this->ruler->push($key, [new $val(), 'set']);
}
}
/**
* @param string $src
* @param MarkdownIt $md
* @param null $env
* @return StateCore
*/
public function createState(string $src, MarkdownIt $md, $env=null): StateCore
{
return new StateCore($src, $md, $env);
}
/**
* @param object $state
*/
public function process(object $state)
{
$rules = $this->ruler->getRules('');
foreach ( $rules as &$rule) {
$rule($state);
}
}
}