Escaping double curly braces inside a markdown code block in Jekyll

前端 未结 5 1980
走了就别回头了
走了就别回头了 2020-11-30 22:17

I\'m using Jekyll to create a documentation site wherein I am trying to document some code that contains handlebars-like syntax. For example {{foo}}. The proble

相关标签:
5条回答
  • 2020-11-30 22:42

    With jekyll the code is:

    {% highlight html%}
    {% raw %}
         <h2> {{ user.name.first | uppercase }}</h2>
         <p> {{ user.email }}</p>
    {% endraw %}
    {% endhighlight %}
    
    0 讨论(0)
  • 2020-11-30 22:47

    You're looking for the {% raw %} tag.

    {% raw %}
    Hello, my name is {{name}}.
    {% endraw %}
    
    0 讨论(0)
  • 2020-11-30 22:51

    You can use {% raw %} to ensure content is unmodified by Jekyll:

    {% raw %}
    This is inserted literally: {{foo}}
    {% endraw %}
    

    However, note that this is not a code block. You will need additional code formatting to make your content render as code:

    {% raw %}
        I'm a code block, because I'm indented by 4 spaces
    {% endraw %}
    
    {% raw %}
    ```handlebars
    I'm a code block that contains {{handlebars}}
    with highlighting.
    ```
    {% endraw %}
    
    0 讨论(0)
  • 2020-11-30 22:52

    This works in jekyll:

    {%raw%}{{thing}}{%endraw%}
    
    0 讨论(0)
  • 2020-11-30 22:58

    For future references: using plain {% raw %} and {% endraw %} is only the second best solution since those are shown if you look up the Markdown on normal github.com.

    The best way is to put {% raw %} and {% endraw %} in HTML comments:

    <!-- {% raw %} -->
    something with curlky brackets like { this } and { that }
    <!-- {% endraw %} -->
    

    Due to the HTML comments it is seen by Github as a comment. In Github pages the raw tags will prevent the parsing of the curly brackets in between the tags.

    0 讨论(0)
提交回复
热议问题