Convenience functions for building pandoc documents programmatically.
Example of use (with OverloadedStrings pragma):
import Text.Pandoc.Builder
myDoc :: Pandoc
myDoc = setTitle "My title" $ doc $
para "This is the first paragraph" <>
para ("And " <> emph "another" <> ".") <>
bulletList [ para "item one" <> para "continuation"
, plain ("item two and a " <>
link "/url" "go to url" "link")
]
And of course, you can use Haskell to define your own builders:
import Text.Pandoc.Builder
import Text.JSON
import Control.Arrow ((***))
import Data.Monoid (mempty)
-- | Converts a JSON document into 'Blocks'.
json :: String -> Blocks
json x =
case decode x of
Ok y -> jsValueToBlocks y
Error y -> error y
where jsValueToBlocks x =
case x of
JSNull -> mempty
JSBool x -> plain $ text $ show x
JSRational _ x -> plain $ text $ show x
JSString x -> plain $ text $ fromJSString x
JSArray xs -> bulletList $ map jsValueToBlocks xs
JSObject x -> definitionList $
map (text *** (:[]) . jsValueToBlocks) $
fromJSObject x
Normalize the TableHead with clipRows and placeRowSection
so that when placed on a grid with the given width and a height
equal to the number of rows in the initial TableHead, there will
be no empty spaces or overlapping cells, and the cells will not
protrude beyond the grid.
Normalize the intermediate head and body section of a
TableBody, as in normalizeTableHead, but additionally ensure
that row head cells do not go beyond the row head inside the
intermediate body.
Normalize the given list of cells so that they fit on a single
grid row. The RowSpan values of the cells are assumed to be valid
(clamped to lie between 1 and the remaining grid height). The cells
in the list are also assumed to be able to fill the entire grid
row. These conditions can be met by appending repeat emptyCell
to the [Cell] list and using clipRows on the entire table
section beforehand.
Normalization follows the principle that cells are placed on a grid
row in order, each at the first available grid position from the
left, having their ColSpan reduced if they would overlap with a
previous cell, stopping once the row is filled. Only the dimensions
of cells are changed, and only of those cells that fit on the row.
Possible overlap is detected using the given [RowSpan], which
is the "overhang" of the previous grid row, a list of the heights
of cells that descend through the previous row, reckoned
only from the previous row.
Its length should be the width (number of columns) of the current
grid row.
For example, the numbers in the following headerless grid table
represent the overhang at each grid position for that table:
In any table, the row before the first has an overhang of
replicate tableWidth 1, since there are no cells to descend into
the table from there. The overhang of the first row in the example
is [1, 2, 2, 3].
So if after clipRows the unnormalized second row of that example
table were
r = [("a", 1, 2),("b", 2, 3)] -- the cells displayed as (label, RowSpan, ColSpan) only
a correct invocation of placeRowSection to normalize it would be
Ensure that the height of each cell in a table section lies
between 1 and the distance from its row to the end of the
section. So if there were four rows in the input list, the cells in
the second row would have their height clamped between 1 and 3.