{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{- |
   Module      : Text.Pandoc.Readers.Org.ParserState
   Copyright   : Copyright (C) 2014-2021 Albert Krewinkel
   License     : GNU GPL, version 2 or above

   Maintainer  : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>

Define the Org-mode parser state.
-}
module Text.Pandoc.Readers.Org.ParserState
  ( OrgParserState (..)
  , defaultOrgParserState
  , OrgParserLocal (..)
  , OrgNoteRecord
  , Tag(..)
  , HasReaderOptions (..)
  , HasQuoteContext (..)
  , HasMacros (..)
  , TodoMarker (..)
  , TodoSequence
  , TodoState (..)
  , activeTodoMarkers
  , registerTodoSequence
  , MacroExpander
  , lookupMacro
  , registerMacro
  , F
  , askF
  , asksF
  , trimInlinesF
  , runF
  , returnF
  , ExportSettings (..)
  , ArchivedTreesOption (..)
  , TeXExport (..)
  , optionsToParserState
  ) where

import Control.Monad.Reader (ReaderT, asks, local)

import Data.Default (Default (..))
import qualified Data.Map as M
import qualified Data.Set as Set
import Data.Text (Text)

import Text.Pandoc.Builder (Blocks)
import Text.Pandoc.Definition (Meta (..), nullMeta)
import Text.Pandoc.Logging
import Text.Pandoc.Options (ReaderOptions (..))
import Text.Pandoc.Parsing (Future, HasIdentifierList (..),
                            HasIncludeFiles (..), HasLastStrPosition (..),
                            HasLogMessages (..), HasMacros (..),
                            HasQuoteContext (..), HasReaderOptions (..),
                            ParserContext (..), QuoteContext (..), SourcePos,
                            askF, asksF, returnF, runF, trimInlinesF)
import Text.Pandoc.Readers.LaTeX.Types (Macro)

-- | This is used to delay evaluation until all relevant information has been
-- parsed and made available in the parser state.
type F = Future OrgParserState

-- | An inline note / footnote containing the note key and its (inline) value.
type OrgNoteRecord = (Text, F Blocks)
-- | Table of footnotes
type OrgNoteTable = [OrgNoteRecord]
-- | Map of functions for link transformations.  The map key is refers to the
-- link-type, the corresponding function transforms the given link string.
type OrgLinkFormatters = M.Map Text (Text -> Text)
-- | Macro expander function
type MacroExpander = [Text] -> Text
-- | Tag
newtype Tag = Tag { Tag -> Text
fromTag :: Text }
  deriving (Int -> Tag -> ShowS
[Tag] -> ShowS
Tag -> String
(Int -> Tag -> ShowS)
-> (Tag -> String) -> ([Tag] -> ShowS) -> Show Tag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tag] -> ShowS
$cshowList :: [Tag] -> ShowS
show :: Tag -> String
$cshow :: Tag -> String
showsPrec :: Int -> Tag -> ShowS
$cshowsPrec :: Int -> Tag -> ShowS
Show, Tag -> Tag -> Bool
(Tag -> Tag -> Bool) -> (Tag -> Tag -> Bool) -> Eq Tag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tag -> Tag -> Bool
$c/= :: Tag -> Tag -> Bool
== :: Tag -> Tag -> Bool
$c== :: Tag -> Tag -> Bool
Eq, Eq Tag
Eq Tag
-> (Tag -> Tag -> Ordering)
-> (Tag -> Tag -> Bool)
-> (Tag -> Tag -> Bool)
-> (Tag -> Tag -> Bool)
-> (Tag -> Tag -> Bool)
-> (Tag -> Tag -> Tag)
-> (Tag -> Tag -> Tag)
-> Ord Tag
Tag -> Tag -> Bool
Tag -> Tag -> Ordering
Tag -> Tag -> Tag
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Tag -> Tag -> Tag
$cmin :: Tag -> Tag -> Tag
max :: Tag -> Tag -> Tag
$cmax :: Tag -> Tag -> Tag
>= :: Tag -> Tag -> Bool
$c>= :: Tag -> Tag -> Bool
> :: Tag -> Tag -> Bool
$c> :: Tag -> Tag -> Bool
<= :: Tag -> Tag -> Bool
$c<= :: Tag -> Tag -> Bool
< :: Tag -> Tag -> Bool
$c< :: Tag -> Tag -> Bool
compare :: Tag -> Tag -> Ordering
$ccompare :: Tag -> Tag -> Ordering
$cp1Ord :: Eq Tag
Ord)

