My jinja2 template receives a code block which may contain any number of different languages. I would like to pass the correct lexer to the template and render it accordingly using the jinja2-highlight plugin (pygments). I render my template using the 'command' variable, which is a dictionary holding all data necessary in the rest of the template. Ideally I'd like to do something along these lines
{% highlight "{{ command.lexer }}", lineno='table' %}{{ command.script }}{% endhighlight %}
I have tried:
{% highlight command.lexer, lineno='table' %}
{% highlight 'command.lexer', lineno='table' %}
{% highlight '{{ command.lexer }}', lineno='table' %}
and even
{% set lexer = command.lexer %}
{% highlight 'lexer', lineno='table' %}
{% highlight '{{ lexer }}', lineno='table' %}
I can't seem to figure out the combination of rendering rules between jinja2 and jinja2-highlight / pygments.
I'd really like to not do something like:
{% if command.lexer == 'bash' %}
{% highlight 'bash', lineno='table' %}
{% elif command.lexer == 'perl' %}
{% highlight 'perl', lineno='table' %}
...
{% endif %}
It seems to have to do with the jinja2 parser class, but I'm a bit stuck.. feels like I'm overlooking something trivial.
Various error messages all look like:
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got ','