Markdown multiline code blocks in tables when rows have to be specified with one-liners

26,726

Solution 1

Replace ` with <code> tags and use &nbsp; and <br>for indentation.

Similarly you can use <pre> tags instead of ```.

Solution 2

Answer by @Meredith is the perfect answer to this. I'd like to add more details and examples below

You cannot replace ` with <code> if you need to add other HTML tags inside the <code> element in your table cell. Instead you need to use backtick (`) inside the <pre> tag like this:

Markdown Input HTML Output HTML Preview
<pre>
<p>Test Line</p>
</pre>
<pre><p>Test line</p></pre>

Test Line

Example 2:

Markdown Input HTML Output HTML Preview
`{a: 1, b: 2, c: 3}` <code>{a: 1, b: 2, c: 3}</code> {a: 1, b: 2, c: 3}
<pre> {JSON: <br>
&emsp; ["Key1":"Value1",<br>
&emsp; "Key2":"Value2"] <br>
}</pre>
<pre> {JSON: <br> &emsp;["Key1":"Value1",<br> &emsp;"Key2":"Value2"]<br> } </pre>
{JSON: 
 ["Key1":"Value1",
 "Key2":"Value2"]
}
Share:
26,726
Meredith
Author by

Meredith

Updated on October 21, 2021

Comments

  • Meredith
    Meredith over 2 years

    I have a table:

    | YAY! | TABLE | \^^/ | 1-liner JSON column! |
    | ---- | ----- | ---- | -------------------- |
    | That |  has  | JSON | `{a: 1, b: 2, c: 3}` |
    | Here |  is   | more | `{d: 4, e: 5, f: 6}` |
    

    Is there any way for me to insert in multiline code blocks into a generated table cell?