ul-table: Markdown Tables Without New Syntax

Our ul-table plugin allows you to write HTML tables as bulleted lists.

Why?

That is, this way of writing tables involves no new syntax. It's not a Markdown language extension.

Table of Contents
Simple Example
Pure Markdown Requires Tedious HTML
Stylesheet
The Untranslated Markdown
More Complex Example
Real Examples in Oils
ul-table Features
Quirks
Appendix
Related Docs
Our Style is Nicer Than Github's
CommonMark
Implemention

Simple Example

Suppose you want to make this table:

Shell Version
bash 5.2
OSH 0.25.0

With ul-table, you type a two-level Markdown list, inside <table> tags:

<table>

- thead
  - Shell
  - Version
- tr
  - [bash]($xref)
  - 5.2
- tr
  - [OSH]($xref)
  - 0.25.0

</table>

(This format looks similar to tables in reStructuredText).

The conversion takes two steps:

  1. Any Markdown translator will produce a <table> <ul> <li> ... </li> </ul> </table> structure.
  2. Our ul-table plugin transforms that into a <table> <tr> <td> </td> </tr> </table> structure, which is a normal HTML table.

Pure Markdown Requires Tedious HTML

The bulleted lists are easier to read and write! Here's the equivalent in CommonMark:

<table>
  <thead>
    <tr>
      <td>Shell</td>
      <td>Version</td>
    </tr>
  </thead>
  <tr>
    <td>

    [bash]($xref)

    </td>
    <td>5.2</td>
  </tr>
  <tr>
    <td>

    [OSH]($xref)

    </td>
    <td>0.25.0</td>
  </tr>

</table>

It uses the rule where you can embed HTML inside markdown, and then markdown inside HTML.

With ul-table, we remove this kind of mutual nesting (at least, one level of it.)


Note that HTML inside CommonMark results in an extra <p> element:

<td>
  <p>OSH</p>
</td>

In contrast, ul-table can produce:

<td>
  OSH
</td>

Stylesheet

To make the table look nice, I use <style> tags inside Markdown:

<style>
table {
  margin: 0 auto;
}
thead {
  font-weight: bold;
}
td {
  padding: 5px;
}
</style>

The Untranslated Markdown

By the way, if you omit the <table> tags, then the bulleted list looks like this:

This is how your tables will appear on sourcehut or Github — the contents are still readable. Remember, ul-table is not an extension to Markdown syntax.

More Complex Example

View the source code of this table: doc/ul-table.md

Shell Version Example Code
bash 5.2
echo sh=$bash
ls /tmp | wc -l
echo
dash 1.5 Inline HTML
mksh 4.0
HTML table inside
this table no way to re-enter inline markdown though?
zsh 3.6 Unordered List
  • one
  • two
yash 1.0 Ordered List
  1. one
  2. two

ksh

This is paragraph one.

This is paragraph two

Another cell with ...

... multiple paragraphs.

Real Examples in Oils

TODO

ul-table Features

Note: should have a custom rule of aligning numbers to right, and text to left? I think web/table/ has that rule.

Quirks

(1) CommonMark doesn't seem to allow empty list items:

- thead
  -
  - above is not rendered as a list item

A workaround is to use a comment:

- tr
  - <!-- empty -->
  - above is OK

(2) Likewise, a cell containing a hyphen may need a comment in front of it:

- tr
  - <!-- hyphen --> -
  - <!-- hyphen --> -

(3) I ran into an issue where line breaks affect backtick expansion to <code>:

- tr
  - <ul-td /> <!-- we need something on this line -->
    ... More `proc` features ...

This is probably the same as case (1), because the <ul-td /> is considered empty.

Appendix

Related Docs

Our Style is Nicer Than Github's

Github-flavored Markdown has an non-standard extension for tables:

This style is hard to read and write, especially with large tables:

| Command | Description |
| --- | --- |
| git status | List all new or modified files |
| git diff | Show file differences that haven't been staged |

Our style is less noisy and more easily editable:

- thead
  - Command
  - Description
- tr
  - git status
  - List all new or modified files
- tr
  - git diff
  - Show file differences that haven't been staged

CommonMark

Implemention

TODO:

Generated on Mon, 23 Dec 2024 17:53:29 +0000