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 \ } \ }.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
José Manuel
  • 35
  • 1
  • 6
  • 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 '16 at 22:23
  • Thanks for answering, but I still have the same problem. – José Manuel Sep 21 '16 at 22:38
  • I just copy-and-pasted your question to a new GitHub Gist. The braces display correctly. https://gist.github.com/Keith-S-Thompson/43ba8e724b2f733c5e1d20e557161b20 – Keith Thompson Sep 21 '16 at 22:39
  • @KeithThompson Try the [original post](http://stackoverflow.com/revisions/29d2e9cd-7279-4e86-ae2d-5f4a90181342/view-source) – OneCricketeer Sep 21 '16 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 – Marcel Valdez Orozco Sep 21 '16 at 22:49
  • Yes, I'm using Jekyll. I'll see your answer Macel. – José Manuel Sep 21 '16 at 22:53
  • @cricket_007: I just copy-and-pasted the original version of the question into the same Gist, file `README_0.md`. I see a stray backtick, but the braces still display correctly, at least in my browser (Chrome on Ubuntu). (Apparently Jekyll is an issue; I don't know anything about that.) – Keith Thompson Sep 21 '16 at 22:56
  • @cricket_007 is different using Jekyll. Here is the answer http://stackoverflow.com/questions/3426182/how-to-escape-liquid-template-tags – José Manuel Sep 21 '16 at 22:58

2 Answers2

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?

Community
  • 1
  • 1
Marcel Valdez Orozco
  • 2,985
  • 1
  • 25
  • 24
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>
Alan
  • 459
  • 6
  • 20