Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twig syntax highlighting broken #881

Closed
ericmorand opened this issue Mar 12, 2018 · 4 comments
Closed

Twig syntax highlighting broken #881

ericmorand opened this issue Mar 12, 2018 · 4 comments
Labels
bugfix-request A request for a bugfix to be developed.

Comments

@ericmorand
Copy link

ericmorand commented Mar 12, 2018

Hi,

First, sorry, I don't know anything about Ruby so I cant' give an example that is not a Jekyll template. Jekyll team confirmed that this is a Rouge issue (jekyll/jekyll#6844).

So here it is, hoping that you'll be able to understand and reproduce the bug.

Rouge syntax highlighting is broken with Twig. Consider the following Jekyll code blocks containing a perfectly valid Twig syntax:

{% highlight twig %}
{% raw %}
{% set a = 'b' %}
{% endraw %}
{% endhighlight %}
    ```twig
    {% raw %}
    {% set a = 'b' %}
    {% endraw %}
    ```

Both outputs the following HTML:

<code class="language-twig" data-lang="twig">
    <span class="cp">{%</span> 
    <span class="k">set</span> 
    <span class="nv">a</span> 
    <span class="err">=</span>
    <span class="s1">'b'</span> 
    <span class="cp">%}</span>
</code>

Notice the err class attributed to the equal sign.

Steps to reproduce

---
layout: post
title:  "Welcome to Jekyll!"
categories: jekyll update
---

{% highlight twig %}
{% raw %}
{% set a = 'b' %}
{% endraw %}
{% endhighlight %}

@pathawks
Copy link

It looks like the Twig lexer is a subclass of the Jinja lexer, which does not include an assignment operator:

https://github.com/jneen/rouge/blob/966efcb7a1cfa1d1851f8f44d292426de2b5d006/lib/rouge/lexers/jinja.rb#L82-L87

For reference, the statement seems to render correctly on GitHub:

{% set a = 'b' %}

GitHub uses the Twig TextMate bundle for highlighting Twig snippets.

@XaBerr
Copy link

XaBerr commented Mar 19, 2018

Same problem here, I do not know if this can help but I'm using jekyll on github to render twig code and give me the same problem.

code

rendering

@stale
Copy link

stale bot commented Jun 19, 2019

This contribution has been automatically marked as stale because it has not had any activity for more than a year. It will be closed if no additional activity occurs within the next 14 days.

@stale stale bot added the stale-issue There has been no activity for a year. label Jun 19, 2019
@pyrmont
Copy link
Contributor

pyrmont commented Jun 19, 2019

Support for raw has been added via #1003. Please let us know if there are any problems with it!

@pyrmont pyrmont closed this as completed Jun 19, 2019
@pyrmont pyrmont added bugfix-request A request for a bugfix to be developed. and removed stale-issue There has been no activity for a year. labels Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix-request A request for a bugfix to be developed.
Projects
None yet
Development

No branches or pull requests

4 participants