Home/Jira formatting reference
Jira text formatting
Languages the Jira {code} macro accepts, and what ADF keeps
The language goes right after the macro name, as in {code:python}. When it is not on the renderer's list, Jira prints an error line that spells out the available languages. Highlighting in a v2 comment and the language stored in ADF are two different things, and they do not always agree.
Wiki markup
{code:python}...{code}
{code:bash|title=install.sh}...{code}
{code:<language>|title=<text>}...{code}
Markdown shortcuts in the editor
Per the Atlassian documentation, not tested.
| Type | What happens |
|---|---|
``` | Opens a code block in the editor, per the Atlassian documentation. The shortcut table does not list a language after the fence. |
Stored as ADF (REST API v3)
The ADF document Jira Cloud stores for ADF:{"content": [{"attrs": {"language": "python"}, "content": [{"text": "print(1)", "type": "text"}], "type": "codeBlock"}], "type": "doc", "version": 1}:
{
"type": "doc",
"version": 1,
"content": [
{
"type": "codeBlock",
"attrs": {
"language": "python"
},
"content": [
{
"type": "text",
"text": "print(1)"
}
]
}
]
}
Examples
Wiki markup (API v2)
{code:python}
print("hi")
{code}Plain case. python is on the list, is highlighted, and is kept in the stored ADF.
Rendered by Jira (HTML)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-python"><span class="code-object">print</span>(<span class="code-quote">"hi"</span>)
</pre>
</div></div>Back to wiki after the round trip
{code:python}print("hi"){code}Sent to Jira Cloud on .
Wiki markup (API v2)
{code:yaml}
a: 1
{code}yaml is highlighted in the v2 render, yet the stored ADF falls back to java.
Rendered by Jira (HTML)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-yaml"><span class="code-keyword">a: </span><span class="code-object">1</span>
</pre>
</div></div>Back to wiki after the round trip
{code:java}a: 1{code}Sent to Jira Cloud on .
Wiki markup (API v2)
{code:sh}
ls
{code}sh is on the list and is highlighted, and it falls back to java in ADF in the same way.
Rendered by Jira (HTML)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-sh">ls
</pre>
</div></div>Back to wiki after the round trip
{code:java}ls{code}Sent to Jira Cloud on .
Wiki markup (API v2)
{code:typescript}
let a = 1
{code}typescript is not on the list. The render shows an error line, and the stored node has no usable language, so it returns as {noformat}.
Rendered by Jira (HTML)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div class="error"><span class="error">Unable to find source-code formatter for language: typescript.</span> Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml</div><pre>let a = 1
</pre>
</div></div>Back to wiki after the round trip
{noformat}let a = 1{noformat}Sent to Jira Cloud on .
Wiki markup (API v2)
{code:ts}
let a = 1
{code}The short name ts is not an alias either. Same error line in the render, java in ADF.
Rendered by Jira (HTML)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div class="error"><span class="error">Unable to find source-code formatter for language: ts.</span> Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml</div><pre>let a = 1
</pre>
</div></div>Back to wiki after the round trip
{code:java}let a = 1{code}Sent to Jira Cloud on .
Wiki markup (API v2)
{code:text}
plain
{code}text is not on the list. For plain monospace use {noformat}.
Rendered by Jira (HTML)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div class="error"><span class="error">Unable to find source-code formatter for language: text.</span> Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml</div><pre>plain
</pre>
</div></div>Back to wiki after the round trip
{code:java}plain{code}Sent to Jira Cloud on .
Wiki markup (API v2)
{code:language=sql}
SELECT 1;
{code}Tries a named parameter. The wiki parser takes only the bare form after the colon, so the block renders unhighlighted as Java.
Rendered by Jira (HTML)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">SELECT 1;
</pre>
</div></div>Back to wiki after the round trip
{code:java}SELECT 1;{code}Sent to Jira Cloud on .
What changes in conversion
- Kept in ADF in these probes: python, json, javascript, go. Replaced by java: yaml, sh, bash, text, ts and any unknown name.
- typescript is the odd one out: it comes back as {noformat}, which means the language is lost and the block is no longer a code macro in wiki.
- The stored value and the v2 highlighting are separate. A language can be highlighted in the render and still be replaced by java once the comment is saved through the editor path.
Pitfalls
- Check the language against the list below before relying on it. A wrong name shows an error line in v2 comments.
- Names are not aliased.
ts,textandtypescriptall fail on Jira Cloud's wiki renderer. - The list as printed by Jira: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml.