Skip to content

Multi-line table cell support via backslash continuation #26

@dereuromark

Description

@dereuromark

Summary

Add support for multi-line table cells using trailing backslash (\) continuation syntax. This would allow cell content to span multiple source lines for improved readability.

Proposed Syntax

Row-Level Continuation (Preferred)

Trailing \ at row end continues the entire row on the next line:

| Name   | Description                              | \
|        | This is additional content for column 2. |

Rationale for preference:

  • Cleaner visual alignment in source
  • Each line is still a complete row structure
  • Easier to parse (row-level state, not cell-level)
  • Works naturally with colspan (content goes to same logical cell)

Alternative: Cell-Level Continuation

Trailing \ before closing | continues only that cell:

| Name   | A very long description that needs to \  |
|        | continue on the next line.               |

This is more granular but requires tracking per-cell continuation state.

Content Merging

When lines are merged:

  • Strip trailing \ and surrounding whitespace
  • Join with a single space (like soft breaks in paragraphs)
  • Result: "content \n more""content more"

Interaction with Related Features

PR #8: Creole-Style Tables

Multi-line cells should work with:

  • Colspan (||): Continuation applies to the logical merged cell
  • Rowspan (|^): Continuation lines can include rowspan markers
  • Header cells (|=): Headers can span multiple lines
|= Feature    |= Long Description Header                 || \
|             |  that spans two columns and two lines    ||

Issue #18: Table Attributes

Row-level continuation should preserve attributes:

| Cell A | Cell B |{.highlight} \
|        | more B |

The {.highlight} applies to the merged row.

Cell attributes on continuation lines could either:

  • Merge with previous attributes
  • Override previous attributes
  • Be an error (simpler)

Recommendation: Only allow attributes on the first line of a continued row.

Alignment

Continuation lines inherit alignment from the separator row:

| Left   |   Center   |    Right |
|:-------|:----------:|----------|
| Short  | A longer \ |    Right |
|        | centered   |          |
|        | paragraph  |          |

Edge Cases

  1. Empty continuation cells: | \ | on continuation = skip column (use previous content only)
  2. Code spans across lines: Not supported (code spans must be single-line)
  3. Escaped backslash: \\| at line end = literal \, no continuation
  4. Trailing whitespace: | content \ | (spaces after \) = continuation
  5. Last row + caption: \ does not affect ^ caption parsing

Implementation Approach

  1. Feature flag: TableExtensions::MULTILINE_CELLS (opt-in, non-standard)
  2. Parser changes in BlockParser::tryParseTable():
    • Detect trailing \ before final |
    • Collect subsequent lines until non-continuation row
    • Merge cell contents before creating TableCell nodes
  3. Minimal renderer changes: None needed (cells receive merged content)

Why Row-Level is Preferred

Aspect Row-Level \ Cell-Level \
Parsing complexity Lower Higher
Visual alignment Better Harder to maintain
Colspan interaction Natural Ambiguous
State tracking Row-level only Per-cell state needed
Error recovery Simpler Complex

Standard Djot Spec

Per the djot specification:

"Contents of table cells are parsed as inlines."

This means:

  • Inline formatting (emphasis, links, code) works
  • Block-level content (paragraphs, lists) is NOT supported
  • Each cell is inherently single-line

So we dont change the specs, we extend it here.
For cases, where the line length would be too exceeded and such a multiline display would help the formatting/readability.

Related

Open Questions

  1. Should continuation lines require the same column count?
  2. How to handle mixed continuation + non-continuation rows?
  3. Should we support \ in caption lines?

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCenhancementNew feature or requestextrabeyond standard/specs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions