pandoc-3.10: Conversion between markup formats

Copyright | Copyright (C) 2009-2024 John MacFarlane
License | GNU GPL, version 2 or above
Maintainer | John MacFarlane <jgm@berkeley.edu>
Stability | alpha
Portability | portable
Safe Haskell | None
Language | Haskell2010

Text.Pandoc.Templates

Description

Utility functions for working with pandoc templates.

`WithDefaultPartials` and `WithPartials` are Monad wrappers. Wrapping these around an instance of `PandocMonad` gives different instances of `TemplateMonad`, with different search behaviors when retrieving partials.

To compile a template and limit partial search to pandoc’s data files, use `runWithDefaultPartials (compileTemplate ...)`.

To compile a template and allow partials to be found locally (either on the file system or via HTTP, in the event that the main template has an absolute URL), ue `runWithPartials (compileTemplate ...)`.

`getTemplate` seeks a template locally, or via HTTP if the template has an absolute URL, falling back to the data files if not found.

Synopsis

- data Template a
- newtype WithDefaultPartials (m :: Type -> Type) a = WithDefaultPartials {
  - runWithDefaultPartials :: m a
  }
- newtype WithPartials (m :: Type -> Type) a = WithPartials {
  - runWithPartials :: m a
  }
- compileTemplate :: (TemplateMonad m, TemplateTarget a) => FilePath -> Text -> m (Either String (Template a))
- renderTemplate :: (TemplateTarget a, ToContext a b) => Template a -> b -> Doc a
- getTemplate :: PandocMonad m => FilePath -> m Text
- getDefaultTemplate :: PandocMonad m => Text -> m Text
- compileDefaultTemplate :: PandocMonad m => Text -> m (Template Text)

# Documentation

data Template a Source #

A template.

#### Instances

Instances details

Functor Template |
Instance details Defined in Text.DocTemplates.Internal Methods fmap :: (a -> b) -> Template a -> Template b Source # (<$) :: a -> Template b -> Template a Source #
Foldable Template |

Instance details

Defined in Text.DocTemplates.Internal

Methods

fold :: Monoid m => Template m -> m Source #

foldMap :: Monoid m => (a -> m) -> Template a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Template a -> m Source #

foldr :: (a -> b -> b) -> b -> Template a -> b Source #

foldr' :: (a -> b -> b) -> b -> Template a -> b Source #

foldl :: (b -> a -> b) -> b -> Template a -> b Source #

foldl' :: (b -> a -> b) -> b -> Template a -> b Source #

foldr1 :: (a -> a -> a) -> Template a -> a Source #

foldl1 :: (a -> a -> a) -> Template a -> a Source #

toList :: Template a -> [a] Source #

null :: Template a -> Bool Source #

length :: Template a -> Int Source #

elem :: Eq a => a -> Template a -> Bool Source #

maximum :: Ord a => Template a -> a Source #

minimum :: Ord a => Template a -> a Source #

sum :: Num a => Template a -> a Source #

product :: Num a => Template a -> a Source #

Traversable Template |
Instance details Defined in Text.DocTemplates.Internal Methods traverse :: Applicative f => (a -> f b) -> Template a -> f (Template b) Source # sequenceA :: Applicative f => Template (f a) -> f (Template a) Source # mapM :: Monad m => (a -> m b) -> Template a -> m (Template b) Source # sequence :: Monad m => Template (m a) -> m (Template a) Source #
Semigroup a => Monoid (Template a) |
Instance details Defined in Text.DocTemplates.Internal Methods mempty :: Template a Source # mappend :: Template a -> Template a -> Template a Source # mconcat :: [Template a] -> Template a Source #
Semigroup a => Semigroup (Template a) |
Instance details Defined in Text.DocTemplates.Internal Methods (<>) :: Template a -> Template a -> Template a Source # sconcat :: NonEmpty (Template a) -> Template a Source # stimes :: Integral b => b -> Template a -> Template a Source #
Data a => Data (Template a) |