-- | The states in which a todo item can be
data TodoState = Todo | Done
  deriving (TodoState -> TodoState -> Bool
(TodoState -> TodoState -> Bool)
-> (TodoState -> TodoState -> Bool) -> Eq TodoState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TodoState -> TodoState -> Bool
$c/= :: TodoState -> TodoState -> Bool
== :: TodoState -> TodoState -> Bool
$c== :: TodoState -> TodoState -> Bool
Eq, Eq TodoState
Eq TodoState
-> (TodoState -> TodoState -> Ordering)
-> (TodoState -> TodoState -> Bool)
-> (TodoState -> TodoState -> Bool)
-> (TodoState -> TodoState -> Bool)
-> (TodoState -> TodoState -> Bool)
-> (TodoState -> TodoState -> TodoState)
-> (TodoState -> TodoState -> TodoState)
-> Ord TodoState
TodoState -> TodoState -> Bool
TodoState -> TodoState -> Ordering
TodoState -> TodoState -> TodoState
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TodoState -> TodoState -> TodoState
$cmin :: TodoState -> TodoState -> TodoState
max :: TodoState -> TodoState -> TodoState
$cmax :: TodoState -> TodoState -> TodoState
>= :: TodoState -> TodoState -> Bool
$c>= :: TodoState -> TodoState -> Bool
> :: TodoState -> TodoState -> Bool
$c> :: TodoState -> TodoState -> Bool
<= :: TodoState -> TodoState -> Bool
$c<= :: TodoState -> TodoState -> Bool
< :: TodoState -> TodoState -> Bool
$c< :: TodoState -> TodoState -> Bool
compare :: TodoState -> TodoState -> Ordering
$ccompare :: TodoState -> TodoState -> Ordering
$cp1Ord :: Eq TodoState
Ord, Int -> TodoState -> ShowS
[TodoState] -> ShowS
TodoState -> String
(Int -> TodoState -> ShowS)
-> (TodoState -> String)
-> ([TodoState] -> ShowS)
-> Show TodoState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TodoState] -> ShowS
$cshowList :: [TodoState] -> ShowS
show :: TodoState -> String
$cshow :: TodoState -> String
showsPrec :: Int -> TodoState -> ShowS
$cshowsPrec :: Int -> TodoState -> ShowS
Show)

-- | A ToDo keyword like @TODO@ or @DONE@.
data TodoMarker = TodoMarker
  { TodoMarker -> TodoState
todoMarkerState :: TodoState
  , TodoMarker -> Text
todoMarkerName  :: Text
  }
  deriving (Int -> TodoMarker -> ShowS
[TodoMarker] -> ShowS
TodoMarker -> String
(Int -> TodoMarker -> ShowS)
-> (TodoMarker -> String)
-> ([TodoMarker] -> ShowS)
-> Show TodoMarker
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TodoMarker] -> ShowS
$cshowList :: [TodoMarker] -> ShowS
show :: TodoMarker -> String
$cshow :: TodoMarker -> String
showsPrec :: Int -> TodoMarker -> ShowS
$cshowsPrec :: Int -> TodoMarker -> ShowS
Show, TodoMarker -> TodoMarker -> Bool
(TodoMarker -> TodoMarker -> Bool)
-> (TodoMarker -> TodoMarker -> Bool) -> Eq TodoMarker
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TodoMarker -> TodoMarker -> Bool
$c/= :: TodoMarker -> TodoMarker -> Bool
== :: TodoMarker -> TodoMarker -> Bool
$c== :: TodoMarker -> TodoMarker -> Bool
Eq)

-- | Collection of todo markers in the order in which items should progress
type TodoSequence = [TodoMarker]

