Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-TABLE-122

A table converts between pipe, list-table and HTML forms without loss, or is refused with a reason

When the writer converts a table between a pipe table, a {list-table} and a simple HTML table, from the table bar, the palette or the slash menu, the extension SHALL replace it in one edit with the other form, keeping its cells, escaped pipes and header row and carrying the alignment only where the target form has it, or SHALL change nothing and give a reason ending Nothing was changed when the conversion would lose content.

Step 1 of path 1 in StRS-MDOKFSTUDIO-TABLE-013: from “The caret is on a pipe table in MyST mode” to “The table is written as a list-table”.

Scenarios 24

The situations the tests check; open one to read it.

nominalList table action: Pipe table
Giventhe caret on the delimiter line of a pipe table with a paragraph before and a table after it
WhenList table is run
Thenonly the table is replaced by a {list-table} directive in one edit, the neighbouring lines and the other table are kept, and the caret is after the new text
nominalPipe table action: List-table from any line
Giventhe caret on the opening fence, on a cell line and on the closing fence of a {list-table}, in turn
WhenPipe table is run
Theneach time the whole directive, fences included, is replaced by a pipe table
nominalA simple HTML table converts to either form
Giventhe caret in a simple HTML table written by the HTML table action
WhenList table or Pipe table is run
Thenthe table is replaced by the {list-table} form or by a pipe table
nominalThe conversion actions follow the table at the caret
InputOutcome
The caret on any line of a pipe table in MyST modeList table is available and the slash menu lists it; Pipe table is not
The caret on any line of a {list-table} (the opening fence, a cell line or the closing fence)Pipe table is available and the slash menu lists it; List table is not
The caret in a simple HTML tableBoth List table and Pipe table are available
refusalCaret elsewhere
Giventhe caret in a paragraph, or no table tools
Whenthe availability of List table and of Pipe table is read, or one of them is run
Thenneither is available and running it never throws
nominalTable bar: Convert after typing
Givena two-column pipe table with text typed in a cell and the editor open
Whenthe writer presses List table
Thenone final previewEditSave is posted whose editedText is the {list-table} form of the table, typed text included, so the whole change is one undo step
boundaryTable bar: Table in a captioned figure
Givena pipe table inside a {table} directive that renders as a figure
Whenthe bar is shown
Thenthe List table button is disabled
boundaryTable bar: A row with text after its closing pipe
Givena pipe table whose row has text after its closing pipe (see SwRS-MDOKFSTUDIO-TABLE-094)
Whenthe table bar is shown
Thenthe List table button is disabled, as the conversion would lose that text
boundaryTable bar: A cell change drops a conversion that was not saved
InputOutcome
A List table conversion prepared and its save refused by the host, then the writer types in the cell (or presses a row or column button)The next save carries the pipe table with the typed text, not the prepared conversion
No prepared conversion and the writer typesSaves carry the pipe table as usual
boundaryTable bar: Line break pasted into the cell
Givena line break pasted into the cell text box
Whenthe writer presses List table
Thenthe line break is already a space (see SwRS-MDOKFSTUDIO-TABLE-091) and the table converts in one final save
boundaryTable bar: A table inside a quote or an admonition
InputOutcome
The cell editor of a pipe table inside a blockquote, a GFM alert or a MyST admonitionThe List table button is disabled and its title says "Not available for a table inside a quote or an admonition" (see SwRS-MDOKFSTUDIO-TABLE-121)
refusalList-table that would lose content
Input ({list-table} converted to a pipe table)Outcome
A titleNo edit; reason "The list-table title would be lost in a pipe table. Nothing was changed."
YAML optionsNo edit; reason "A list-table with YAML options cannot be converted. Nothing was changed."
A :name: labelNo edit; reason "The list-table label (:name:) would be lost in a pipe table. Nothing was changed."
:header-rows: set to a wordNo edit; reason "The :header-rows: option is not a number. Nothing was changed."
A cell that continues on an indented line (multi-line or block cell)No edit; reason "A list-table cell with several lines or block content cannot be a pipe table cell. Nothing was changed."
Rows of 2 and 3 cellsNo edit; reason "The rows do not all have the same number of cells. Nothing was changed."
No rowsNo edit; reason "The list-table has no rows. Nothing was changed."
refusalHTML table that would lose content
Input (HTML table converted by List table or Pipe table)Outcome
A colspan, a class on a row, or other attributes (spans, classes, styles)No edit; reason "This HTML table has X; only a simple table converts. Nothing was changed." where X names what the table has
A nested em element in a cell (markup inside a cell)Same reason form, X names what the table has
Text between rows (text outside its cells)Same reason form, X names what the table has
An element other than table, thead, tbody, tr, th and tdSame reason form, X names the element
Rows of different lengthsNo edit; reason "The rows do not all have the same number of cells. Nothing was changed."
refusalSeveral header rows
Givena {list-table} (or an HTML table) with :header-rows: 2
WhenPipe table is run
Thenno edit is produced and the reason is "A pipe table has one header row; this table has 2. Nothing was changed."
refusalPipe table whose row has text after its closing pipe
Givena pipe table with a token after the closing pipe of a row, such as "| alpha | 1 | ^row-a"
Whenit is converted to a list-table (the HTML table action of SwRS-MDOKFSTUDIO-TABLE-117 gives no edit and no reason)
Thenno edit is produced and the reason is "A row has text after its closing pipe that would be lost. Nothing was changed."
refusalTable already in the target form
Givena pipe table converted to a pipe table, and a list-table converted to a list-table (directly through the conversion function)
Whenthe conversion is requested
Thenthe result is a refusal with the sentence "This is already a pipe table." or "This is already a list-table."
boundaryText that is no table
InputOutcome
A paragraph of textThe result is neither a conversion nor a reason (undefined)
An empty stringThe result is neither a conversion nor a reason (undefined)
nominalTables that convert
InputOutcome
A {list-table} of equal rows, with or without :header-rows: and a :widths: optionThe conversion to a pipe table succeeds
A simple HTML table whose cells carry only align="left", "center" or "right"The conversion succeeds
The same list-table with :header-rows: 1The conversion to a pipe table succeeds
A list-table converted to a pipe table (the other form)The conversion is done
nominalPipe table to list-table
InputOutcome
A pipe table with a header and one body rowThe result opens with a three-backtick {list-table} fence, carries :header-rows: 1 and has one "* -" row per row, each further cell on a " -" line, closed by the same fence
A cell containing a run of three backticksThe fence has four backticks (longer than any backtick run in a cell)
nominalEscaped pipes
Givena pipe table cell containing x\|y, and a list-table cell containing a|b
Whenthe first is converted to a list-table and the second to a pipe table
Thenthe list-table item holds x|y, and the pipe table cell is written a\|b
boundaryAlignment
InputOutcome
A pipe table with a left, a centre and a right aligned column, converted to a list-tableThe list-table carries no alignment: the colons are dropped
A pipe table with plain --- delimiters, converted to a list-tableThe conversion succeeds in the same way and the result carries no alignment
An HTML table with align="left", "center" and "right" cells in its first row, converted to a pipe tableThe delimiter row is ":---", ":---:" and "---:"
A column without an align attribute, converted to a pipe tableIts delimiter cell is "---"
nominalList-table read in every fence style
InputOutcome
List-tables fenced with backticks, tildes and colons, with :widths: and :header-rows: 1, converted to pipe tablesEach gives the same pipe table and the :widths: option is dropped
A list-table without :header-rows:The pipe table has an empty header row followed by all the rows
nominalCanonical round trip
Giventhe canonical pipe tables of the lossless test ("| a | b |" with "---" delimiters, no alignment colons), with escaped pipes and empty cells
Wheneach is converted to a list-table and back
Thenthe result equals the original text
boundaryOther styles lose their style
Givena table that is padded, indented, written with long dashes or with alignment colons
Whenthe round trip is made
Thenthe result is the canonical table: padding, indentation, delimiter width and colons are lost

Implemented in 3

Tested by 9

Replaces

SwRS-MDOKFSTUDIO-TABLE-070The List table button converts the edited table in one final save superseded superseded by SwRS-MDOKFSTUDIO-TABLE-122 Markdown file
SwRS-MDOKFSTUDIO-TABLE-073List table converts the table at the caret to a list-table in one edit superseded superseded by SwRS-MDOKFSTUDIO-TABLE-122 Markdown file
SwRS-MDOKFSTUDIO-TABLE-074Pipe table converts the table at the caret to a pipe table in one edit superseded superseded by SwRS-MDOKFSTUDIO-TABLE-122 Markdown file
SwRS-MDOKFSTUDIO-TABLE-076A conversion that would lose content is refused with a reason superseded superseded by SwRS-MDOKFSTUDIO-TABLE-122 Markdown file
SwRS-MDOKFSTUDIO-TABLE-080A conversion keeps cells, escapes and alignment across forms superseded superseded by SwRS-MDOKFSTUDIO-TABLE-122 Markdown file