Instance details

Defined in Text.DocTemplates.Internal

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Template a -> c (Template a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Template a) Source #

toConstr :: Template a -> Constr Source #

dataTypeOf :: Template a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Template a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Template a)) Source #

gmapT :: (forall b. Data b => b -> b) -> Template a -> Template a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Template a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Template a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Template a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Template a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Template a -> m (Template a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Template a -> m (Template a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Template a -> m (Template a) Source #

Generic (Template a) |

Instance details

Defined in Text.DocTemplates.Internal

Associated Types

type Rep (Template a) |

Instance details

Defined in Text.DocTemplates.Internal

type Rep (Template a) = D1 ('MetaData "Template" "Text.DocTemplates.Internal" "doctemplates-0.11.0.1-D1ix9osNqlP9wO3nyCLxCL" 'False) (((C1 ('MetaCons "Interpolate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Variable)) :+: C1 ('MetaCons "Conditional" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Variable) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))))) :+: (C1 ('MetaCons "Iterate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Variable) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)))) :+: C1 ('MetaCons "Nested" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))))) :+: ((C1 ('MetaCons "Partial" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Pipe]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))) :+: C1 ('MetaCons "Literal" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc a)))) :+: (C1 ('MetaCons "Concat" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))) :+: C1 ('MetaCons "Empty" 'PrefixI 'False) (U1 :: Type -> Type))))

Methods

from :: Template a -> Rep (Template a) x Source #

to :: Rep (Template a) x -> Template a Source #

Read a => Read (Template a) |
Instance details Defined in Text.DocTemplates.Internal Methods readsPrec :: Int -> ReadS (Template a) Source # readList :: ReadS [Template a] Source # readPrec :: ReadPrec (Template a) Source # readListPrec :: ReadPrec [Template a] Source #
Show a => Show (Template a) |
Instance details Defined in Text.DocTemplates.Internal Methods showsPrec :: Int -> Template a -> ShowS Source # show :: Template a -> String Source # showList :: [Template a] -> ShowS Source #
Eq a => Eq (Template a) |
Instance details Defined in Text.DocTemplates.Internal Methods (==) :: Template a -> Template a -> Bool Source # (/=) :: Template a -> Template a -> Bool Source #
Ord a => Ord (Template a) |

Instance details

Defined in Text.DocTemplates.Internal

Methods

compare :: Template a -> Template a -> Ordering Source #

(<) :: Template a -> Template a -> Bool Source #

(<=) :: Template a -> Template a -> Bool Source #

(>) :: Template a -> Template a -> Bool Source #

(>=) :: Template a -> Template a -> Bool Source #

max :: Template a -> Template a -> Template a Source #

min :: Template a -> Template a -> Template a Source #

type Rep (Template a) |

Instance details

Defined in Text.DocTemplates.Internal

type Rep (Template a) = D1 ('MetaData "Template" "Text.DocTemplates.Internal" "doctemplates-0.11.0.1-D1ix9osNqlP9wO3nyCLxCL" 'False) (((C1 ('MetaCons "Interpolate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Variable)) :+: C1 ('MetaCons "Conditional" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Variable) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))))) :+: (C1 ('MetaCons "Iterate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Variable) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)))) :+: C1 ('MetaCons "Nested" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))))) :+: ((C1 ('MetaCons "Partial" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Pipe]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))) :+: C1 ('MetaCons "Literal" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc a)))) :+: (C1 ('MetaCons "Concat" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Template a))) :+: C1 ('MetaCons "Empty" 'PrefixI 'False) (U1 :: Type -> Type))))

newtype WithDefaultPartials (m :: Type -> Type) a Source #

Wrap a Monad in this if you want partials to be taken only from the default data files.

Constructors

WithDefaultPartials |

Fields

- runWithDefaultPartials :: m a

#### Instances

Instances details

PandocMonad m => TemplateMonad (WithDefaultPartials m) Source # |
Instance details Defined in Text.Pandoc.Templates Methods getPartial :: FilePath -> WithDefaultPartials m Text Source #
Applicative m => Applicative (WithDefaultPartials m) Source # |

