jgm/djot

Allow attributes for list items, table cells and rows

faelys opened this issue · 4 comments

faelys commented

It was a tangential point in #249: currently djot doesn't provide a way to add attributes for list items, table cells, and table rows.

The syntax would be straightforward, keeping the usual attribute syntax:

  • between final list item marker punctuation and the mandatory blank that follows,
  • right after the left-hand | of a table cell,
  • before the first | and/or (to be defined) after the final | of a table row.

Here are a few examples:

-{.bulletitem} list item
- list item

1. list titem
2.{.highlight} list item

(1){#lonelyitem} list item

| head 1 | head 2 |{.extraboldrow}
| cell 1 |{.redcell} cell 2 |
|{.bluecell} cell 3 | cell 4 |

For the table elements, the rationale is that this way the cell attributes feel "inside" the cell, while the row attributes are stuck besides the row.

With regards to row attribute placement, rows are in a weird middle-ground between blocks and inline, so there is no consistency argument for attributes before it (like blocks) or after it (like inline spans). I think source presentation is less impacted by attributes after the row, so it's my main proposition, but I don't have an opinion about also allowing them before or not.

The consistency is broken for cells, but I think "inside" is stronger than "before" or "after" in a table. Maybe sticking the attributes on the right-hand side of the cell (i.e. just before the right-hand |) would be more consistent with other span elements, but it might be confusing to have attributes on both side of the rightmost | (or maybe not, since one is really inside and the other is outside).

I’d find attributes for list items very useful.

However, maybe pipe tables should remain simple and another syntax should be used for more complex tables. I like Markdoc’s syntax. I we use a Djot div block instead of Markdoc tags, we get:

::: table
* Heading 1
* Heading 2
---
* Row 1 Cell 1
* Row 1 Cell 2
---
* Row 2 Cell 1
* Row 2 cell 2
:::

With list item attributes, this syntax becomes very flexible.

jgm commented

Or just something like a RST list table, which doesn't require anything new in the parser.

Note that the Markdoc-ish syntax doesn’t require changing the parser – it could be implemented via a filter: It’s a div block around lists that are separated by thematic breaks.

bpj commented

Note that the Markdoc-ish syntax doesn’t require changing the parser – it could be implemented via a filter: It’s a div block around lists that are separated by thematic breaks.

A two-level list to table can also be implemented as a filter. I wrote such a filter for Pandoc. Most of it is about

  • making sure that the enclosing div contains a one two-level list and an optional paragraph (caption).
  • Parsing (div) attributes and setting column widths and alignments accordingly, including converting widths from percentages to fractions (basically convert strings to numbers and divide them by 100.)

Extracting list items and converting them to table rows is rather trivial (at least when using SimpleTable as my filter does).

One of these days I'm going to rewrite my filter using re to parse width/alignment attributes allowing a "looser" format.