gridtables: Parser for reStructuredText-style grid tables.

[ library, mit, text ] [ Propose Tags ]

Provides a parser for plain-text representations of tables. This package supports table headers, cells spanning multiple columns or rows, as well as a way to specfiy column alignments.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1.0, 0.0.2.0, 0.0.3.0, 0.1.0.0
Change log CHANGELOG.md
Dependencies array, base (>=4.12 && <5), containers, doclayout, parsec (>=3.1 && <3.2), text (>=1.1.1.0 && <1.3 || >=2.0 && <2.1) [details]
License MIT
Copyright © 2022 Albert Krewinkel
Author Albert Krewinkel
Maintainer Albert Krewinkel <albert@zeitkraut.de>
Category Text
Home page https://github.com/tarleb/gridtables
Bug tracker https://github.com/tarleb/gridtables/issues
Source repo head: git clone https://github.com/tarleb/gridtables.git
Uploaded by tarleb at 2022-07-29T08:41:55Z
Distributions Arch:0.1.0.0, Fedora:0.1.0.0, LTSHaskell:0.1.0.0, NixOS:0.1.0.0, Stackage:0.1.0.0, openSUSE:0.1.0.0
Reverse Dependencies 1 direct, 167 indirect [details]
Downloads 3736 total (161 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-07-29 [all 1 reports]

Readme for gridtables-0.0.1.0

[back to package description]

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.

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   |
+------+--------+-------+

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.