Skip to content

Conversation

@TuongNM
Copy link
Contributor

@TuongNM TuongNM commented Nov 2, 2025

This adds the following table features:

In addition to handling row spans in headers and footer as described in #7326 (comment) I also had to handle row spans over empty rows. You can't really write an empty row in asciidoc but a row span that would go into an empty row still has to be handled. Otherwise the row span wouldn't add up.
I made those row spans basically consume empty rows. Whenever there are row spans that would go over an empty row, that empty row is removed and the row span is decremented. This corrects the row span count in the asciidoc output and handles empty rows.
Any empty rows that remain get filled up with empty columns.

T.P.Writers.Shared: Add functions allRowsEmpty and tableBodiesToRows from the RST writer for reuse in the asciidoc writer.

I got hlint warnings about NonEmpty and unzip: Currently NonEmpty exports a polymorphic unzip function but that will become monomorphic in base-4.22 (https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-List-NonEmpty.html#v:unzip). To avoid any hassles in the future I restricted the NonEmpty imports so that the Prelude unzip function is used.

Fixes: #7326
Fixes: #8199

@TuongNM TuongNM force-pushed the asciidoc-writer-add-more-table-features branch 2 times, most recently from 200a7d1 to a44e399 Compare November 2, 2025 16:00
@jgm
Copy link
Owner

jgm commented Nov 3, 2025

This is great! Two suggestions:

  • Mark the commit with [API change] on the new Shared exports.
  • Could we use HTML instead of native for the source tables in the new command test, just to cut down its size?

This adds the following table features:
- row span and column span
- footer row
- individual horizontal cell alignment

[API change] T.P.Writers.Shared:
Add functions `allRowsEmpty` and
`tableBodiesToRows` from the RST writer for
reuse in other writers.

Also fix hlint warning about `unzip` from `NonEmpty`:
The exported polymorphic function will become
monomorphic in the future. Restrict the `NonEmpty`
import to use the Prelude `unzip` function.
@TuongNM TuongNM force-pushed the asciidoc-writer-add-more-table-features branch from a44e399 to a7e4585 Compare November 3, 2025 18:39
@TuongNM
Copy link
Contributor Author

TuongNM commented Nov 3, 2025

I added the missing [API change] into the commit message (one of these days I will remember to do it beforehand).

I replaced most of the source tables with HTML. I kept the test for cell aligments native due to the HTML reader inferring default column alignments that I don't think fit a test about individual cell alignments.

I also kept the test for empty rows native due to the HTML reader proactively adding empty cells rather than keeping the row empty.

This HTML table:

<table>
  <tr>
    <td>Body 1</td>
  </tr>
  <tr></tr>
  <tr>
    <td>Body 2</td>
  </tr>
</table>

gets parsed as:

[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignDefault , ColWidthDefault ) ]
    (TableHead ( "" , [] , [] ) [])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 0)
        []
        [ Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Body" , Space , Str "1" ] ]
            ]
        , Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] ) AlignDefault (RowSpan 1) (ColSpan 1) []
            ]
        , Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Body" , Space , Str "2" ] ]
            ]
        ]
    ]
    (TableFoot ( "" , [] , [] ) [])
]

Is this a bug? I don't think it's correct that an empty row is parsed as a row with an empty cell.

@TuongNM
Copy link
Contributor Author

TuongNM commented Nov 3, 2025

I also noticed that the HTML writer is not preserving the empty row.

This native table:

[ Table
    ( "" , [] , [] )
    (Caption Nothing [])
    [ ( AlignDefault , ColWidthDefault )
    ]
    (TableHead ( "" , [] , [] ) [])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 0)
        []
        [ Row
            ( "" , [] , [] )
            [ Cell
                ( "" , [] , [] )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Body" ] ]
            ]
        , Row ( "" , [] , [] ) []
        ]
    ]
    (TableFoot ( "" , [] , [] ) [])
]

is converted to this HTML table:

<table>
  <tbody>
    <tr>
      <td>Body</td>
    </tr>
    <tr>
      <td></td>
    </tr>
  </tbody>
</table>

I also don't think that this is right either. The empty row should be preserved, right?

@jgm
Copy link
Owner

jgm commented Nov 3, 2025

I agree that these things seem like bugs, but there might be a reason for them that I've either forgotten or never knew (because someone else wrote that code).
Feel free to open new issues for them!

@jgm jgm merged commit 594f109 into jgm:main Nov 3, 2025
11 of 14 checks passed
@TuongNM TuongNM deleted the asciidoc-writer-add-more-table-features branch November 7, 2025 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add to asciidoc writer support for tables with merged cells Table with span column and span row are not transform correctly from rst to asciidoc

2 participants