How can I escape curly braces within {code} tags?

Patrick McElhaney
Contributor
December 17, 2013

I was trying to show someone how to use the {code} tag in a comment in Crucible. I want to wrap my example in code tags, but have the literal "{code}" show up in the example.

Hey girl, I heard you like putting code in your comments.

{code}
\{code\}
// Your code goes here.
\{code\}
{code}

And this is how it came out:

Hey girl, I heard you like putting code in your comments.
\{code\}
    // Your code goes here.
    \{code\}

How can I enter the comment so that it appears like this?

Hey girl, I heard you like putting code in your comments.
{code}
    // Your code goes here.
    {code}

15 answers

11 votes
Chandler258
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 25, 2015

You can use HTML escape characters to do the curly braces: 

{ = {

} = }

 

Example: {{{your text here}}}

jason_s September 11, 2015

Doesn't work in {code} tags.

Chandler258
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 1, 2015

Jason, you are right, it does not work with {code} tags. It does work for the problem that Patrick was having: Hey girl, I heard you like putting code in your comments. {code} // Your code goes here. {code} As far as I know, in {code} tags there is no need to escape curly braces. You might need to put the actual tag in it's own line: {code} { "Name": "Somename" "Lastname": "Somelastname" } {code}

8 votes
Patrick McElhaney
Contributor
December 17, 2013

Sigh. I can't figure out how to enter code in the question so it doesn't create several disjointed code blocks.

You guys, this would be so much easier if you just got rid of these proprietary markup languages and switched to Markdown.

Frak N
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 4, 2019

YES! Every forum site in the world lets you copy and paste unformatted text but you guys have to do it your own weird way that doesn't work!

All I want it to copy and paste my console logs as a comment and move on. But now because there's JSON in the logs, it ruins everything.

Why is it that you can't reproduce what Notepad can!?

ctreptow
Contributor
April 4, 2019

Notepad is an application that displays a whole file and confluence is a webpage that displays code, this is just not comparable. You need a delimiter in this case and obviously the delimiter { code } is very common

James Bromwell
Contributor
April 4, 2019

The delimiter " { code } " is not "very common", it's used in Atlassian products and basically nowhere else.  Even in Wikimedia markup you can format JSON and other common flavors of curly-brace-containing code pretty easily, though pasting HTML is a chore.

 

I've said it elsewhere and I'll say it again: Markdown won. It's just better *for discussing code* than any other lightweight markup language.  If Atlassian mostly made products to help librarians deal with books or automotive engineers design cars, the use of a markup language that makes it impossible to talk about JSON and other brace-heavy code snippets would be totally understandable.  But they don't -- they make software that's used almost exclusively for managing software projects.

 

This problem was embarrassing 10 years ago.  In 2019, it is inexcusable.

Like # people like this
James Bromwell
Contributor
July 25, 2019

Hah, just got an email from Atlassian asking me to come back to the community here because the above post is so popular :D

 

We're still waiting...

Like Jonathan Ditzel likes this
5 votes
T
Contributor
November 2, 2016

Another vote for switching to Markdown!  It shouldn't take half an hour to find a way to get a close-curly-brace in a code section.  Backspace escaping should work for code sections like it does for underscores in underline sections.  The JIRA markup language is as inconsistent as it is buggy.

3 votes
Maciek Pawlowski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 4, 2015

This solution works if you don't mind your text being bold:

example 1:

{foo}

  1. type the "*" character
  2. type the "{" character
  3. type your text
  4. type the "*" character twice. This effectively ends a bold run and starts another bold run.
  5. type the "}" character.
  6. type the "*" character to end the bolding.

example 2:

{{code}}

  1. type the "*" character
  2. type the "{" character twice
  3. type your text
  4. type the "}" character.
  5. type the "*" character twice. This effectively ends a bold run and starts another bold run.
  6. type the "}" character.
  7. type the "*" character to end the bolding.

 

Deleted user November 22, 2016

This absolutely works and was the only way I could enter the regex "[- 0-9_\p{Ll}\p{Lu}\p{Lt}]" into a JIRA comment ... though in raw it does look like this: *"[- 0-9_\p**{**Ll**}**\p**{**Lu**}**\p**{**Lt**}**\]"*

1 vote
ctreptow
Contributor
February 19, 2019

here is a dirty hack: insert a (invisible) space before or after the word "code":

​{code}
this is my {code​}
{code}

notice: i've inserted the invisible space after the word "code" within the code-block.

A drawback: copying this code probably prevents it from functioning correct.
You can also insert just a space and hope the person that copies notices it...

1 vote
rob.green
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 11, 2018

The formatting in the JIRA editable content sections is disgraceful.

