MyNixOS website logo
Description

Parser for reStructuredText-style grid tables.

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.

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.

Metadata

Version

0.1.0.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows