-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #173 Update the php syntax file to highlight attributes (javi…
…ereguiluz, wouterj) This PR was merged into the main branch. Discussion ---------- Update the php syntax file to highlight attributes Alternative to #172 (as per my suggestion). `@javiereguiluz` what do you think of this? The output is slightly different from yours, but that's how highlight.js works :) I tried my suggestion of converting the latest highlight.js syntax file, this unfortunately didn't work (there are too many BC breaks in v10). So I've copy pasted their regex and used it to what is available in our syntax file already. If we want to go this way, I can also follow up with a PR adding more support for PHP features (e.g. arrow functions). For now, I've just added a couple keywords that plainly were missing (such as trait and enum). Commits ------- 020a281 Add support for PHP attributes 9764478 Add tests for highlighting PHP attributes
- Loading branch information
Showing
4 changed files
with
233 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
tests/fixtures/expected/blocks/code-blocks/php-attributes.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<div translate="no" data-loc="54" class="notranslate codeblock codeblock-length-md codeblock-php-attributes codeblock-php"> | ||
<div class="codeblock-scroll"> | ||
<pre class="codeblock-lines">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</pre> | ||
<pre class="codeblock-code"> | ||
<code> | ||
<span class="hljs-comment">// src/SomePath/SomeClass.php</span> | ||
<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">SomePath</span>; | ||
<span class="hljs-keyword">use</span><span class="hljs-title">Symfony</span>\<span class="hljs-title">Component</span>\<span class="hljs-title">Validator</span>\<span class="hljs-title">Constraints</span> <span class="hljs-title">as</span> <span class="hljs-title">Assert</span>; | ||
<span class="hljs-class"> | ||
<span class="hljs-keyword">class</span> | ||
<span class="hljs-title">SomeClass</span> | ||
</span> | ||
{ | ||
<span class="hljs-php-attribute">#[AttributeName]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property1</span> | ||
; | ||
<span class="hljs-php-attribute">#[AttributeName()]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property2</span> | ||
; | ||
<span class="hljs-php-attribute">#[AttributeName(<span class="hljs-string">'value'</span>)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property3</span> | ||
; | ||
<span class="hljs-php-attribute">#[AttributeName(<span class="hljs-string">'value'</span>, option: <span class="hljs-string">'value'</span>)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property4</span> | ||
; | ||
<span class="hljs-php-attribute">#[AttributeName([<span class="hljs-string">'value'</span> => <span class="hljs-string">'value'</span>])]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property5</span> | ||
; | ||
<span class="hljs-php-attribute">#[AttributeName( | ||
<span class="hljs-string">'value'</span>, | ||
option: <span class="hljs-string">'value'</span> | ||
)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property6</span> | ||
; | ||
<span class="hljs-php-attribute">#[Assert\AttributeName(<span class="hljs-string">'value'</span>)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property7</span> | ||
; | ||
<span class="hljs-php-attribute">#[Assert\AttributeName( | ||
<span class="hljs-string">'value'</span>, | ||
option: <span class="hljs-string">'value'</span> | ||
)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property8</span> | ||
; | ||
<span class="hljs-php-attribute">#[Route(<span class="hljs-string">'/blog/{page<\d+>}'</span>, name: <span class="hljs-string">'blog_list'</span>)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property9</span> | ||
; | ||
<span class="hljs-php-attribute">#[Assert\GreaterThanOrEqual( | ||
value: <span class="hljs-number">18</span>, | ||
)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property10</span> | ||
; | ||
<span class="hljs-php-attribute">#[ORM\CustomIdGenerator(class: <span class="hljs-string">'doctrine.uuid_generator'</span>)]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property11</span> | ||
; | ||
<span class="hljs-php-attribute">#[Assert\AtLeastOneOf([ | ||
<span class="hljs-keyword">new</span> Assert\Regex(<span class="hljs-string">'/#/'</span>), | ||
<span class="hljs-keyword">new</span> Assert\Length(min: <span class="hljs-number">10</span>), | ||
])]</span> | ||
<span class="hljs-keyword">private</span> | ||
<span class="hljs-variable"> | ||
<span class="hljs-variable-other-marker">$</span> property12</span> | ||
; | ||
}</code></pre> | ||
</div> | ||
</div> |
56 changes: 56 additions & 0 deletions
56
tests/fixtures/source/blocks/code-blocks/php-attributes.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.. code-block:: php-attributes | ||
// src/SomePath/SomeClass.php | ||
namespace App\SomePath; | ||
use Symfony\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; | ||
} |