scholdoc-types-0.1.3: Scholdoc fork of pandoc-types

CopyrightCopyright (C) 2010 John MacFarlane
LicenseGNU GPL, version 2 or above
MaintainerJohn MacFarlane <jgm@berkeley.edu>
Stabilityalpha
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Text.Pandoc.Builder

Contents

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 [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

Documentation

newtype Many a Source

Constructors

Many 

Fields

unMany :: Seq a
 

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

An infix synonym for mappend.

Since: 4.5.0.0

toList :: Many a -> [a] Source

fromList :: [a] -> Many a Source

Document builders

class HasMeta a where Source

Methods

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

deleteMeta :: String -> a -> a Source

Inline list builders

text :: String -> Inlines Source

Convert a String to Inlines, treating interword spaces as Spaces. If you want a Str with literal spaces, use str.

codeWith :: Attr -> String -> Inlines Source

Inline code with attributes.

code :: String -> Inlines Source

Plain inline code.

math :: String -> Inlines Source

Inline math

displayMath :: String -> Inlines Source

Display math

displayMathWith :: Attr -> String -> Inlines Source

Display math with attributes

link Source

Arguments

:: String

URL

-> String

Title

-> Inlines

Label

-> Inlines 

image Source

Arguments

:: String

URL

-> String

Title

-> Inlines

Alt text

-> Inlines 

imageWith Source

Arguments

:: Attr 
-> String

URL

-> String

Title

-> Inlines

Alt text

-> Inlines 

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.

codeBlock :: String -> Blocks Source

A plain code block.

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

Ordered list with attributes.

orderedList :: [Blocks] -> Blocks Source

Ordered list with default attributes.

header Source

Arguments

:: Int

Level

-> Inlines 
-> Blocks 

table Source

Arguments

:: Inlines

Caption

-> [(Alignment, Double)]

Column alignments and fractional widths

-> [Blocks]

Headers

-> [[Blocks]]

Rows

-> Blocks 

simpleTable Source

Arguments

:: [Blocks]

Headers

-> [[Blocks]]

Rows

-> Blocks 

A simple table without a caption.

imageGrid :: [Inlines] -> Blocks Source

A column of rows of images, forming a grid (used for figures)

figure Source

Arguments

:: FigureType 
-> Attr 
-> PreparedContent 
-> Blocks

Float content (intrepreted according to FigureType)

-> Inlines

Caption

-> Blocks 

Generic figure builder for all figure types

statement Source

Arguments

:: String 
-> StatementStyle

Style (Theorem, Standard, Remark, Other)

-> (Inlines, String)

Label (with raw string)

-> String

Counter name

-> Int

Hierarchial level (1-6)

-> String

Default numerical label

-> Inlines

Caption

-> Blocks

Text

-> Blocks 

Statements (theorem, lemma, definiton, example, etc)

proof Source

Arguments

:: Inlines

Replacement title

-> Blocks

Text

-> Blocks