How to embed markdown in a table

I’d like to construct a three column table where each table cell contains a block of text processed by Markdown – say a list of 3-10 items or a block of code in ... .

I haven’t been able to find a clean solution for this. I’m quite certain that using Markdown tables are not the solution because of the multi-line nature of the contents.

The best I’ve been able to come up with is using shortcodes to mimic the HTML tags:

{{% mdTbl %}}
{{% mdtr %}}
{{% mdtd %}}
* markdown 
* code

json
{
    name: "wombat"
}

{{% /mdtd %}}

{{% mdtd %}}
{{% /mdtd %}}

{{% mdtd %}}
{{% /mdtd %}}

{{% /mdtr %}}
{{% /mdTbl %}}

The shortcode for mdtd is just <td>{{.Inner}}</td>.

This works, but I was hoping for something more elegant. My main complaints are the “tag bloat” of <td>...</td> turning into {{% mdtd %}}...{{% /mdtd %}} and not being able to indent to show the logical structure.

Suggestions?

Opinion: don’t use markdown to author complex tables; use HTML instead.

Option 1 - Create a unique shortcode for each table

layouts/shortcodes/
└── tables/
    ├── table-1.html
    ├── table-2.html
    └── table-3.html

Option 2 - Allow HTML in markdown

Only do this if you trust the content authors.

Site configuration:

[markup.goldmark.renderer]
unsafe = true
1 Like

Thanks for the thoughts, @jmooring.

Does your opinion change at all if the tables are simple (just a table with three columns and multiple rows) but its the content of each table cell that’s complex (and therefore I’d like to use Markdown)?

Just to verify my understanding of Option 1 – You’d have the complete table (as html) in each shortcode and then just use the shortcode to insert it in the appropriate place in the markdown file.

Option 2: Yes, I trust the authors. Already have unsafe enabled. What I haven’t been able to do, however, is something like:

<table><tr><td>
My markdown code
* one
* two 
* three
</td></tr></table>

The markdown doesn’t render.

I think If I could do the above, I’d have my answer.

Yes, your understanding is correct.

You need a blank line. See CommonMark specification, specifically the end condition for HTML blocks.

<table><tr><td>

My markdown code
* one
* two 
* three
</td></tr></table>

1 Like

Thank you!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.