File: README.md

package info (click to toggle)
haskell-gridtables 0.1.0.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: haskell: 1,001; makefile: 5
file content (98 lines) | stat: -rw-r--r-- 2,870 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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:

``` haskell
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.