Why Sponsor Oils? | source | all docs for version 0.24.0 | all versions | oilshell.org
Our ul-table
plugin allows you to write HTML tables as bulleted
lists.
Why?
<tr>
and <td>
and </td>
and </tr>
is
tedious.That is, this way of writing tables involves no new syntax. It's not a Markdown language extension.
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:
<table> <ul> <li> ... </li> </ul> </table>
structure.ul-table
plugin transforms that into a
<table> <tr> <td> </td> </tr> </table>
structure, which is a normal HTML
table.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>
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>
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.
View the source code of this table: doc/ul-table.md
Shell | Version | Example Code | ||||
bash | 5.2 |
|
||||
dash | 1.5 | Inline HTML | ||||
mksh | 4.0 |
|
||||
zsh | 3.6 | Unordered List
|
||||
yash | 1.0 | Ordered List
|
||||
This is paragraph one. This is paragraph two |
Another cell with ... ... multiple paragraphs. |
TODO
ul-table
Features<ul-col class=foo />
<colgroup>
<ul-row class=foo />
<ul-td colspan=2 />
Note: should have a custom rule of aligning numbers to right, and text to left?
I think web/table/
has that rule.
(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.
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
TODO:
doctools/ul-table.sh