Personal Preprocessor
May 15, 2019
This is an unsupported table hack. It adds mdtbl
and
mdtblio
codeblocks. The mdtblio
prints the
code in a text area first before processing. mdtbls are easier to write
than to read.
These table formats have been tested under pandoc 2.7 (by John MacFarlane).
The input file for this document is pandoctbl.md
, which
also includes the required CSS.
Download the pandoctbl perl code and this pandoctbl.md sample
Install the cpan module Perl6::Slurp.
Run pandoctbl pandoctbl.md -s -o pandoctbl.html
(or
pandoctbl pandoctbl.md -s --template ~/.pandoc/default.html4 -o pandoctbl.html
).
<style>
th { text-align:center; }
.celll { text-align:left; }
.cellc { text-align:center; }
.cellr { text-align:right; }
span.red { color:red; }
span.blue { color:blue; }
span.bgyellow { background-color:yellow; }
</style>
caption: table 1
---t
^ h1-left ^ h1-center ^ h1-right ^ h1-left-3col ^^^ h1-center-3col ^^^ h1-right-3col ^^^
---m
| l1 | c1 | r3 | ctr4 | ctr5 | ctr6 | ctr7 | ctr8 | ctr9 | ctr10 | ctr11 | ctr12 |
| l1 | c1 | r3 | ctr4-6 ||| ctr7-9 ||| ctr10-12 |||
| l1 | c1 | r3 | lft4-6-tres-cols ||| rght7-9-tres-cols ||| ctr10-12-tres-cols |||
---b
——————— | ————————— | ———————— | ———— | ———— | ———— | ———— | ———— | ———— | ————— | ————— | ————— |
h1-left | h1-center | h1-right | h1-left-3col | h1-center-3col | h1-right-3col | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
——————— | ————————— | ———————— | ———— | ———— | ———— | ———— | ———— | ———— | ————— | ————— | ————— |
l1 | c1 | r3 | ctr4 | ctr5 | ctr6 | ctr7 | ctr8 | ctr9 | ctr10 | ctr11 | ctr12 |
l1 | c1 | r3 | ctr4-6 | ctr7-9 | ctr10-12 | ||||||
l1 | c1 | r3 | lft4-6-tres-cols | rght7-9-tres-cols | ctr10-12-tres-cols | ||||||
——————— | ————————— | ———————— | ———— | ———— | ———— | ———— | ———— | ———— | ————— | ————— | ————— |
caption: table 2
---t
^ ^ *Roots* ^^^^
^ From X ^ square ^ cube ^ tetra ^ not ^
---m
| For 2.0 | 1.414213562 | 1.259921050 | 1.189207115 | -1.1487 |
| For 3.0 | 1.732050808 | 1.442249570 | 1.316074013 | 1.24573 |
| For 4.0 | 2 | 1.587401052 | 1.414213562 | -1.31607 |
| For 5.0 | -2.23607 | 1.587401052 | 1.414213562 | 0.0 |
---m
| left | right | both centered || right |
^^ ^ bgyellow 2 ^ blue 1 ^ 3 ^ cond 1 ^
---b
——————— | ——————————— | ——————————— | ——————————— | ———————— |
*Roots* | ||||
---|---|---|---|---|
From X | square | cube | tetra | not |
——————— | ——————————— | ——————————— | ——————————— | ———————— |
For 2.0 | 1.41 | 1.3 | 1.189 | –1.1 |
For 3.0 | 1.73 | 1.4 | 1.316 | 1.2 |
For 4.0 | 2.00 | 1.6 | 1.414 | –1.3 |
For 5.0 | –2.24 | 1.6 | 1.414 | 0.0 |
——————— | ——————————— | ——————————— | ——————————— | ———————— |
left | right | both centered | right |
A format string, applied only to numbers in cells (strings are ignored), can be attached by starting a line with two carets (^^). A standalone number in the field is interpreted as digits after the decimal point. A string of at least two characters is interpreted as css. The “cond” string has special meaning: It attaches “blue” to positives, “red” to negatives, and “black to zero.
This works by outputting both a =latex
and a
=html
codeblock. The pandoc pass will process and then
remove the useless one.
The table format is very flexible.
You can abuse the left/center/right spacing to format individual
cells in individual ways. Just redefine the latex macro and the html
css. For example, you could define cellr
not only to
text-justify right, but also to italicize and overstrike and this would
apply only in those cells that start with at least two spaces and end
with exactly one space..
You could define a column style of ’overstrike and have every number in such columns be overstruck via css.
Rules in Tables
In html output, the table rules are simply replaced by emdashes according to the largest entry in all cells in this column. There is no intelligence about colspan spanning.
There is no support for clines. The obvious code would be
---2-4
. The problem is deciding how many dashes should be
added in html.
LaTeX tables could be more intelligent in terms of nice output formatting.
We want a realignment utility (for readability) md to md processor
I am uncertain whether tabs should be expanded into spaces first.