-- | Org-mode parser state
data OrgParserState = OrgParserState
  { OrgParserState -> [Text]
orgStateAnchorIds            :: [Text]
  , OrgParserState -> String
orgStateEmphasisCharStack    :: [Char]
  , OrgParserState -> String
orgStateEmphasisPreChars     :: [Char] -- ^ Chars allowed to occur before
                                           -- emphasis; spaces and newlines are
                                           -- always ok in addition to what is
                                           -- specified here.
  , OrgParserState -> String
orgStateEmphasisPostChars    :: [Char] -- ^ Chars allowed at after emphasis
  , OrgParserState -> Maybe Int
orgStateEmphasisNewlines     :: Maybe Int
  , OrgParserState -> Set Tag
orgStateExcludeTags          :: Set.Set Tag
  , OrgParserState -> Bool
orgStateExcludeTagsChanged   :: Bool
  , OrgParserState -> ExportSettings
orgStateExportSettings       :: ExportSettings
  , OrgParserState -> Set Text
orgStateIdentifiers          :: Set.Set Text
  , OrgParserState -> [Text]
orgStateIncludeFiles         :: [Text]
  , OrgParserState -> Maybe SourcePos
orgStateLastForbiddenCharPos :: Maybe SourcePos
  , OrgParserState -> Maybe SourcePos
orgStateLastPreCharPos       :: Maybe SourcePos
  , OrgParserState -> Maybe SourcePos
orgStateLastStrPos           :: Maybe SourcePos
  , OrgParserState -> OrgLinkFormatters
orgStateLinkFormatters       :: OrgLinkFormatters
  , OrgParserState -> Map Text MacroExpander
orgStateMacros               :: M.Map Text MacroExpander
  , OrgParserState -> Int
orgStateMacroDepth           :: Int
  , OrgParserState -> F Meta
orgStateMeta                 :: F Meta
  , OrgParserState -> OrgNoteTable
orgStateNotes'               :: OrgNoteTable
  , OrgParserState -> ReaderOptions
orgStateOptions              :: ReaderOptions
  , OrgParserState -> ParserContext
orgStateParserContext        :: ParserContext
  , OrgParserState -> Set Tag
orgStateSelectTags           :: Set.Set Tag
  , OrgParserState -> Bool
orgStateSelectTagsChanged    :: Bool
  , OrgParserState -> [[TodoMarker]]
orgStateTodoSequences        :: [TodoSequence]
  , OrgParserState -> Bool
orgStateTrimLeadBlkIndent    :: Bool
  , OrgParserState -> [LogMessage]
orgLogMessages               :: [LogMessage]
  , OrgParserState -> Map Text Macro
orgMacros                    :: M.Map Text Macro
  }

newtype OrgParserLocal = OrgParserLocal
  { OrgParserLocal -> QuoteContext
orgLocalQuoteContext :: QuoteContext
  }

instance Default OrgParserLocal where
  def :: OrgParserLocal
def = QuoteContext -> OrgParserLocal
OrgParserLocal QuoteContext
NoQuote

instance HasReaderOptions OrgParserState where
  extractReaderOptions :: OrgParserState -> ReaderOptions
extractReaderOptions = OrgParserState -> ReaderOptions
orgStateOptions

instance HasLastStrPosition OrgParserState where
  getLastStrPos :: OrgParserState -> Maybe SourcePos
getLastStrPos = OrgParserState -> Maybe SourcePos
orgStateLastStrPos
  setLastStrPos :: Maybe SourcePos -> OrgParserState -> OrgParserState
setLastStrPos Maybe SourcePos
pos OrgParserState
st = OrgParserState
st{ orgStateLastStrPos :: Maybe SourcePos
orgStateLastStrPos = Maybe SourcePos
pos }

instance Monad m => HasQuoteContext st (ReaderT OrgParserLocal m) where
  getQuoteContext :: ParsecT s st (ReaderT OrgParserLocal m) QuoteContext
getQuoteContext = (OrgParserLocal -> QuoteContext)
-> ParsecT s st (ReaderT OrgParserLocal m) QuoteContext
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks OrgParserLocal -> QuoteContext
orgLocalQuoteContext
  withQuoteContext :: QuoteContext
