Text.Pandoc.Builder

pandoc-types-1.17.0.5: Types for representing a structured document

Copyright | Copyright (C) 2010-2016 John MacFarlane
License | BSD3
Maintainer | John MacFarlane <jgm@berkeley.edu>
Stability | alpha
Portability | portable
Safe Haskell | None
Language | Haskell98

Text.Pandoc.Builder

Contents

- Document builders
- Inline list builders
- Block list builders

Description

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")
                 ]

Isn't that nicer than writing the following?

    import Text.Pandoc.Definition
    import Data.Map (fromList)

    myDoc :: Pandoc
    myDoc = Pandoc (Meta {unMeta = fromList [("title",
              MetaInlines [Str "My",Space,Str "title"])]})
            [Para [Str "This",Space,Str "is",Space,Str "the",Space,Str "first",
             Space,Str "paragraph"],Para [Str "And",Space,Emph [Str "another"],
             Str "."]
            ,BulletList [
              [Para [Str "item",Space,Str "one"]
              ,Para [Str "continuation"]]
             ,[Plain [Str "item",Space,Str "two",Space,Str "and",Space,
                      Str "a",Space,Link nullAttr [Str "link"] ("/url","go to url")]]]]

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

Synopsis

- module Text.Pandoc.Definition
- newtype Many a = Many {
  - unMany :: Seq a
  }
- type Inlines = Many Inline
- type Blocks = Many Block
- (<>) :: Monoid m => m -> m -> m
- singleton :: a -> Many a
- toList :: Many a -> [a]
- fromList :: [a] -> Many a
- isNull :: Many a -> Bool
- doc :: Blocks -> Pandoc
- class ToMetaValue a where
- class HasMeta a where
- setTitle :: Inlines -> Pandoc -> Pandoc
- setAuthors :: [Inlines] -> Pandoc -> Pandoc
- setDate :: Inlines -> Pandoc -> Pandoc
- text :: String -> Inlines
- str :: String -> Inlines
- emph :: Inlines -> Inlines
- strong :: Inlines -> Inlines
- strikeout :: Inlines -> Inlines
- superscript :: Inlines -> Inlines
- subscript :: Inlines -> Inlines
- smallcaps :: Inlines -> Inlines
- singleQuoted :: Inlines -> Inlines
- doubleQuoted :: Inlines -> Inlines
- cite :: [Citation] -> Inlines -> Inlines
- codeWith :: Attr -> String -> Inlines
- code :: String -> Inlines
- space :: Inlines
- softbreak :: Inlines
- linebreak :: Inlines
- math :: String -> Inlines
- displayMath :: String -> Inlines
- rawInline :: String -> String -> Inlines
- link :: String -> String -> Inlines -> Inlines
- linkWith :: Attr -> String -> String -> Inlines -> Inlines
- image :: String -> String -> Inlines -> Inlines
- imageWith :: Attr -> String -> String -> Inlines -> Inlines
- note :: Blocks -> Inlines
- spanWith :: Attr -> Inlines -> Inlines
- trimInlines :: Inlines -> Inlines
- para :: Inlines -> Blocks
- plain :: Inlines -> Blocks
- lineBlock :: [Inlines] -> Blocks
- codeBlockWith :: Attr -> String -> Blocks
- codeBlock :: String -> Blocks
- rawBlock :: String -> String -> Blocks
- blockQuote :: Blocks -> Blocks
- bulletList :: [Blocks] -> Blocks
- orderedListWith :: ListAttributes -> [Blocks] -> Blocks
- orderedList :: [Blocks] -> Blocks
- definitionList :: [(Inlines, [Blocks])] -> Blocks
- header :: Int -> Inlines -> Blocks
- headerWith :: Attr -> Int -> Inlines -> Blocks
- horizontalRule :: Blocks
- table :: Inlines -> [(Alignment, Double)] -> [Blocks] -> [[Blocks]] -> Blocks
- simpleTable :: [Blocks] -> [[Blocks]] -> Blocks
- divWith :: Attr -> Blocks -> Blocks

# Documentation

module Text.Pandoc.Definition

newtype Many a #

Constructors

Many |
Fields unMany :: Seq a

Instances

