Skip to content

Commit 4cac105

Browse files
committed
bug #180 Highlight nested PHP comments (javiereguiluz, wouterj)
This PR was merged into the main branch. Discussion ---------- Highlight nested PHP comments Related to symfony/symfony-docs#20121 This PR adds a failing test that shows the issue. This is the output change that would make test pass: ```diff - ), [ // wait - <span class="hljs-number">5</span> - seconds before processing + ), [ + <span class="hljs-comment">// wait 5 seconds before processing</span> ``` Commits ------- af7ee47 Allow one line comments in argument list 8f09af6 Highlight nested PHP comments
2 parents b5a4aed + af7ee47 commit 4cac105

File tree

4 files changed

+99
-14
lines changed

4 files changed

+99
-14
lines changed

src/Templates/highlight.php/php.json

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,15 @@
204204
"_": "variable"
205205
},
206206
{
207-
"$ref": "#contains.10.contains.3.contains.2",
207+
"$ref": "#contains.3",
208+
"_": "comment"
209+
},
210+
{
211+
"$ref": "#contains.4",
212+
"_": "comment"
213+
},
214+
{
215+
"$ref": "#contains.5",
208216
"_": "comment"
209217
},
210218
{
@@ -258,19 +266,8 @@
258266
"_": "variable"
259267
},
260268
{
261-
"className": "comment",
262-
"begin": "/\\*",
263-
"end": "\\*/",
264-
"contains": [
265-
{
266-
"$ref": "#contains.2.contains.0"
267-
},
268-
{
269-
"className": "doctag",
270-
"begin": "(?:TODO|FIXME|NOTE|BUG|XXX):",
271-
"relevance": 0
272-
}
273-
]
269+
"$ref": "#contains.5",
270+
"_": "comment"
274271
},
275272
{
276273
"className": "string",

tests/IntegrationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ public function parserUnitBlockProvider()
298298
'blockName' => 'code-blocks/php-attributes',
299299
];
300300

301+
yield 'code-block-php-nested-comments' => [
302+
'blockName' => 'code-blocks/php-nested-comments',
303+
];
304+
301305
yield 'code-block-text' => [
302306
'blockName' => 'code-blocks/text',
303307
];
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<p>You can do that by adding a "stamp" to your message:</p>
2+
<div translate="no" data-loc="10" class="notranslate codeblock codeblock-length-md codeblock-php">
3+
<div class="codeblock-scroll">
4+
<pre class="codeblock-lines">1
5+
2
6+
3
7+
4
8+
5
9+
6
10+
7
11+
8
12+
9
13+
10</pre>
14+
<pre class="codeblock-code">
15+
<code>
16+
<span class="hljs-keyword">use</span>
17+
<span class="hljs-title">Symfony</span>
18+
\
19+
<span class="hljs-title">Component</span>
20+
\
21+
<span class="hljs-title">Messenger</span>
22+
\
23+
<span class="hljs-title">MessageBusInterface</span>
24+
;
25+
<span class="hljs-keyword">use</span>
26+
<span class="hljs-title">Symfony</span>
27+
\
28+
<span class="hljs-title">Component</span>
29+
\
30+
<span class="hljs-title">Messenger</span>
31+
\
32+
<span class="hljs-title">Stamp</span>
33+
\
34+
<span class="hljs-title">DelayStamp</span>
35+
;
36+
<span class="hljs-keyword">public</span>
37+
<span class="hljs-function">
38+
<span class="hljs-keyword">function</span>
39+
<span class="hljs-title">index</span>
40+
<span class="hljs-params">
41+
(MessageBusInterface
42+
<span class="hljs-variable">
43+
<span class="hljs-variable-other-marker">$</span>
44+
bus
45+
</span>
46+
)
47+
</span>
48+
</span>
49+
{
50+
<span class="hljs-variable">
51+
<span class="hljs-variable-other-marker">$</span>
52+
bus
53+
</span>
54+
-&gt;
55+
<span class="hljs-title invoke__">dispatch</span>
56+
(
57+
<span class="hljs-keyword">new</span>
58+
<span class="hljs-title invoke__">SmsNotification</span>
59+
(
60+
<span class="hljs-string">'...'</span>
61+
), [
62+
<span class="hljs-comment">// wait 5 seconds before processing</span>
63+
<span class="hljs-keyword">new</span>
64+
<span class="hljs-title invoke__">DelayStamp</span>
65+
(
66+
<span class="hljs-number">5000</span>
67+
), ]);
68+
}
69+
</code>
70+
</pre>
71+
</div>
72+
</div>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
You can do that by adding a "stamp" to your message::
2+
3+
use Symfony\Component\Messenger\MessageBusInterface;
4+
use Symfony\Component\Messenger\Stamp\DelayStamp;
5+
6+
public function index(MessageBusInterface $bus)
7+
{
8+
$bus->dispatch(new SmsNotification('...'), [
9+
// wait 5 seconds before processing
10+
new DelayStamp(5000),
11+
]);
12+
}

0 commit comments

Comments
 (0)