Escaping Twig macros in Geshi

While writing the last post, I had some trouble trying to escape a Twig macro when using Geshi for syntax highlighting. Here’s the trick to escape it: raw.

The raw Twig tag prints the subsequent tags without interpreting it.

{%geshi 'twig'%}
{ %raw%}{% macro button(...) %}{ %endraw%}
<p>Some random HTML code...</p>{% raw%}{% endmacro %}{ %endraw%}
{%endgeshi%}

We had to add an extra space between { and %. Can you figure out why? :-)