-> ParsecT s st (ReaderT OrgParserLocal m) a
-> ParsecT s st (ReaderT OrgParserLocal m) a
withQuoteContext QuoteContext
q = (OrgParserLocal -> OrgParserLocal)
-> ParsecT s st (ReaderT OrgParserLocal m) a
-> ParsecT s st (ReaderT OrgParserLocal m) a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\OrgParserLocal
s -> OrgParserLocal
s{orgLocalQuoteContext :: QuoteContext
orgLocalQuoteContext = QuoteContext
q})

instance HasIdentifierList OrgParserState where
  extractIdentifierList :: OrgParserState -> Set Text
extractIdentifierList = OrgParserState -> Set Text
orgStateIdentifiers
  updateIdentifierList :: (Set Text -> Set Text) -> OrgParserState -> OrgParserState
updateIdentifierList Set Text -> Set Text
f OrgParserState
s = OrgParserState
s{ orgStateIdentifiers :: Set Text
orgStateIdentifiers = Set Text -> Set Text
f (OrgParserState -> Set Text
orgStateIdentifiers OrgParserState
s) }

instance HasLogMessages OrgParserState where
  addLogMessage :: LogMessage -> OrgParserState -> OrgParserState
addLogMessage LogMessage
msg OrgParserState
st = OrgParserState
st{ orgLogMessages :: [LogMessage]
orgLogMessages = LogMessage
msg LogMessage -> [LogMessage] -> [LogMessage]
forall a. a -> [a] -> [a]
: OrgParserState -> [LogMessage]
orgLogMessages OrgParserState
st }
  getLogMessages :: OrgParserState -> [LogMessage]
getLogMessages OrgParserState
st = [LogMessage] -> [LogMessage]
forall a. [a] -> [a]
reverse ([LogMessage] -> [LogMessage]) -> [LogMessage] -> [LogMessage]
forall a b. (a -> b) -> a -> b
$ OrgParserState -> [LogMessage]
orgLogMessages OrgParserState
st

instance HasMacros OrgParserState where
  extractMacros :: OrgParserState -> Map Text Macro
extractMacros OrgParserState
st = OrgParserState -> Map Text Macro
orgMacros OrgParserState
st
  updateMacros :: (Map Text Macro -> Map Text Macro)
-> OrgParserState -> OrgParserState
updateMacros Map Text Macro -> Map Text Macro
f OrgParserState
st = OrgParserState
st{ orgMacros :: Map Text Macro
orgMacros = Map Text Macro -> Map Text Macro
f (OrgParserState -> Map Text Macro
orgMacros OrgParserState
st) }

instance HasIncludeFiles OrgParserState where
  getIncludeFiles :: OrgParserState -> [Text]
getIncludeFiles = OrgParserState -> [Text]
orgStateIncludeFiles
  addIncludeFile :: Text -> OrgParserState -> OrgParserState
addIncludeFile Text
f OrgParserState
st = OrgParserState
st { orgStateIncludeFiles :: [Text]
orgStateIncludeFiles = Text
f Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: OrgParserState -> [Text]
orgStateIncludeFiles OrgParserState
st }
  dropLatestIncludeFile :: OrgParserState -> OrgParserState
dropLatestIncludeFile OrgParserState
st =
    OrgParserState
st { orgStateIncludeFiles :: [Text]
orgStateIncludeFiles = Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
drop Int
1 ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ OrgParserState -> [Text]
orgStateIncludeFiles OrgParserState
st }

instance Default OrgParserState where
  def :: OrgParserState
def = OrgParserState
defaultOrgParserState

