3

I would like to write {{ ... }} inside a code block using Markdown.

For example:

{{ var }}  

I don't know why it disappears. However I can write it outside a block of code: \ {\ { var \ } \ }.

8
  • 1
    Two things to try: (1) make sure you don't have a space between two of the backticks on the code-block starter line; (2) try using an indented code block instead of a fenced code block.
    – zwol
    Sep 21, 2016 at 22:23
  • Thanks for answering, but I still have the same problem. Sep 21, 2016 at 22:38
  • I just copy-and-pasted your question to a new GitHub Gist. The braces display correctly. gist.github.com/Keith-S-Thompson/… Sep 21, 2016 at 22:39
  • @KeithThompson Try the original post Sep 21, 2016 at 22:41
  • 1
    OP is probably using Jekyll to build his github pages and var is being resolved to a variable with an empty value Sep 21, 2016 at 22:49

2 Answers 2

2

Github flavored markdown supports that

You should be able to do exactly that. I think you must be using a bugged markdown implementation (or one with a 'templating mechanism' where {{ xxx }} is treated like variable interpolation), in normal markdown the following code block should work:

{{ var }}

As you can see, the StackOverflow markdown processor is doing the right thing, it is putting {{ var }} verbatim in the code block.

But Jekyll is another story

If you are using Jekyll to create your github pages, be aware that {{ }} is used for variable interpolation. Jekyll uses Liquid for this. Documentation:

Your answer is probably here (there are multiple options): How to escape liquid template tags?

3
1

You could use something like this.

{% highlight liquid %}
  {% raw %}
    {{ Your code here }}
  {% endraw %}
{% endhighlight %}

This will output the following code:

<code class="language-liquid" data-lang="liquid">  
  <span class="p">{{</span>
  <span class="w"> </span>
  <span class="nv">Your code here</span>
  <span class="w"> </span>
  <span class="p">}}</span>
</code>

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.