aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Class/CommonState.hs
blob: 4a0f66859a267e0b8c423b96aa3edb19fd36d00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{- |
Module      : Text.Pandoc.Class.CommonState
Copyright   : Copyright (C) 2016-2020 Jesse Rosenthal, John MacFarlane
License     : GNU GPL, version 2 or above

Maintainer  : Jesse Rosenthal <jrosenthal@jhu.edu>
Stability   : alpha
Portability : portable

Common state shared by all pandoc-specific operations, including
those in readers, writers, and Lua filters.
-}

module Text.Pandoc.Class.CommonState
  ( CommonState(..)
  , defaultCommonState
  )
where

import Data.Default (Default (def))
import Data.Text (Text)
import Text.Pandoc.BCP47 (Lang)
import Text.Pandoc.MediaBag (MediaBag)
import Text.Pandoc.Logging (LogMessage, Verbosity (WARNING))
import Text.Pandoc.Translations (Translations)

-- | 'CommonState' represents state that is used by all
-- instances of 'PandocMonad'.  Normally users should not
-- need to interact with it directly; instead, auxiliary
-- functions like 'setVerbosity' and 'withMediaBag' should be used.
data CommonState = CommonState
  { stLog          :: [LogMessage]
    -- ^ A list of log messages in reverse order
  , stUserDataDir  :: Maybe FilePath
    -- ^ Directory to search for data files
  , stSourceURL    :: Maybe Text
    -- ^ Absolute URL + dir of 1st source file
  , stRequestHeaders :: [(Text, Text)]
    -- ^ Headers to add for HTTP requests
  , stMediaBag     :: MediaBag
    -- ^ Media parsed from binary containers
  , stTranslations :: Maybe (Lang, Maybe Translations)
    -- ^ Translations for localization
  , stInputFiles   :: [FilePath]
    -- ^ List of input files from command line
  , stOutputFile   :: Maybe FilePath
    -- ^ Output file from command line
  , stResourcePath :: [FilePath]
    -- ^ Path to search for resources like
    -- included images
  , stVerbosity    :: Verbosity
    -- ^ Verbosity level
  , stTrace        :: Bool
    -- ^ Controls whether tracing messages are
    -- issued.
  }

-- | The default @'CommonState'@. All fields are initialized as the
-- monoid identity of their resprective type, except for:
--
--   * @'stResourcePath'@, which is set to @["."]@,
--   * @'stTrace'@, which is set to @'False'@, and
--   * @'stVerbosity'@, which is set to @WARNING@.
defaultCommonState :: CommonState
defaultCommonState = CommonState
  { stLog = []
  , stUserDataDir = Nothing
  , stSourceURL = Nothing
  , stRequestHeaders = []
  , stMediaBag = mempty
  , stTranslations = Nothing
  , stInputFiles = []
  , stOutputFile = Nothing
  , stResourcePath = ["."]
  , stVerbosity = WARNING
  , stTrace = False
  }

instance Default CommonState where
  def = defaultCommonState