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;
}
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
blog
TODO: Wiki pages could use conversion
ul-table
Featuresul-table
and inline HTML
ul-table
, but other rows use raw <tr>
<td-attrs class=foo />
in a tr
section<td-attrs class=foo />
in the thead
sectiontr <tr-attrs class=foo />
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 or invisible character:
- tr
- <!-- empty -->
- above is OK
- tr
-
- also OK
As similar issue is that line breaks affect backtick expansion to <code>
:
- tr
- <td-attrs /> <!-- we need something on this line -->
... More `proc` features ...
I think this is also because <td-attrs />
doesn't "count" as text, so the
list item is considered empty.
(2) Likewise, a cell with a literal hyphen may need a comment in front of it:
- tr
- <!-- hyphen --> -
- <!-- hyphen --> -
<th>
is like <td>
, but it belongs in <thead><tr>
. Browsers make it
bold and centered.class=
on <colgroup>
and <col>
and align columns left and
right.
class=
on every <td>
cell instead.ul-table
solves this with "inherited" <td-attrs />
in the thead
section.(1) Why do row with attributes look like tr <tr-attrs />
? The first tr
looks redundant.
This is because of the CommonMark quirk above: a list item without text is
treated as empty. So we require the extra tr
text.
It's also consistent with plain rows, without attributes.
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