diff --git a/src/Templates/highlight.php/php.json b/src/Templates/highlight.php/php.json index 50b53fe7..3f127b81 100644 --- a/src/Templates/highlight.php/php.json +++ b/src/Templates/highlight.php/php.json @@ -8,8 +8,23 @@ "php7" ], "case_insensitive": true, - "keywords": "and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try switch continue endfor endif declare unset true false trait goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally", + "keywords": "and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try match switch continue endfor endif declare unset true false goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally", "contains": [ + { + "className": "php-attribute", + "begin": "#\\[\\s*(\\\\?[A-Z][A-Za-z0-9_\\x7f-\\xff]+|\\\\?[A-Z]+(?=[A-Z][a-z0-9_\\x7f-\\xff])){1,}(?![A-Za-z0-9])(?![$])", + "end": "]", + "contains": [ + { + "begin": "\\(", + "end": "\\)", + "keywords": "true false null new array", + "contains": { + "$ref": "#contains.10.contains.1.contains" + } + } + ] + }, { "className": "comment", "begin": "#", @@ -35,7 +50,7 @@ "begin": "<\\?(php)?|\\?>" }, { - "$ref": "#contains.0.contains.0" + "$ref": "#contains.1.contains.0" }, { "className": "doctag", @@ -54,7 +69,7 @@ "begin": "@[A-Za-z]+" }, { - "$ref": "#contains.0.contains.0" + "$ref": "#contains.1.contains.0" }, { "className": "doctag", @@ -69,7 +84,7 @@ "end": false, "contains": [ { - "$ref": "#contains.0.contains.0" + "$ref": "#contains.1.contains.0" }, { "className": "doctag", @@ -105,7 +120,7 @@ ] }, { - "$ref": "#contains.1.contains.0" + "$ref": "#contains.2.contains.0" }, { "className": "variable", @@ -137,10 +152,11 @@ "className": "params", "begin": "\\(", "end": "\\)", + "keywords": "true false null new array", "contains": [ "self", { - "$ref": "#contains.7" + "$ref": "#contains.8" }, { "className": "comment", @@ -148,7 +164,7 @@ "end": "\\*/", "contains": [ { - "$ref": "#contains.0.contains.0" + "$ref": "#contains.1.contains.0" }, { "className": "doctag", @@ -161,10 +177,10 @@ "className": "string", "contains": [ { - "$ref": "#contains.4.contains.0" + "$ref": "#contains.5.contains.0" }, { - "$ref": "#contains.1.contains.0" + "$ref": "#contains.2.contains.0" } ], "variants": [ @@ -183,7 +199,7 @@ "illegal": null, "contains": [ { - "$ref": "#contains.4.contains.0" + "$ref": "#contains.5.contains.0" } ] }, @@ -194,7 +210,7 @@ "illegal": null, "contains": [ { - "$ref": "#contains.4.contains.0" + "$ref": "#contains.5.contains.0" }, { "className": "subst", @@ -230,7 +246,7 @@ }, { "className": "class", - "beginKeywords": "class interface", + "beginKeywords": "class interface trait enum", "end": "{", "excludeEnd": true, "illegal": "[:\\(\\$\"]", @@ -239,7 +255,7 @@ "beginKeywords": "extends implements" }, { - "$ref": "#contains.9.contains.0" + "$ref": "#contains.10.contains.0" } ] }, @@ -249,7 +265,7 @@ "illegal": "[\\.']", "contains": [ { - "$ref": "#contains.9.contains.0" + "$ref": "#contains.10.contains.0" } ] }, @@ -258,7 +274,7 @@ "end": ";", "contains": [ { - "$ref": "#contains.9.contains.0" + "$ref": "#contains.10.contains.0" } ] }, @@ -266,10 +282,10 @@ "begin": "=>" }, { - "$ref": "#contains.9.contains.1.contains.3" + "$ref": "#contains.10.contains.1.contains.3" }, { - "$ref": "#contains.9.contains.1.contains.4" + "$ref": "#contains.10.contains.1.contains.4" } ] } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index cf34cde0..69b36815 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -290,6 +290,10 @@ public function parserUnitBlockProvider() 'blockName' => 'code-blocks/php-annotations', ]; + yield 'code-block-php-attributes' => [ + 'blockName' => 'code-blocks/php-attributes', + ]; + yield 'code-block-text' => [ 'blockName' => 'code-blocks/text', ]; diff --git a/tests/fixtures/expected/blocks/code-blocks/php-attributes.html b/tests/fixtures/expected/blocks/code-blocks/php-attributes.html new file mode 100644 index 00000000..541681cd --- /dev/null +++ b/tests/fixtures/expected/blocks/code-blocks/php-attributes.html @@ -0,0 +1,140 @@ +
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+
+
+ // src/SomePath/SomeClass.php
+namespace App\SomePath;
+ useSymfony\Component\Validator\Constraints as Assert;
+
+ class
+ SomeClass
+
+ {
+ #[AttributeName]
+ private
+
+ $ property1
+ ;
+ #[AttributeName()]
+ private
+
+ $ property2
+ ;
+ #[AttributeName('value')]
+ private
+
+ $ property3
+ ;
+ #[AttributeName('value', option: 'value')]
+ private
+
+ $ property4
+ ;
+ #[AttributeName(['value' => 'value'])]
+ private
+
+ $ property5
+ ;
+ #[AttributeName(
+ 'value',
+ option: 'value'
+ )]
+ private
+
+ $ property6
+ ;
+ #[Assert\AttributeName('value')]
+ private
+
+ $ property7
+ ;
+ #[Assert\AttributeName(
+ 'value',
+ option: 'value'
+ )]
+ private
+
+ $ property8
+ ;
+ #[Route('/blog/{page<\d+>}', name: 'blog_list')]
+ private
+
+ $ property9
+ ;
+ #[Assert\GreaterThanOrEqual(
+ value: 18,
+ )]
+ private
+
+ $ property10
+ ;
+ #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
+ private
+
+ $ property11
+ ;
+ #[Assert\AtLeastOneOf([
+ new Assert\Regex('/#/'),
+ new Assert\Length(min: 10),
+ ])]
+ private
+
+ $ property12
+ ;
+}
+