Skip to content

Commit 29ddf17

Browse files
committed
feature #184 Add support for inline Twig comments (javiereguiluz)
This PR was merged into the main branch. Discussion ---------- Add support for inline Twig comments Twig added inline comments (twigphp/Twig#4349) so I tried to add support for them here. But, it's not working. Anyone knows if this could be easy to fix or if it's too complex to do it? Thanks! Commits ------- 126cfbf Add support for inline Twig comments
2 parents b4a1031 + 126cfbf commit 29ddf17

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/Templates/highlight.php/twig.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@
2525
"begin": "\\{%",
2626
"end": "%}",
2727
"contains": [
28+
{
29+
"className": "comment",
30+
"begin": "#",
31+
"end": "$",
32+
"endsWithParent": true
33+
},
2834
{
2935
"className": "name",
3036
"begin": "\\w+",
3137
"keywords": "apply autoescape block deprecated do embed extends filter flush for from if import include macro sandbox set use verbatim with endapply endautoescape endblock enddeprecated enddo endembed endextends endfilter endflush endfor endfrom endif endimport endinclude endmacro endsandbox endset enduse endverbatim endwith",
3238
"starts": {
3339
"endsWithParent": true,
3440
"contains": [
41+
{
42+
"$ref": "#contains.1.contains.0"
43+
},
3544
{
3645
"begin": "\\|[A-Za-z_]+:?",
3746
"keywords": "abs batch capitalize column convert_encoding date date_modify default escape filter first format inky_to_html inline_css join json_encode keys last length lower map markdown merge nl2br number_format raw reduce replace reverse round slice sort spaceless split striptags title trim upper url_encode",
@@ -53,7 +62,7 @@
5362
]
5463
},
5564
{
56-
"$ref": "#contains.1.contains.0.starts.contains.0.contains.0"
65+
"$ref": "#contains.1.contains.1.starts.contains.1.contains.0"
5766
}
5867
],
5968
"relevance": 0
@@ -68,10 +77,13 @@
6877
"contains": [
6978
"self",
7079
{
71-
"$ref": "#contains.1.contains.0.starts.contains.0"
80+
"$ref": "#contains.1.contains.0"
81+
},
82+
{
83+
"$ref": "#contains.1.contains.1.starts.contains.1"
7284
},
7385
{
74-
"$ref": "#contains.1.contains.0.starts.contains.0.contains.0"
86+
"$ref": "#contains.1.contains.1.starts.contains.1.contains.0"
7587
}
7688
]
7789
}
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1-
<div translate="no" data-loc="1" class="notranslate codeblock codeblock-length-sm codeblock-twig">
1+
<div translate="no" data-loc="9" class="notranslate codeblock codeblock-length-sm codeblock-twig">
22
<div class="codeblock-scroll">
3-
<pre class="codeblock-lines">1</pre>
4-
<pre class="codeblock-code"><code><span class="hljs-comment">{# some code #}</span></code></pre>
3+
<pre class="codeblock-lines">1
4+
2
5+
3
6+
4
7+
5
8+
6
9+
7
10+
8
11+
9</pre>
12+
<pre class="codeblock-code">
13+
<code>
14+
<span class="hljs-comment">{# some code #}</span>
15+
<span class="xml"></span>
16+
<span class="hljs-template-tag">
17+
{%
18+
<span class="hljs-name"><span class="hljs-keyword">set</span></span> some_var = 'some value' <span class="hljs-comment"># some inline comment</span>
19+
%}
20+
</span>
21+
<span class="xml"></span>
22+
<span class="hljs-template-variable">{{
23+
<span class="hljs-comment"># another inline comment</span>
24+
'Lorem Ipsum'|uppercase
25+
<span class="hljs-comment"># final inline comment</span>
26+
}}</span>
27+
</code>
28+
</pre>
529
</div>
630
</div>
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
21
.. code-block:: twig
2+
33
{# some code #}
4+
{%
5+
set some_var = 'some value' # some inline comment
6+
%}
7+
{{
8+
# another inline comment
9+
'Lorem Ipsum'|uppercase
10+
# final inline comment
11+
}}

0 commit comments

Comments
 (0)