Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandoc Markdown: Multiparagraph list with code blocks

The whole documentation on Lists on the Pandoc site seems wrong or at best a huge mess.

I mostly sorted out the way to deal with multiple paragraphs in lists, but I am stuck with the following combination: The text paragraph following a code block paragraph falls off the list. That is, a code block paragraph breaks the list (as seen in the latex .tex output file; use option -t tex).

If the following Markdown text is in file test.md and I use Pandoc as pandoc -t latex test.md -o test.pdf

How should the following Markdown text be formatted so that Paragraph 3 falls inside item 1 of the list and is aligned with its first paragraph?

   1. List item. Paragraph 1

   ```javascript
        // Second paragraph is a code block. If start at column 6, code shows ok.
        // Additional indentation only moves code block further right
        // Notice code block tag/backticks starts at column 1 though!!
        //  If it starts at col 2+, code block w/ tag is messed up as all code block.
        var x = 3
        print( "Pandoc has made a mess out of Markdown!" )
   ```

        Paragraph 3. However list is broken and Par 3 falls off.
   2. List item

It should show as:

  1. List item. Paragraph 1

// Second paragraph is a code block. If start at column 6, code shows ok. // Additional indentation only moves code block further right // Notice code block tag/backticks starts at column 1 though!! // If it starts at col 2+, code block w/ tag is messed up as all code block. var x = 3 print( "Pandoc has made a mess out of Markdown!" )

   Paragraph 3. However list is broken and Par 3 falls off.

2. List item

But instead shows as

  1. List item. Paragraph 1

// Second paragraph is a code block. If start at column 6, code shows ok. // Additional indentation only moves code block further right // Notice code block tag/backticks starts at column 1 though!! // If it starts at col 2+, code block w/ tag is messed up as all code block. var x = 3 print( "Pandoc has made a mess out of Markdown!" )

Paragraph 3. However list is broken and Par 3 falls off.

  1. List item
like image 430
MASL Avatar asked Apr 06 '26 21:04

MASL


1 Answers

The key is to use the right combination of indents and newlines:

1. List item, no indention

    This paragraph is indented by two tabs (four spaces). 
    Put separating newlines below and above the following code chunk:

    ```javascript
    // This code chunk is indented by two tabs (four spaces)
    var x = 3
    print("Pandoc has made a mess out of Markdown!")
    ```

    Paragraph 3 is indented by two tabs.

2. List item, no indention

This yields

enter image description here

like image 170
Martin C. Arnold Avatar answered Apr 11 '26 15:04

Martin C. Arnold



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!