pandoc-types-1.8: Types for representing a structured documentSource codeContentsIndex
Text.Pandoc.Builder
Portabilityportable
Stabilityalpha
MaintainerJohn MacFarlane <jgm@berkeley.edu>
Contents
Document builders
Inline list builders
Block list builders
Description

Convenience functions for building pandoc documents programmatically.

Example of use (requires the OverloadedStrings language extension):

 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

 myDoc :: Pandoc
 myDoc = Pandoc (Meta {docTitle = [Str "My",Space,Str "title"]
                      , docAuthors = []
                      , docDate = []})
  [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 [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 ((***))

 -- | 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         -> empty
            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
type Inlines = Seq Inline
type Blocks = Seq Block
toList :: Foldable t => t a -> [a]
fromList :: [a] -> Seq a
empty :: Seq a
(+++) :: Monoid a => a -> a -> a
doc :: Blocks -> Pandoc
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
emdash :: Inlines
endash :: Inlines
apostrophe :: Inlines
linebreak :: Inlines
math :: String -> Inlines
displayMath :: String -> Inlines
rawInline :: Format -> String -> Inlines
link :: String -> String -> Inlines -> Inlines
image :: String -> String -> Inlines -> Inlines
note :: Blocks -> Inlines
para :: Inlines -> Blocks
plain :: Inlines -> Blocks
codeBlockWith :: Attr -> String -> Blocks
codeBlock :: String -> Blocks
rawBlock :: Format -> String -> Blocks
blockQuote :: Blocks -> Blocks
bulletList :: [Blocks] -> Blocks
orderedListWith :: ListAttributes -> [Blocks] -> Blocks
orderedList :: [Blocks] -> Blocks
definitionList :: [(Inlines, [Blocks])] -> Blocks
header :: Int -> Inlines -> Blocks
horizontalRule :: Blocks
table :: Inlines -> [(Alignment, Double)] -> [Blocks] -> [[Blocks]] -> Blocks
simpleTable :: [Blocks] -> [[Blocks]] -> Blocks
Documentation
module Text.Pandoc.Definition
type Inlines = Seq InlineSource
type Blocks = Seq BlockSource
toList :: Foldable t => t a -> [a]Source
List of elements of a structure.
fromList :: [a] -> Seq aSource
O(n). Create a sequence from a finite list of elements. There is a function toList in the opposite direction for all instances of the Foldable class, including Seq.
empty :: Seq aSource
O(1). The empty sequence.
(+++) :: Monoid a => a -> a -> aSource
Concatenate two Inliness or two Blockss.
Document builders
doc :: Blocks -> PandocSource
setTitle :: Inlines -> Pandoc -> PandocSource
setAuthors :: [Inlines] -> Pandoc -> PandocSource
setDate :: Inlines -> Pandoc -> PandocSource
Inline list builders
text :: String -> InlinesSource
Convert a String to Inlines, treating interword spaces as Spaces. If you want a Str with literal spaces, use str.
str :: String -> InlinesSource
emph :: Inlines -> InlinesSource
strong :: Inlines -> InlinesSource
strikeout :: Inlines -> InlinesSource
superscript :: Inlines -> InlinesSource
subscript :: Inlines -> InlinesSource
smallcaps :: Inlines -> InlinesSource
singleQuoted :: Inlines -> InlinesSource
doubleQuoted :: Inlines -> InlinesSource
cite :: [Citation] -> Inlines -> InlinesSource
codeWith :: Attr -> String -> InlinesSource
Inline code with attributes.
code :: String -> InlinesSource
Plain inline code.
space :: InlinesSource
emdash :: InlinesSource
endash :: InlinesSource
apostrophe :: InlinesSource
linebreak :: InlinesSource
math :: String -> InlinesSource
Inline math
displayMath :: String -> InlinesSource
Display math
rawInline :: Format -> String -> InlinesSource
linkSource
:: StringURL
-> StringTitle
-> InlinesLabel
-> Inlines
imageSource
:: StringURL
-> StringTitle
-> InlinesAlt text
-> Inlines
note :: Blocks -> InlinesSource
Block list builders
para :: Inlines -> BlocksSource
plain :: Inlines -> BlocksSource
codeBlockWith :: Attr -> String -> BlocksSource
A code block with attributes.
codeBlock :: String -> BlocksSource
A plain code block.
rawBlock :: Format -> String -> BlocksSource
blockQuote :: Blocks -> BlocksSource
bulletList :: [Blocks] -> BlocksSource
orderedListWith :: ListAttributes -> [Blocks] -> BlocksSource
Ordered list with attributes.
orderedList :: [Blocks] -> BlocksSource
Ordered list with default attributes.
definitionList :: [(Inlines, [Blocks])] -> BlocksSource
headerSource
:: IntLevel
-> Inlines
-> Blocks
horizontalRule :: BlocksSource
tableSource
:: InlinesCaption
-> [(Alignment, Double)]Column alignments and fractional widths
-> [Blocks]Headers
-> [[Blocks]]Rows
-> Blocks
simpleTableSource
:: [Blocks]Headers
-> [[Blocks]]Rows
-> Blocks
A simple table without a caption.
Produced by Haddock version 2.6.1