Skip to content

Instantly share code, notes, and snippets.

@RichDom2185
Created November 16, 2022 01:29
Show Gist options
  • Save RichDom2185/26166ba51cf432b90a0afb04993d0640 to your computer and use it in GitHub Desktop.
Save RichDom2185/26166ba51cf432b90a0afb04993d0640 to your computer and use it in GitHub Desktop.
Create lists and other multi-line/block elements in markdown tables

Easy lists and multiline elements in Markdown tables

Note: This only works in Jekyll due to usage of Liquid syntax.

Markdown syntax only supports one line in table cells. We use Liquid (used in Jekyll) to make it easier to add lists and other elements into the markdown table.

Steps:

  1. Create the table layout using pure markdown
  2. Use a temporary string as a placeholder to substitute the variables later
  3. Use markdownify to convert the markdown table into HTML
  4. Do a simple text substitution of the placeholder text with whatever cell content we want to actually place

Example:

{% capture SUB %}
* Item 1
* Item 2
{% endcapture %}
{% assign SUB = SUB | markdownify %}

{% capture TABLE %}
| Look Below!   |
|---------------|
| :placeholder: |
{% endcapture %}

{{ TABLE
  | markdownify
  | replace: ":placeholder:", SUB
}}

Note that since the text substitution happens at the HTML step (after the markdown parsing), this means we also have to pass in the markdownify-ed table cell contents. In the above example, this step is done in line 5 (the reassignment of the SUB variable).

Result:

Look Below!
  • Item 1
  • Item 2

You can then use CSS to eliminate the extra spacing that is introduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment