pandoc-crossref 0.1.5.1 → 0.1.5.2
raw patch · 2 files changed
+74/−6 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Text.Pandoc.CrossRef: getSettings :: Meta -> IO Meta
+ Text.Pandoc.CrossRef: CrossRefEnv :: Meta -> Options -> CrossRefEnv
+ Text.Pandoc.CrossRef: [creOptions] :: CrossRefEnv -> Options
+ Text.Pandoc.CrossRef: [creSettings] :: CrossRefEnv -> Meta
+ Text.Pandoc.CrossRef: data CrossRefEnv
+ Text.Pandoc.CrossRef: type CrossRefM a = Reader CrossRefEnv a
Files
- pandoc-crossref.cabal +2/−2
- src/Text/Pandoc/CrossRef.hs +72/−4
pandoc-crossref.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: pandoc-crossref-version: 0.1.5.1+version: 0.1.5.2 synopsis: Pandoc filter for cross-references description: pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them. license: GPL-2@@ -23,7 +23,7 @@ source-repository this type: git location: https://github.com/lierdakil/pandoc-crossref- tag: v0.1.5.1+ tag: v0.1.5.2 library exposed-modules: Text.Pandoc.CrossRef
src/Text/Pandoc/CrossRef.hs view
@@ -1,10 +1,60 @@+{- |+ Module : Text.Pandoc.CrossRef+ Copyright : Copyright (C) 2015 Nikolay Yakimov+ License : GNU GPL, version 2 or above++ Maintainer : Nikolay Yakimov <root@livid.pp.ru>+ Stability : alpha+ Portability : portable++Public interface to pandoc-crossref library++Example of use:++> import Text.Pandoc+> import Text.Pandoc.JSON+>+> import Text.Pandoc.CrossRef+>+> main :: IO ()+> main = toJSONFilter go+> where+> go fmt p@(Pandoc meta _) = runCrossRefIO meta fmt action p+> where+> action (Pandoc _ bs) = do+> meta' <- crossRefMeta+> bs' <- crossRefBlocks bs+> return $ Pandoc meta' bs'++This module also exports utility functions for setting up meta-settings for+pandoc-crossref. Refer to documentation for a complete list of metadata field+names. All functions accept a single argument of type, returned by+"Text.Pandoc.Builder" functions, and return 'Meta'.++Example:++> runCrossRefIO meta fmt crossRefBlocks blocks+> where+> meta =+> figureTitle (str "Figura")+> <> tableTitle (str "Tabla")+> <> figPrefix (str "fig.")+> <> eqnPrefix (str "ec.")+> <> tblPrefix (str "tbl.")+> <> loftitle (header 1 $ text "Lista de figuras")+> <> lotTitle (header 1 $ text "Lista de tablas")+> <> chaptersDepth (MetaString "2")++-}+ module Text.Pandoc.CrossRef (- getSettings- , crossRefBlocks+ crossRefBlocks , crossRefMeta , runCrossRef , runCrossRefIO , module SG+ , CrossRefM+ , CrossRefEnv(..) ) where import Control.Monad.State@@ -20,13 +70,18 @@ import Text.Pandoc.CrossRef.Util.ModifyMeta import Text.Pandoc.CrossRef.Util.Settings.Gen as SG +-- | Enviromnent for 'CrossRefM' data CrossRefEnv = CrossRefEnv {- creSettings :: Meta- , creOptions :: Options+ creSettings :: Meta -- ^Metadata settings+ , creOptions :: Options -- ^Internal pandoc-crossref options } +-- | Essentially a reader monad for basic pandoc-crossref environment type CrossRefM a = R.Reader CrossRefEnv a +{- | Walk over blocks, while inserting cross-references, list-of, etc.++Works in 'CrossRefM' monad. -} crossRefBlocks :: [Block] -> CrossRefM [Block] crossRefBlocks blocks = do opts <- R.asks creOptions@@ -38,12 +93,21 @@ >>= bottomUpM (listOf opts) return $ evalState doWalk def +{- | Modifies metadata for LaTeX output, adding header-includes instructions+to setup custom and builtin environments.++Note, that if output format is not "latex", this function does nothing.++Works in 'CrossRefM' monad. -} crossRefMeta :: CrossRefM Meta crossRefMeta = do opts <- R.asks creOptions dtv <- R.asks creSettings return $ modifyMeta opts dtv +{- | Run an action in 'CrossRefM' monad with argument, and return pure result.++This is primary function to work with 'CrossRefM' -} runCrossRef :: (Walkable a b) => Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> b runCrossRef meta fmt action arg = R.runReader (action arg) env where@@ -53,6 +117,10 @@ , creOptions = getOptions settings fmt } +{- | Run an action in 'CrossRefM' monad with argument, and return 'IO' result.++This function will attempt to read pandoc-crossref settings from settings+file specified by crossrefYaml metadata field. -} runCrossRefIO :: (Walkable a b) => Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> IO b runCrossRefIO meta fmt action arg = do settings <- getSettings meta