defaultOrgParserState :: OrgParserState
defaultOrgParserState :: OrgParserState
defaultOrgParserState = OrgParserState :: [Text]
-> String
-> String
-> String
-> Maybe Int
-> Set Tag
-> Bool
-> ExportSettings
-> Set Text
-> [Text]
-> Maybe SourcePos
-> Maybe SourcePos
-> Maybe SourcePos
-> OrgLinkFormatters
-> Map Text MacroExpander
-> Int
-> F Meta
-> OrgNoteTable
-> ReaderOptions
-> ParserContext
-> Set Tag
-> Bool
-> [[TodoMarker]]
-> Bool
-> [LogMessage]
-> Map Text Macro
-> OrgParserState
OrgParserState
  { orgStateAnchorIds :: [Text]
orgStateAnchorIds = []
  , orgStateEmphasisPreChars :: String
orgStateEmphasisPreChars = String
"-\t ('\"{"
  , orgStateEmphasisPostChars :: String
orgStateEmphasisPostChars  = String
"-\t\n .,:!?;'\")}["
  , orgStateEmphasisCharStack :: String
orgStateEmphasisCharStack = []
  , orgStateEmphasisNewlines :: Maybe Int
orgStateEmphasisNewlines = Maybe Int
forall a. Maybe a
Nothing
  , orgStateExportSettings :: ExportSettings
orgStateExportSettings = ExportSettings
forall a. Default a => a
def
  , orgStateExcludeTags :: Set Tag
orgStateExcludeTags = Tag -> Set Tag
forall a. a -> Set a
Set.singleton (Tag -> Set Tag) -> Tag -> Set Tag
forall a b. (a -> b) -> a -> b
$ Text -> Tag
Tag Text
"noexport"
  , orgStateExcludeTagsChanged :: Bool
orgStateExcludeTagsChanged = Bool
False
  , orgStateIdentifiers :: Set Text
orgStateIdentifiers = Set Text
forall a. Set a
Set.empty
  , orgStateIncludeFiles :: [Text]
orgStateIncludeFiles = []
  , orgStateLastForbiddenCharPos :: Maybe SourcePos
orgStateLastForbiddenCharPos = Maybe SourcePos
forall a. Maybe a
Nothing
  , orgStateLastPreCharPos :: Maybe SourcePos
orgStateLastPreCharPos = Maybe SourcePos
forall a. Maybe a
Nothing
  , orgStateLastStrPos :: Maybe SourcePos
orgStateLastStrPos = Maybe SourcePos
forall a. Maybe a
Nothing
  , orgStateLinkFormatters :: OrgLinkFormatters
orgStateLinkFormatters = OrgLinkFormatters
forall k a. Map k a
M.empty
  , orgStateMacros :: Map Text MacroExpander
orgStateMacros = Map Text MacroExpander
forall k a. Map k a
M.empty
  , orgStateMacroDepth :: Int
orgStateMacroDepth = Int
0
  , orgStateMeta :: F Meta
orgStateMeta = Meta -> F Meta
forall (m :: * -> *) a. Monad m => a -> m a
return Meta
nullMeta
  , orgStateNotes' :: OrgNoteTable
orgStateNotes' = []
  , orgStateOptions :: ReaderOptions
orgStateOptions = ReaderOptions
forall a. Default a => a
def
  , orgStateParserContext :: ParserContext
orgStateParserContext = ParserContext
NullState
  , orgStateSelectTags :: Set Tag
orgStateSelectTags = Tag -> Set Tag
forall a. a -> Set a
Set.singleton (Tag -> Set Tag) -> Tag -> Set Tag
forall a b. (a -> b) -> a -> b
$ Text -> Tag
Tag Text
"export"
  , orgStateSelectTagsChanged :: Bool
orgStateSelectTagsChanged = Bool
False
  , orgStateTrimLeadBlkIndent :: Bool
orgStateTrimLeadBlkIndent = Bool
True
  , orgStateTodoSequences :: [[TodoMarker]]
orgStateTodoSequences = []
  , orgLogMessages :: [LogMessage]
orgLogMessages = []
  , orgMacros :: Map Text Macro
orgMacros = Map Text Macro
forall k a. Map k a
M.empty
  }

optionsToParserState :: ReaderOptions -> OrgParserState
optionsToParserState :: ReaderOptions -> OrgParserState
optionsToParserState ReaderOptions
opts =
  OrgParserState
forall a. Default a => a
def { orgStateOptions :: ReaderOptions
orgStateOptions = ReaderOptions
opts }

