Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 341
Meredith Avatar asked Jun 12 '14 17:06

Meredith


People also ask

How do I put multiple lines in a Markdown cell in a table?

In summary, if you need to have a table cell span multiple lines when writing Markdown, use the HTML <br> tag, as shown.

How do you write multiple lines in Markdown?

Paragraphs. To create paragraphs in Markdown, use one or more lines of consecutive text followed by one or more blank lines. Note: If you don't leave a blank line between blocks of text, they will be collapsed into a single paragraph.

How do you make a code block in Markdown?

The basic Markdown syntax allows you to create code blocks by indenting lines by four spaces or one tab. If you find that inconvenient, try using fenced code blocks. Depending on your Markdown processor or editor, you'll use three backticks ( ``` ) or three tildes ( ~~~ ) on the lines before and after the code block.

How do I break a line in a table in Markdown?

A newline in Markdown is created by “2 spaces at the end of the line and a single newline”. where the _ are spaces.


2 Answers

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

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

like image 58
Meredith Avatar answered Oct 02 '22 16:10

Meredith


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"]
}
like image 33
Gangula Avatar answered Oct 02 '22 17:10

Gangula