{-# LANGUAGE CPP #-}

{-|
This module exports an API similar to pandoc-types' "Text.Pandoc.Builder", but
with the `simple*` versions as the default versions, and with a few extras
from "Text.Pandoc.Builder.Monadic.Veneer".

In general, Builder.simple{a} becomes Builder.Monadic.{a} and Builder.{a}
becomes Builder.Monadic.{a}'.

If you want to match the "Text.Pandoc.Builder" API more precisely, you can use
"Text.Pandoc.Builder.Monadic.Verbatim" instead.
-}

module Text.Pandoc.Builder.Monadic
  (
  -- * Monadic element builder
    Builder

  -- * Pandoc element types
  , module Text.Pandoc.Definition

  -- * Top-level
  , doc
  , setTitle
  , setAuthors
  , setDate
  , setMeta

  -- * Inline builders
  , text
  , str
  , strshow
  , emph
  , underline
  , strong
  , strikeout
  , superscript
  , subscript
  , smallcaps
  , singleQuoted
  , doubleQuoted
  , cite
  , code
  , codeWith
  , space
  , softbreak
  , linebreak
  , math
  , displayMath
  , rawInline
  , link
  , linkWith
  , image
  , imageWith
  , note
  , spanWith
  , trimInlines

  -- * Block builders
  , h1
  , h2
  , h3
  , h4
  , h5

  , para
  , plain
  , div'
  , span'
  , lineBlock
  , codeBlockWith
  , codeBlock
  , rawBlock
  , blockQuote
  , bulletList
  , orderedListWith
  , orderedList
  , definitionList
  , header
  , headerWith
  , horizontalRule
  , cell
  , cell'
  , emptyCell
  , cellWith
  , table
  , table'
  , tableWithColspec
  , tableWith
  , tableWith'
#if MIN_VERSION_pandoc_types(1,23,0)
  , figure
  , figureWith
#endif
  , caption
  , caption'
  , emptyCaption
#if MIN_VERSION_pandoc_types(1,22,1)
  , imgFigure
  , imgFigureWith
#endif
  , divWith

  -- * Table processing
  , normalizeTableHead
  , normalizeTableBody
  , normalizeTableFoot
  , placeRowSection
  , clipRows
  ) where

import Text.Pandoc.Definition
import Data.Text                            (Text)
import Text.Pandoc.Builder.Monadic.Verbatim hiding
  ( simpleCell, cell, table, simpleTable
  , caption, simpleCaption
#if MIN_VERSION_pandoc_types(1,22,1)
  , simpleFigure
  , simpleFigureWith
#endif
  , tableWith
  )
import Text.Pandoc.Builder.Monadic.Internal (tellOne, runToList)
import Text.Pandoc.Builder.Monadic.Veneer

import qualified Text.Pandoc.Builder.Monadic.Verbatim as V

-- | Build a 1x1 cell with default alignment, given some pandoc.
-- Same as 'Text.Pandoc.Builder.Monadic.Verbatim.simpleCell'.
cell :: Builder Block -> Cell
cell :: Builder Block -> Cell
cell = Builder Block -> Cell
V.simpleCell

-- | Build a cell of a table, full API excluding attributes.
-- Same as 'Text.Pandoc.Builder.Monadic.Verbatim.cell'.
cell' :: Alignment -> RowSpan -> ColSpan -> Builder Block -> Cell
cell' :: Alignment -> RowSpan -> ColSpan -> Builder Block -> Cell
cell' = Alignment -> RowSpan -> ColSpan -> Builder Block -> Cell
V.cell

-- | Build a table, given a list of header cells, and a list of rows.
-- Same as 'Text.Pandoc.Builder.Monadic.Verbatim.simpleTable'.
table :: [Builder Block] -> [[Builder Block]] -> Builder Block
table :: [Builder Block] -> [[Builder Block]] -> Builder Block
table = [Builder Block] -> [[Builder Block]] -> Builder Block
V.simpleTable

-- | Build a table, given attributes, a list of header cells, and a list of rows.
-- This is equivalent to 'Text.Pandoc.Builder.Monadic.Verbatim.simpleTable' with
-- attributes.
tableWith :: Attr -> [Builder Block] -> [[Builder Block]] -> Builder Block
tableWith :: Attr -> [Builder Block] -> [[Builder Block]] -> Builder Block
tableWith Attr
attr [Builder Block]
headings [[Builder Block]]
body =
  case Builder Block -> [Block]
forall el. Builder el -> [el]
runToList (Builder Block -> [Block]) -> Builder Block -> [Block]
forall a b. (a -> b) -> a -> b
$ [Builder Block] -> [[Builder Block]] -> Builder Block
table [Builder Block]
headings [[Builder Block]]
body of
    [Table Attr
_ Caption
a [ColSpec]
b TableHead
c [TableBody]
d TableFoot
e] -> Block -> Builder Block
forall a. a -> Builder a
tellOne (Block -> Builder Block) -> Block -> Builder Block
forall a b. (a -> b) -> a -> b
$ Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr Caption
a [ColSpec]
b TableHead
c [TableBody]
d TableFoot
e
    [Block]
_ -> [Char] -> Builder Block
forall a. HasCallStack => [Char] -> a
error [Char]
"Invariant broken. Table builder didn't return one element."

-- | Build a table, full API excluding attributes.
-- Same as 'Text.Pandoc.Builder.Monadic.Verbatim.table'.
table'
  :: Caption
  -> [ColSpec]
  -> TableHead
  -> [TableBody]
  -> TableFoot
  -> Builder Block
table' :: Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Builder Block
table' = Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Builder Block
V.table

-- | Build a table, full API including attributes.
-- Same as 'Text.Pandoc.Builder.Monadic.Verbatim.tableWith'.
tableWith'
  :: Attr
  -> Caption
  -> [ColSpec]
  -> TableHead
  -> [TableBody]
  -> TableFoot
  -> Builder Block
tableWith' :: Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Builder Block
tableWith' = Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Builder Block
V.tableWith

-- | Make a caption, without a short version.
-- Same as 'Text.Pandoc.Builder.Monadic.Verbatim.simpleCaption'.
caption :: Builder Block -> Caption
caption :: Builder Block -> Caption
caption = Builder Block -> Caption
V.simpleCaption

-- | Make a caption, with an optional short version.
-- Same as 'Text.Pandoc.Builder.Monadic.Verbatim.caption'.
caption' :: Maybe ShortCaption -> Builder Block -> Caption
caption' :: Maybe ShortCaption -> Builder Block -> Caption
caption' = Maybe ShortCaption -> Builder Block -> Caption
V.caption

#if MIN_VERSION_pandoc_types(1,22,1)
-- | Build a captioned figure, containing an image.
-- This is available in pandoc-types >= 1.22.1, which corresponds to pandoc >= 2.15.
imgFigure :: Builder Inline -> Text -> Text
                  -> Builder Block
imgFigure :: Builder Inline -> Text -> Text -> Builder Block
imgFigure = Builder Inline -> Text -> Text -> Builder Block
V.simpleFigure

-- | Build a captioned figure containing an image, with attributes.
-- This is available in pandoc-types >= 1.22.1, which corresponds to pandoc >= 2.15.
imgFigureWith :: Attr -> Builder Inline -> Text -> Text -> Builder Block
imgFigureWith :: Attr -> Builder Inline -> Text -> Text -> Builder Block
imgFigureWith = Attr -> Builder Inline -> Text -> Text -> Builder Block
V.simpleFigureWith
#endif