Completed
Push — master ( 6054a8...c11aa8 )
by Kacper
04:06
created

Html::getAliases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 8
loc 8
rs 9.4285
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Language;
17
18
use Kadet\Highlighter\Matcher\RegexMatcher;
19
use Kadet\Highlighter\Parser\CloseRule;
20
use Kadet\Highlighter\Parser\Token\LanguageToken;
21
use Kadet\Highlighter\Parser\OpenRule;
22
use Kadet\Highlighter\Parser\TokenFactory;
23
24
class Html extends Xml
25
{
26
    /**
27
     * Tokenization rules
28
     */
29
    public function setupRules()
30
    {
31
        parent::setupRules();
32
33
        $css = new Css();
34
        $js  = new JavaScript();
35
        $this->rules->addMany([
36
            'language.'.$js->getIdentifier() => [
37
                new OpenRule(new RegexMatcher('/<script.*?>()/'), [
38
                    'factory'     => new TokenFactory(LanguageToken::class),
39
                    'inject'      => $js,
40
                    'language'    => $this,
41
                    'postProcess' => true
42
                ]),
43
                new CloseRule(new RegexMatcher('/()<\/script>/'), [
44
                    'factory'  => new TokenFactory(LanguageToken::class),
45
                    'language' => $js
46
                ])
47
            ],
48
            'language.'.$css->getIdentifier() => [
49
                new OpenRule(new RegexMatcher('/<style.*?>()/'), [
50
                    'factory'     => new TokenFactory(LanguageToken::class),
51
                    'inject'      => $css,
52
                    'language'    => $this,
53
                    'postProcess' => true
54
                ]),
55
                new CloseRule(new RegexMatcher('/()<\/style>/'), [
56
                    'factory'  => new TokenFactory(LanguageToken::class),
57
                    'language' => $css
58
                ])
59
            ]
60
        ]);
61
    }
62
63
    public function getIdentifier()
64
    {
65
        return 'html';
66
    }
67
68 View Code Duplication
    public static function getMetadata()
69
    {
70
        return [
71
            'name'      => ['html'],
72
            'mime'      => ['text/html'],
73
            'extension' => ['*.html', '*.htm']
74
        ];
75
    }
76
}
77