Functor Many # |
Methods fmap :: (a -> b) -> Many a -> Many b # (<$) :: a -> Many b -> Many a #
IsString Inlines # |
Methods fromString :: String -> Inlines #
Foldable Many # |
Methods fold :: Monoid m => Many m -> m # foldMap :: Monoid m => (a -> m) -> Many a -> m # foldr :: (a -> b -> b) -> b -> Many a -> b # foldr' :: (a -> b -> b) -> b -> Many a -> b # foldl :: (b -> a -> b) -> b -> Many a -> b # foldl' :: (b -> a -> b) -> b -> Many a -> b # foldr1 :: (a -> a -> a) -> Many a -> a # foldl1 :: (a -> a -> a) -> Many a -> a # toList :: Many a -> [a] # null :: Many a -> Bool # length :: Many a -> Int # elem :: Eq a => a -> Many a -> Bool # maximum :: Ord a => Many a -> a # minimum :: Ord a => Many a -> a # sum :: Num a => Many a -> a # product :: Num a => Many a -> a #
Traversable Many # |
Methods traverse :: Applicative f => (a -> f b) -> Many a -> f (Many b) # sequenceA :: Applicative f => Many (f a) -> f (Many a) # mapM :: Monad m => (a -> m b) -> Many a -> m (Many b) # sequence :: Monad m => Many (m a) -> m (Many a) #
Monoid Inlines # |
Methods mempty :: Inlines # mappend :: Inlines -> Inlines -> Inlines # mconcat :: [Inlines] -> Inlines #
ToMetaValue Blocks # |
Methods toMetaValue :: Blocks -> MetaValue #
ToMetaValue Inlines # |
Methods toMetaValue :: Inlines -> MetaValue #
Eq a => Eq (Many a) # |
Methods (==) :: Many a -> Many a -> Bool # (/=) :: Many a -> Many a -> Bool #
Data a => Data (Many a) # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Many a -> c (Many a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Many a) # toConstr :: Many a -> Constr # dataTypeOf :: Many a -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Many a)) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Many a)) # gmapT :: (forall b. Data b => b -> b) -> Many a -> Many a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Many a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Many a -> r # gmapQ :: (forall d. Data d => d -> u) -> Many a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Many a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Many a -> m (Many a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Many a -> m (Many a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Many a -> m (Many a) #
Ord a => Ord (Many a) # |
Methods compare :: Many a -> Many a -> Ordering # (<) :: Many a -> Many a -> Bool # (<=) :: Many a -> Many a -> Bool # (>) :: Many a -> Many a -> Bool # (>=) :: Many a -> Many a -> Bool # max :: Many a -> Many a -> Many a # min :: Many a -> Many a -> Many a #
Read a => Read (Many a) # |
Methods readsPrec :: Int -> ReadS (Many a) # readList :: ReadS [Many a] # readPrec :: ReadPrec (Many a) # readListPrec :: ReadPrec [Many a] #
Show a => Show (Many a) # |
Methods showsPrec :: Int -> Many a -> ShowS # show :: Many a -> String # showList :: [Many a] -> ShowS #
Generic (Many a) # |
Associated Types type Rep (Many a) :: * -> * # Methods from :: Many a -> Rep (Many a) x # to :: Rep (Many a) x -> Many a #
Monoid (Many Block) # |
Methods mempty :: Many Block # mappend :: Many Block -> Many Block -> Many Block # mconcat :: [Many Block] -> Many Block #
type Rep (Many a) # |
type Rep (Many a) = D1 (MetaData "Many" "Text.Pandoc.Builder" "pandoc-types-1.17.0.5-Fs9knDTXyPJ11ecqtheA3E" True) (C1 (MetaCons "Many" PrefixI True) (S1 (MetaSel (Just Symbol "unMany") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Seq a))))

type Inlines = Many Inline #

type Blocks = Many Block #

(<>) :: Monoid m => m -> m -> m infixr 6 #

An infix synonym for `mappend`.

Since: 4.5.0.0

singleton :: a -> Many a #

toList :: Many a -> [a] #

fromList :: [a] -> Many a #

isNull :: Many a -> Bool #

# Document builders

doc :: Blocks -> Pandoc #

class ToMetaValue a where #

Minimal complete definition

toMetaValue

Methods

toMetaValue :: a -> MetaValue #

Instances