registerTodoSequence :: TodoSequence -> OrgParserState -> OrgParserState
registerTodoSequence :: [TodoMarker] -> OrgParserState -> OrgParserState
registerTodoSequence [TodoMarker]
todoSeq OrgParserState
st =
  let curSeqs :: [[TodoMarker]]
curSeqs = OrgParserState -> [[TodoMarker]]
orgStateTodoSequences OrgParserState
st
  in OrgParserState
st{ orgStateTodoSequences :: [[TodoMarker]]
orgStateTodoSequences = [TodoMarker]
todoSeq [TodoMarker] -> [[TodoMarker]] -> [[TodoMarker]]
forall a. a -> [a] -> [a]
: [[TodoMarker]]
curSeqs }

-- | Get the current todo/done sequences. If no custom todo sequences have been
-- defined, return a list containing just the default todo/done sequence.
activeTodoSequences :: OrgParserState -> [TodoSequence]
activeTodoSequences :: OrgParserState -> [[TodoMarker]]
activeTodoSequences OrgParserState
st =
  let curSeqs :: [[TodoMarker]]
curSeqs = OrgParserState -> [[TodoMarker]]
orgStateTodoSequences OrgParserState
st
  in if [[TodoMarker]] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[TodoMarker]]
curSeqs
     then [[ TodoState -> Text -> TodoMarker
TodoMarker TodoState
Todo Text
"TODO" , TodoState -> Text -> TodoMarker
TodoMarker TodoState
Done Text
"DONE" ]]
     else [[TodoMarker]]
curSeqs

activeTodoMarkers :: OrgParserState -> TodoSequence
activeTodoMarkers :: OrgParserState -> [TodoMarker]
activeTodoMarkers = [[TodoMarker]] -> [TodoMarker]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[TodoMarker]] -> [TodoMarker])
-> (OrgParserState -> [[TodoMarker]])
-> OrgParserState
-> [TodoMarker]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> [[TodoMarker]]
activeTodoSequences

lookupMacro :: Text -> OrgParserState -> Maybe MacroExpander
lookupMacro :: Text -> OrgParserState -> Maybe MacroExpander
lookupMacro Text
macroName = Text -> Map Text MacroExpander -> Maybe MacroExpander
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
macroName (Map Text MacroExpander -> Maybe MacroExpander)
-> (OrgParserState -> Map Text MacroExpander)
-> OrgParserState
-> Maybe MacroExpander
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> Map Text MacroExpander
orgStateMacros

registerMacro :: (Text, MacroExpander) -> OrgParserState -> OrgParserState
registerMacro :: (Text, MacroExpander) -> OrgParserState -> OrgParserState
registerMacro (Text
name, MacroExpander
expander) OrgParserState
st =
  let curMacros :: Map Text MacroExpander
curMacros = OrgParserState -> Map Text MacroExpander
orgStateMacros OrgParserState
st
  in OrgParserState
st{ orgStateMacros :: Map Text MacroExpander
orgStateMacros = Text
-> MacroExpander
-> Map Text MacroExpander
-> Map Text MacroExpander
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
name MacroExpander
expander Map Text MacroExpander
curMacros }



--
-- Export Settings
--

-- | Options for the way archived trees are handled.
data ArchivedTreesOption =
    ArchivedTreesExport       -- ^ Export the complete tree
  | ArchivedTreesNoExport     -- ^ Exclude archived trees from exporting
  | ArchivedTreesHeadlineOnly -- ^ Export only the headline, discard the contents

-- | Options for the handling of LaTeX environments and fragments.
-- Represents allowed values of Emacs variable @org-export-with-latex@.
data TeXExport
  = TeXExport                 -- ^ Include raw TeX in the output
  | TeXIgnore                 -- ^ Ignore raw TeX
  | TeXVerbatim               -- ^ Keep everything in verbatim

