|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tempest\Highlight\Languages\Html\Patterns; |
| 6 | + |
| 7 | +use Tempest\Highlight\IsPattern; |
| 8 | +use Tempest\Highlight\Pattern; |
| 9 | +use Tempest\Highlight\PatternTest; |
| 10 | +use Tempest\Highlight\Tokens\TokenTypeEnum; |
| 11 | + |
| 12 | +#[PatternTest(input: '<x-hello attr="">', output: 'attr')] |
| 13 | +#[PatternTest(input: '<a href="">', output: 'href')] |
| 14 | +#[PatternTest(input: '<a data-type="">', output: 'data-type')] |
| 15 | +#[PatternTest(input: '<x-post :foreach="$this->posts as $post">', output: ':foreach')] |
| 16 | +#[PatternTest(input: '<xsl xmlns:xsl="http">', output: 'xmlns:xsl')] |
| 17 | +#[PatternTest(input: "<item attr='value'>", output: 'attr')] |
| 18 | +#[PatternTest(input: "<item simple=value>", output: 'simple')] |
| 19 | +#[PatternTest(input: "<item with-hyphen=simple-with-hyphen>", output: 'with-hyphen')] |
| 20 | +#[PatternTest(input: "<div class=''><span style=''></span></div>", output: ['class', 'style'])] |
| 21 | +#[PatternTest(input: '<item |
| 22 | + id = |
| 23 | + "multiline-attr">', output: 'id')] |
| 24 | +#[PatternTest(input: '<item |
| 25 | + type |
| 26 | + = |
| 27 | + "multiline-attr">', output: 'type')] |
| 28 | +#[PatternTest(input: '<item |
| 29 | + a |
| 30 | + ="multiline-attr">', output: 'a')] |
| 31 | +#[PatternTest(input: '<p></p>', output: null)] |
| 32 | +# Not yet implemented |
| 33 | +# #[PatternTest(input: "<script defer>", output: 'defer')] |
| 34 | +final readonly class HtmlAttributePattern implements Pattern |
| 35 | +{ |
| 36 | + use IsPattern; |
| 37 | + |
| 38 | + public function getPattern(): string |
| 39 | + { |
| 40 | + return '(?<match>[\w\-:]+)\s*=\s*(?:["\']|[\w-]+)'; |
| 41 | + } |
| 42 | + |
| 43 | + public function getTokenType(): TokenTypeEnum |
| 44 | + { |
| 45 | + return TokenTypeEnum::PROPERTY; |
| 46 | + } |
| 47 | +} |
0 commit comments