Instance details

Defined in Text.Pandoc.Templates

Methods

pure :: a -> WithDefaultPartials m a Source #

(<*>) :: WithDefaultPartials m (a -> b) -> WithDefaultPartials m a -> WithDefaultPartials m b Source #

liftA2 :: (a -> b -> c) -> WithDefaultPartials m a -> WithDefaultPartials m b -> WithDefaultPartials m c Source #

(*>) :: WithDefaultPartials m a -> WithDefaultPartials m b -> WithDefaultPartials m b Source #

(<*) :: WithDefaultPartials m a -> WithDefaultPartials m b -> WithDefaultPartials m a Source #

Functor m => Functor (WithDefaultPartials m) Source # |
Instance details Defined in Text.Pandoc.Templates Methods fmap :: (a -> b) -> WithDefaultPartials m a -> WithDefaultPartials m b Source # (<$) :: a -> WithDefaultPartials m b -> WithDefaultPartials m a Source #
Monad m => Monad (WithDefaultPartials m) Source # |
Instance details Defined in Text.Pandoc.Templates Methods (>>=) :: WithDefaultPartials m a -> (a -> WithDefaultPartials m b) -> WithDefaultPartials m b Source # (>>) :: WithDefaultPartials m a -> WithDefaultPartials m b -> WithDefaultPartials m b Source # return :: a -> WithDefaultPartials m a Source #

newtype WithPartials (m :: Type -> Type) a Source #

Wrap a Monad in this if you want partials to be looked for locally (or, when the main template is at a URL, via HTTP), falling back to default data files.

Constructors

WithPartials |

Fields

- runWithPartials :: m a

#### Instances

Instances details

PandocMonad m => TemplateMonad (WithPartials m) Source # |
Instance details Defined in Text.Pandoc.Templates Methods getPartial :: FilePath -> WithPartials m Text Source #
Applicative m => Applicative (WithPartials m) Source # |

Instance details

Defined in Text.Pandoc.Templates

Methods

pure :: a -> WithPartials m a Source #

(<*>) :: WithPartials m (a -> b) -> WithPartials m a -> WithPartials m b Source #

liftA2 :: (a -> b -> c) -> WithPartials m a -> WithPartials m b -> WithPartials m c Source #

(*>) :: WithPartials m a -> WithPartials m b -> WithPartials m b Source #

(<*) :: WithPartials m a -> WithPartials m b -> WithPartials m a Source #

Functor m => Functor (WithPartials m) Source # |
Instance details Defined in Text.Pandoc.Templates Methods fmap :: (a -> b) -> WithPartials m a -> WithPartials m b Source # (<$) :: a -> WithPartials m b -> WithPartials m a Source #
Monad m => Monad (WithPartials m) Source # |
Instance details Defined in Text.Pandoc.Templates Methods (>>=) :: WithPartials m a -> (a -> WithPartials m b) -> WithPartials m b Source # (>>) :: WithPartials m a -> WithPartials m b -> WithPartials m b Source # return :: a -> WithPartials m a Source #

compileTemplate :: (TemplateMonad m, TemplateTarget a) => FilePath -> Text -> m (Either String (Template a)) Source #

Compile a template. The FilePath parameter is used to determine a default path and extension for partials and may be left empty if partials are not used.

renderTemplate :: (TemplateTarget a, ToContext a b) => Template a -> b -> Doc a Source #

Render a compiled template in a "context" which provides values for the template's variables.

getTemplate :: PandocMonad m => FilePath -> m Text Source #

Retrieve text for a template.

getDefaultTemplate Source #

Arguments

:: PandocMonad m |
=> Text | Name of writer
-> m Text |

Get default template for the specified writer.

compileDefaultTemplate :: PandocMonad m => Text -> m (Template Text) Source #

Get and compile default template for the specified writer. Raise an error on compilation failure.