jgm / djot

A light markup language
https://djot.net
MIT License
1.62k stars 43 forks source link

Allow attributes for list items, table cells and rows #250

Open faelys opened 9 months ago

faelys commented 9 months ago

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:

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).

rauschma commented 2 months ago

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 2 months ago

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

rauschma commented 2 months ago

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 2 months ago

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

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.