Copyright | Copyright (C) 2010 John MacFarlane |
---|---|
License | GNU GPL, version 2 or above |
Maintainer | John MacFarlane <jgm@berkeley.edu> |
Stability | alpha |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
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 [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
- module Text.Pandoc.Definition
- newtype Many a = Many {}
- 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
- toMetaValue :: a -> MetaValue
- class HasMeta a where
- setMeta :: ToMetaValue b => String -> b -> a -> a
- deleteMeta :: String -> a -> a
- 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
- numRef :: NumberedReference -> String -> Inlines
- codeWith :: Attr -> String -> Inlines
- code :: String -> Inlines
- space :: Inlines
- linebreak :: Inlines
- math :: String -> Inlines
- displayMath :: String -> Inlines
- displayMathWith :: Attr -> String -> Inlines
- rawInline :: String -> String -> Inlines
- link :: 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
- 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
- imageGrid :: [Inlines] -> Blocks
- figure :: FigureType -> Attr -> PreparedContent -> Blocks -> Inlines -> Blocks
- statement :: String -> StatementStyle -> (Inlines, String) -> String -> Int -> String -> Inlines -> Blocks -> Blocks
- proof :: Inlines -> Blocks -> Blocks
- divWith :: Attr -> Blocks -> Blocks
Documentation
module Text.Pandoc.Definition
Functor Many | |
IsString Inlines | |
Foldable Many | |
Traversable Many | |
Monoid Inlines | |
ToMetaValue Blocks | |
ToMetaValue Inlines | |
Eq a => Eq (Many a) | |
Data a => Data (Many a) | |
Ord a => Ord (Many a) | |
Read a => Read (Many a) | |
Show a => Show (Many a) | |
Generic (Many a) | |
Monoid (Many Block) | |
Typeable (* -> *) Many | |
type Rep (Many a) |
Document builders
class ToMetaValue a where Source
toMetaValue :: a -> MetaValue Source
ToMetaValue Bool | |
ToMetaValue MetaValue | |
ToMetaValue Blocks | |
ToMetaValue Inlines | |
ToMetaValue a => ToMetaValue [a] | |
ToMetaValue a => ToMetaValue (Map String a) |
setMeta :: ToMetaValue b => String -> b -> a -> a Source
deleteMeta :: String -> a -> a Source
setAuthors :: [Inlines] -> Pandoc -> Pandoc Source
Inline list builders
superscript :: Inlines -> Inlines Source
singleQuoted :: Inlines -> Inlines Source
doubleQuoted :: Inlines -> Inlines Source
numRef :: NumberedReference -> String -> Inlines Source
displayMath :: String -> Inlines Source
Display math
displayMathWith :: Attr -> String -> Inlines Source
Display math with attributes
Image element with additional attributes
trimInlines :: Inlines -> Inlines Source
Trim leading and trailing Sp (spaces) from an Inlines.
Block list builders
codeBlockWith :: Attr -> String -> Blocks Source
A code block with attributes.
blockQuote :: Blocks -> Blocks Source
bulletList :: [Blocks] -> Blocks Source
orderedListWith :: ListAttributes -> [Blocks] -> Blocks Source
Ordered list with attributes.
orderedList :: [Blocks] -> Blocks Source
Ordered list with default attributes.
definitionList :: [(Inlines, [Blocks])] -> Blocks Source
imageGrid :: [Inlines] -> Blocks Source
A column of rows of images, forming a grid (used for figures)
:: FigureType | |
-> Attr | |
-> PreparedContent | |
-> Blocks | Float content (intrepreted according to FigureType) |
-> Inlines | Caption |
-> Blocks |
Generic figure builder for all figure types