When pasting JSON snippets, I've been formatting code as monospace and inserting { and } to avoid double braces, however it randomly decides whether to print a single "{" or "}", or wrap sections in "{{ }}".

Every time it goes bezerk putting in "{{ }}" I have to go back and fix it, sometimes multiple times before it leaves it alone.

There are many, many good editors out there, why can't Atlassian get this right? Sites like StackOverflow have vastly better online editors. The behaviour of the Confluence and JIRA editors is quite different, why?

Does anyone have a reliable way of putting, say JSON into an editable section and have it not messed up? 

{
"name":"foo",
"age":23
}
James Bromwell
Contributor
January 30, 2019

The simple fact is that lightweight markup for talking about code has been solved.  Markdown won, for good reason, and the nonsense that Atlassian uses lost.  It's terrible and the longer they insist on using it, the more embarrassing it will be when they finally give up and switch.

Like brent olson likes this
1 vote
T
Contributor
November 2, 2016

With underscores, one can backslash an underscore mid-underline-section to get a literal underline there.  With double curly braces around code, one cannot backslash a close-curly-brace mid-code-section to get a literal close-curly-brace there.

 

Example without proper escaping:

{{my_dict = {}}}    renders as    my_dict = {}

 

Example attempting to use a backslash to escape the close-curly-brace (which doesn't work):

{{my_dict = {\}}}  renders as     my_dict = {}

 

Is there a sane alternative that works in this case?

I'm not seeing one in the other answers to this question.  The double-star trick mentioned in another answer does not work in the case of code sections (delineated with double curly braces).

The trick I have found to work is to close the curly brace section early, then put the single close-curly-brace in its own code section.  Thus, the workaround to get one close-curly-brace in your code section is the mind-numbing sequence of:

}}{{}}}

That'll put a close curly brace at the end of a code section.  You'll need to reopen the code-section with a {{ after all of that if you're not yet at the end of your code section.

 

Example of the functioning workaround:

{{my_dict = }}{{}}}     renders as      my_dict = {}

 

There really needs to be a better way.

 

 

1 vote
Patrick McElhaney
Contributor
October 6, 2014
0 votes
Tidbit Software
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 18, 2020

Just in case this helps someone else, I found this question while trying to figure out how to escape French braces under Wiki markup for Trac.

I was doing something like,

{{{foo=bar{:}}}}

which was formatting all but the trailing brace. However, this will be parsed correctly by adding a single white space before and after the string to be formatted,

{{{ foo=bar{:} }}}

Of course, I figured out after the fact that a more sensible solution is to simply do,

`foo=bar{:}`

Again, I don't know if this applies to O.P.'s question and/or Crucible, but I'd like to the knowledge for others just in case.

0 votes
edward71 September 20, 2019

Im using ConfluencePS to add pages , they contain lots of code, json, regexes etc..

In my first run I notice: Invoke-Method : com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro '
*** "applicationid"' is unknown.

So I assume this is because the { is interpreted as a macro.

But I think... I need a filter to filter all possible tokens that it picks up (i notice it hides [  ]  texts) in the text pieces but it must remain the markup in the non textual pieces e.g. lists and such.

0 votes
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 17, 2018

Still confirmed: no way to apply formatting with the {code} block.

Escaping curly braces worked fine for this simple example when typing commentary on the Text tab:

<script type "text/javascript">
$(document).ready(function() \{
var tblFilter = $('.tableFilterCbStyle');
tblFilter.find('.sortable-container').removeClass('sortable-container').sortable(
\{disabled: true\});
 \});
</script>

This results in the visual representation (when switching to Visual tab) without formatting as a code block:

<script type "text/javascript">
$(document).ready(function() {
var tblFilter = $('.tableFilterCbStyle');
tblFilter.find('.sortable-container').removeClass('sortable-container').sortable(
{disabled: true});
 });
</script>
0 votes
Nathan Hinchey August 29, 2018

Is this still unresolved?

MikeRosoftJH
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 30, 2018

It is. We have Jira in our company, and the visual editor still corrupts the ending braces in a code block, and I haven't found a way to fix them.

0 votes
Tasos Chalkias
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 5, 2017

You could try doubling the curly braces. So, you type "{{" and "}}" instead of "{" and "}".

I am not sure if that will work in Crucible, but I know it works on JIRA comments and descriptions.

0 votes
John Burak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 6, 2014

Amen to that.

0 votes
HosseinA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 18, 2013

Hi,

In order to escape it, you can do this:

1- {

2- }

3- Then place the cursor in the middle of {} and type

Hope this works.

Patrick McElhaney
Contributor
January 2, 2014

Thanks. That doesn't work.

Like Thor Simon likes this
T
Contributor
November 22, 2016

Can you please get a backslash to escape a close-curly-brace inside a code-section?

Like Thor Simon likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events