-- | Export settings <http://orgmode.org/manual/Export-settings.html>
-- These settings can be changed via OPTIONS statements.
data ExportSettings = ExportSettings
  { ExportSettings -> ArchivedTreesOption
exportArchivedTrees    :: ArchivedTreesOption -- ^ How to treat archived trees
  , ExportSettings -> Either [Text] [Text]
exportDrawers          :: Either [Text] [Text]
  -- ^ Specify drawer names which should be exported.  @Left@ names are
  -- explicitly excluded from the resulting output while @Right@ means that
  -- only the listed drawer names should be included.
  , ExportSettings -> Bool
exportEmphasizedText   :: Bool -- ^ Parse emphasized text
  , ExportSettings -> Int
exportHeadlineLevels   :: Int
  -- ^ Maximum depth of headlines, deeper headlines are convert to list
  , ExportSettings -> Bool
exportPreserveBreaks   :: Bool -- ^ Whether to preserve linebreaks
  , ExportSettings -> Bool
exportSmartQuotes      :: Bool -- ^ Parse quotes smartly
  , ExportSettings -> Bool
exportSpecialStrings   :: Bool -- ^ Parse ellipses and dashes smartly
  , ExportSettings -> Bool
exportSubSuperscripts  :: Bool -- ^ TeX-like syntax for sub- and superscripts
  , ExportSettings -> Bool
exportWithAuthor       :: Bool -- ^ Include author in final meta-data
  , ExportSettings -> Bool
exportWithCreator      :: Bool -- ^ Include creator in final meta-data
  , ExportSettings -> Bool
exportWithEmail        :: Bool -- ^ Include email in final meta-data
  , ExportSettings -> Bool
exportWithEntities     :: Bool -- ^ Include MathML-like entities
  , ExportSettings -> Bool
exportWithFootnotes    :: Bool -- ^ Include footnotes
  , ExportSettings -> TeXExport
exportWithLatex        :: TeXExport -- ^ Handling of raw TeX commands
  , ExportSettings -> Bool
exportWithPlanning     :: Bool -- ^ Keep planning info after headlines
  , ExportSettings -> Bool
exportWithTags         :: Bool -- ^ Keep tags as part of headlines
  , ExportSettings -> Bool
exportWithTables       :: Bool -- ^ Include tables
  , ExportSettings -> Bool
exportWithTodoKeywords :: Bool -- ^ Keep TODO keywords in headers
  }

instance Default ExportSettings where
  def :: ExportSettings
def = ExportSettings
defaultExportSettings

defaultExportSettings :: ExportSettings
defaultExportSettings :: ExportSettings
defaultExportSettings = ExportSettings :: ArchivedTreesOption
-> Either [Text] [Text]
-> Bool
-> Int
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> TeXExport
-> Bool
-> Bool
-> Bool
-> Bool
-> ExportSettings
ExportSettings
  { exportArchivedTrees :: ArchivedTreesOption
exportArchivedTrees = ArchivedTreesOption
ArchivedTreesHeadlineOnly
  , exportDrawers :: Either [Text] [Text]
exportDrawers = [Text] -> Either [Text] [Text]
forall a b. a -> Either a b
Left [Text
"LOGBOOK"]
  , exportEmphasizedText :: Bool
exportEmphasizedText = Bool
True
  , exportHeadlineLevels :: Int
exportHeadlineLevels = Int
3
  , exportPreserveBreaks :: Bool
exportPreserveBreaks = Bool
False
  , exportSmartQuotes :: Bool
exportSmartQuotes = Bool
False
  , exportSpecialStrings :: Bool
exportSpecialStrings = Bool
True
  , exportSubSuperscripts :: Bool
exportSubSuperscripts = Bool
True
  , exportWithAuthor :: Bool
exportWithAuthor = Bool
True
  , exportWithCreator :: Bool
exportWithCreator = Bool
True
  , exportWithEmail :: Bool
exportWithEmail = Bool
True
  , exportWithEntities :: Bool
exportWithEntities = Bool
True
  , exportWithFootnotes :: Bool
exportWithFootnotes = Bool
True
  , exportWithLatex :: TeXExport
exportWithLatex = TeXExport
TeXExport
  , exportWithPlanning :: Bool
exportWithPlanning = Bool
False
  , exportWithTags :: Bool
exportWithTags = Bool
True
  , exportWithTables :: Bool
exportWithTables = Bool
True
  , exportWithTodoKeywords :: Bool
exportWithTodoKeywords = Bool
True
  }