Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to nest code block under a list item in BitBucket mark down?

While there are several questions/answers with combination of keywords from this question, I don't see one that directly asks the same question or answers it.

I want to nest a code block under a list item. When I follow this answer, I don't quite get the effect I'm looking for. In below image, I wouldn't want the leading spaces in the code block and I would like the box itself to be indented under the list item. How do I achieve this?

enter image description here

And, here is the actual MD:

** Help Page **

* This is a list item that has a code block going with it

```
#!c#
        try
        {
            DoSomething(passThis, andThis);
        }
        catch (Exception ex)
        {
            ex.Log();
        }

```
like image 326
WiSeeker Avatar asked Nov 20 '16 18:11

WiSeeker


People also ask

How do I add code block to Markdown?

To produce a code block in Markdown, simply indent every line of the block by at least 4 spaces or 1 tab. For example, given this input: This is a normal paragraph: This is a code block. A code block continues until it reaches a line that is not indented (or the end of the article).

Does bitbucket support Markdown?

Bitbucket can parse and display Markdown, reStructuredText, Textile, and plain text README files. With a syntax like Markdown, you can emphasize text, include screen captures, and more.

How do you escape code block in Markdown?

Depending on your Markdown processor or editor, you'll use three backticks ( ``` ) or three tildes ( ~~~ ) on the lines before and after the code block.


1 Answers

Instead of a fenced code block (```), use an indented code block. Indent with four spaces to nest inside the list item, and four more to represent a code block:

**Help Page**

* This is a list item that has a code block going with it

        #!c
        try
        {
            DoSomething(passThis, andThis);
        }
        catch (Exception ex)
        {
            ex.Log();
        }

Note that the language tag here should be #!c, not #!c# as in your question.

Alternatively, you can use a fenced code block but it must still be indented by four spaces so it gets included in the list item:

**Help Page**

* This is a list item that has a code block going with it

    ```c
    try
    {
        DoSomething(passThis, andThis);
    }
    catch (Exception ex)
    {
        ex.Log();
    }
    ```
like image 106
Chris Avatar answered Oct 11 '22 18:10

Chris