RFC Spec extension for *tables*: Syntax and transformation rules

@mofosyne : Thanks for the helpful links! Here are some comments on the examples discussed there:


CSV table format with “pipes”

Might you also be interested in this other thread, on a proposal for a restricted subset of pipe syntax as an alternative to CSV?

Nonwithstanding the question if and how colon “:” should and could be used in CommonMark “table block”, the “example spreadsheet” would be recognized and parsed according to the CommonMark table rules I proposed (with the exception of “:”, discussed later).

The resulting element structure should be (remember that I cobble together these HTML results by hand—so the usual disclaimers apply!):

<table><tbody>
  <tr><td>Tables</td><td>Are</td><td>Cool</td></tr>
  <tr><td>col 1 is</td><td>leftaligned</td><td>$1600</td></tr>
  <tr><td>col 1 is</td><td>centered</td><td>$12</td></tr>
  <tr><td>col 1 is</td><td>right-aligned</td><td>$1</td></tr>
</tbody></table>

Note that

  1. the “:” have been ignored here (they could obviously translate into an “appropriate” attribute in the <td> elements);

  2. because the “table ruler line” uses only “-” (and not “=”), the first row in the CommonMark table will be placed into the table body, and leave the table heading (the <thead> element of HTML) omitted (the default).

If the row containing “Tables”, “Are”, and “Coolshould form a table heading row (HTML <thead> element) in the output, the table rule line could be re-written as

|=---------|:-------------:|------:|

[NOTE: Well, my current wording says the table rule line should only contain either=or-”, but that’s just a preliminary rule after all, right? :wink: ]

But CSV has no concept of table heading row anyway, IIRC …

To summarize: The difference between “CSV table” and “HTML table” (or “DocBook table” etc) boils down not to differences in CommonMark parsing or input syntax, but to differences in the generated output element structure and their rendering, as far as I can tell.


Tables in pure Markdown

Also talks about tables in

this discussion, which has various suggestions and examples of “CommonMark tables”.

The examples given by @nichtich would—as far as I understand my proposal and can “simulate” a parser—all be recognized by the proposed specification (in the current wording), again with the the same two restrictions that

  1. column-alignment using “:” is (not yet) specified;

  2. to separate off a table heading row, a table rule line must have “=”, because using “-” alone does not suffice to mark up a table heading row (in the current wording).

If this is deemed important, the specification could easily be adapted to cover these two details too—but I’m not sure right now how the “column alignment” should be mapped into the output element structure.


On the other hand, your (@mofosyne’s) own table example given in the discussion over there:

A header           | Another header      |   Price
====================================================
Some text here     | Another bit of text |    34,10
Lorem ipsum        | In principo creavit |    624,45
----------------------------------------------------
||                                   Total:   658,55

and your comment

If there is a need to distinguish headers in tables. This could be an option, of specifying thicker lines.

both reflect exactly my motivation for the distinction between “=” and “-” in table rule lines, and also nearly exactly matches my proposed syntax rules:

Which would require at least one “|” (“pipes”, or the “official” name vertical line) character in table rule lines, because otherwise eg a block of lines containing just one line having only=” as content would be detected as a table block by the syntax rules for tables:

A header           | Another header      |   Price
===================|=====================|==========
Some text here     | Another bit of text |    34,10
Lorem ipsum        | In principo creavit |    624,45
-------------------|---------------------|----------
||                                   Total:   658,55

or —

— this one:

A header | Another header | Price
|=
Some text here | Another bit of text | 34,10
Lorem ipsum | In principo creavit | 624,45
|-
|| Total:   658,55

[NOTE: I’m not sure if one shoud require the “|” to be “free-standing” in table content lines, ie separated from cell content by white space. But I certainly think the CommonMark text looks better and is easier to recognize by a human parserreader this way! ]

Any proposals for that little detail?


Open questions

Questions remaining open with regard to the examples seen so far:

  1. If and how should “:” be used and interpreted in table rule lines? (IMO: Sooner or later: yes; but maybe later than right now.)

  2. Should mixing “=” and “-” in table rule lines be allowed? (IMO: Yes!)

  3. Is the proposed requirement to use “=” in a table rule line if one wants to produce a table heading row too simple-minded? (IMO: Probably yes, in the light of “current practice”.)

  4. Should it be a requirement that “|” in “table content lines” (ie in lines in a table block which are not “table rule lines”) be separated from cell content by white space? (IMO: Probably yes.)

Kind regards,

tin-pot