MIT licensed by Albert Krewinkel
Maintained by Albert Krewinkel
This version can be pinned in stack with:gridtables-0.1.0.0@sha256:20f6faa3d75724133253d970daee8ee1e6fb77841d4be4e82273168e22f7c42b,2975

Module documentation for 0.1.0.0

Used by 1 package in lts-22.33(full list with versions):

gridtables

Parser for reStructuredText-style grid tables.

This package provides a parser for plain-text representations of tables, like the one given below.

+---------------------+-----------------------+
| Location            | Temperature 1961-1990 |
|                     | in degree Celsius     |
|                     +-------+-------+-------+
|                     | min   | mean  | max   |
+=====================+=======+=======+=======+
| Antarctica          | -89.2 | N/A   | 19.8  |
+---------------------+-------+-------+-------+
| Earth               | -89.2 | 14    | 56.7  |
+---------------------+-------+-------+-------+

Character widths

The tables are intended to look good when viewed in a monospace font. Therefore, wide and full-width characters, as those in East Asian scripts, are counted as two characters, while zero-width and combining characters are treated as if they have no width.

Column alignments

The parser re-implements a table extensions from John MacFarlane’s pandoc, namely support for column-wide cell alignments. The alignment of cells is determined by placing colons in the row that separates the table head from the body, like so:

+------+--------+-------+
| left | center | right |
+:=====+:======:+======:+
| 1    | 2      | 3     |
+------+--------+-------+

The first line must be used for headless tables:

+:-----+:------:+------:+
| left | center | right |
+------+--------+-------+
| a 1  | b 2    | c 3   |
+------+--------+-------+

Table Foot

This library implements an extension that enables to create tables with table foots: If the last separator line is a part separator, i.e., if it consists of = instead of -, then all rows after the second-to-last part separator are treated as the table foot.

E.g., consider the following table:

+------+-------+
| Item | Price |
+======+=======+
| Eggs | 5£    |
+------+-------+
| Spam | 3£    |
+======+=======+
| Sum  | 8£    |
+======+=======+

Here, the last row, containing “Sum” and “8£”, would be the table foot.

Algorithm

The cell tracing algorithm used in this package has been translated from the original Python implementation for reStructuredText. The parser has been placed in the public domain.

Usage

The usual way to use this package will be to use it as part of a parsec parser:

main :: IO ()
main = do
  let gt = T.unlines
           [ "+------+--------+-------+"
           , "| left | center | right |"
           , "+:=====+:======:+======:+"
           , "| 1    | 2      | 3     |"
           , "+------+--------+-------+"
           ]
  in print (runParser GT.gridTable () "table" gt)

Use traceLines :: [Text] -> Maybe (GridTable [Text]), if the table’s raw lines have been retrieved in a different way.

Changes

Changelog

gridtables uses PVP Versioning.

gridtables-0.1.0.0

Release pending.

  • Added support for table foots.

gridtables-0.0.3.0

Released 2022-08-18.

  • Missing cells no longer cause an error, but are replaced with empty cells.

  • The borders of the last cell in a row are allowed to be shorter than the cell. Previously the last column was discarded in that case.

gridtables-0.0.2.0

Released 2022-07-30.

  • Treat “combining” Unicode characters, such as the zero-width space or the word joiner, as having no width.

gridtables-0.0.1.0

Released 2022-07-29.

  • Boldly going where no Haskell library has gone before.