ToMetaValue Bool # |
Methods toMetaValue :: Bool -> MetaValue #
ToMetaValue MetaValue # |
Methods toMetaValue :: MetaValue -> MetaValue #
ToMetaValue Blocks # |
Methods toMetaValue :: Blocks -> MetaValue #
ToMetaValue Inlines # |
Methods toMetaValue :: Inlines -> MetaValue #
ToMetaValue a => ToMetaValue [a] # |
Methods toMetaValue :: [a] -> MetaValue #
ToMetaValue a => ToMetaValue (Map String a) # |
Methods toMetaValue :: Map String a -> MetaValue #

class HasMeta a where #

Minimal complete definition

setMeta, deleteMeta

Methods

setMeta :: ToMetaValue b => String -> b -> a -> a #

deleteMeta :: String -> a -> a #

Instances

HasMeta Meta # |
Methods setMeta :: ToMetaValue b => String -> b -> Meta -> Meta # deleteMeta :: String -> Meta -> Meta #
HasMeta Pandoc # |
Methods setMeta :: ToMetaValue b => String -> b -> Pandoc -> Pandoc # deleteMeta :: String -> Pandoc -> Pandoc #

setTitle :: Inlines -> Pandoc -> Pandoc #

setAuthors :: [Inlines] -> Pandoc -> Pandoc #

setDate :: Inlines -> Pandoc -> Pandoc #

# Inline list builders

text :: String -> Inlines #

Convert a `String` to `Inlines`, treating interword spaces as `Space`s or `SoftBreak`s. If you want a `Str` with literal spaces, use `str`.

str :: String -> Inlines #

emph :: Inlines -> Inlines #

strong :: Inlines -> Inlines #

strikeout :: Inlines -> Inlines #

superscript :: Inlines -> Inlines #

subscript :: Inlines -> Inlines #

smallcaps :: Inlines -> Inlines #

singleQuoted :: Inlines -> Inlines #

doubleQuoted :: Inlines -> Inlines #

cite :: [Citation] -> Inlines -> Inlines #

codeWith :: Attr -> String -> Inlines #

Inline code with attributes.

code :: String -> Inlines #

Plain inline code.

space :: Inlines #

softbreak :: Inlines #

linebreak :: Inlines #

math :: String -> Inlines #

Inline math

displayMath :: String -> Inlines #

Display math

rawInline :: String -> String -> Inlines #

link #

Arguments

:: String | URL
-> String | Title
-> Inlines | Label
-> Inlines |

linkWith #

Arguments

:: Attr | Attributes
-> String | URL
-> String | Title
-> Inlines | Label
-> Inlines |

image #

Arguments

:: String | URL
-> String | Title
-> Inlines | Alt text
-> Inlines |

imageWith #

Arguments

:: Attr | Attributes
-> String | URL
-> String | Title
-> Inlines | Alt text
-> Inlines |

note :: Blocks -> Inlines #

spanWith :: Attr -> Inlines -> Inlines #

trimInlines :: Inlines -> Inlines #

Trim leading and trailing spaces and softbreaks from an Inlines.

# Block list builders

para :: Inlines -> Blocks #

plain :: Inlines -> Blocks #

lineBlock :: [Inlines] -> Blocks #

codeBlockWith :: Attr -> String -> Blocks #

A code block with attributes.

codeBlock :: String -> Blocks #

A plain code block.

rawBlock :: String -> String -> Blocks #

blockQuote :: Blocks -> Blocks #

bulletList :: [Blocks] -> Blocks #

orderedListWith :: ListAttributes -> [Blocks] -> Blocks #

Ordered list with attributes.

orderedList :: [Blocks] -> Blocks #

Ordered list with default attributes.

definitionList :: [(Inlines, [Blocks])] -> Blocks #

header #

Arguments

:: Int | Level
-> Inlines |
-> Blocks |

headerWith :: Attr -> Int -> Inlines -> Blocks #

horizontalRule :: Blocks #

table #

Arguments

:: Inlines | Caption
-> [(Alignment, Double)] | Column alignments and fractional widths
-> [Blocks] | Headers
-> [[Blocks]] | Rows
-> Blocks |

simpleTable #

Arguments

:: [Blocks] | Headers
-> [[Blocks]] | Rows
-> Blocks |

A simple table without a caption.

divWith :: Attr -> Blocks -> Blocks #