Markdown: How to insert Java code block inside table cell?

前端 未结 3 1122
孤独总比滥情好
孤独总比滥情好 2020-12-22 11:45

I know how to insert a line of code inside a table cell. But I cannot do it when I want to insert a code block like this inside a table cell:

public class He         


        
相关标签:
3条回答
  • 2020-12-22 12:22

    You can't without raw HTML.

    Most, if not all Markdown implementations which support table syntax only support inline markup within table cells. That means that "block level" constructs can not be used within table cells from Markdown. That means no paragraphs, lists, blockqoutes, code blocks, etc.

    If you want to wrap a code block in a table cell in a Markdown document you will need to use raw HTML for the entire table and most likely the code block as well.

    0 讨论(0)
  • 2020-12-22 12:30

    Pandoc supports grid tables with embedded code blocks:

    +---------------+---------------+
    |               | code          |
    +===============+===============+
    | Bananas       | ```           |
    |               | foo           |
    |               | ```           |
    +---------------+---------------+
    | Apples        | ```           |
    |               | foo           |
    |               | ```           |
    +---------------+---------------+
    
    0 讨论(0)
  • 2020-12-22 12:36

    If you'd like it to stay in the same neat format and not in one line, you might need to consider another option besides a table in markdown or markdown altogether. Otherwise, you can just using the backtick (`) on the code block, like so:

    #### Table Example
    Column 1 | Column 2 | Column 3 
    --- | --- | --- 
    `public class HelloWorld {public static void main(String[] args) { System.out.println("Hello, World");}}` | random text | 1234563
    

    Feel free to put this code in an online editor and see how it looks for yourself. Play around with it until it suits your needs: http://dillinger.io/

    0 讨论(0)
提交回复
热议问题