Twig syntax highlighting in code blocks is a mess. Many things just don't work (see first bug report and examples below) and make reading code less clear than without highlights.
Please remove the feature until this works better.
.
Problems
Twig:
- Some Twig tags and operators are highlighted (1) and some are not (2)
- Filters are not highlighted at all (3)
- String "var" highlighted as twig tag (4)
Twig Comments:
- No highlighting of comment text and opening tag (5)
- Twig code highlighting not disabled within comments (6)
HTML:
- Different opening/closing tag highlights (7)
- Opening tag highlighted differently if attributes added (8)
- Twig code highlighting not disabled within comments (9)
- HTML code highlighted treated similar to twig code and vars (10)
- No highlighting of HTML comments (11)
- Complete twig syntax highlighting fails if the code begins with html (see ex. here)
Other:
- Strange highlights of words like "Twig" and "Comment" (12)
.
Examples
Syntax language set to lang-twig
:
{% set foo = true %} [1]
{% extends "foo.html" %} [1]
{% spaceless %} ... {% endspaceless %} [2]
{% macro foo() %} ... {% endmacro %} [2]
{{ foo|raw ~ foo|length ~ foo|date('Y') ~ '...' }} [3]
{% if var == true and foo == 'string' %} ... {% elseif foo %} ... {% endif %} [2, 4]
{# Twig code within comments: extends, in, ... #} [5, 6, 12]
<p>Twig code within html: with, set, ...</p> [7, 9, 10, 12]
<p attribute="extends test">HTML code with attributes</p> [8, 10]
<!-- HTML Comment --> [11, 12]
.
Comparison
Compare this to syntax highlighting in Sublime Text using PHP-Twig.tmbundle by Andrew Fricke or Craft-Twig.tmbundle by Ben Parizek:
lang-php
option for the tags that are using it, and encourage people to use<!-- language: lang-twig -->
in the code block if desired.lang-none
tolang-twig
with one of my answers, I think this works very good as an example of how bad this actually works so far.<!-- language: lang-twig -->
is already added? They'll still look like cr.. (sorry) or I'll have to open them all up and remove the line?! Please just remove it altogether. It's just for now until s.o. makes it work properly. In the meantime we can all continue to use it in the markup and then, some day, they'll all look beautiful :Dlanguage
tag, the parser is doing exactly... nothing. Or more specifically, it's falling back to "default" detection, which is generally picking it up as HTML.none
orhtml
as the automatic highlighting for anything with a "twig" tag. I'd like to hear more from the community and other mods before we make a decision like that.