aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Org/ExportSettings.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Readers/Org/ExportSettings.hs')
-rw-r--r--src/Text/Pandoc/Readers/Org/ExportSettings.hs36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Org/ExportSettings.hs b/src/Text/Pandoc/Readers/Org/ExportSettings.hs
index 9b293f880..ab402b8c9 100644
--- a/src/Text/Pandoc/Readers/Org/ExportSettings.hs
+++ b/src/Text/Pandoc/Readers/Org/ExportSettings.hs
@@ -20,7 +20,7 @@ import Text.Pandoc.Readers.Org.Parsing
import Control.Monad (mzero, void)
import Data.Char (toLower)
import Data.Maybe (listToMaybe)
-import Data.Text (Text)
+import Data.Text (Text, unpack)
-- | Read and handle space separated org-mode export settings.
exportSettings :: PandocMonad m => OrgParser m ()
@@ -59,7 +59,7 @@ exportSetting = choice
, ignoredSetting "stat"
, booleanSetting "tags" (\val es -> es { exportWithTags = val })
, ignoredSetting "tasks"
- , ignoredSetting "tex"
+ , texSetting "tex" (\val es -> es { exportWithLatex = val })
, ignoredSetting "timestamp"
, ignoredSetting "title"
, ignoredSetting "toc"
@@ -68,6 +68,8 @@ exportSetting = choice
, ignoreAndWarn
] <?> "export setting"
+-- | Generic handler for export settings. Takes a parser which converts
+-- the plain option text into a data structure.
genericExportSetting :: Monad m
=> OrgParser m a
-> Text
@@ -101,10 +103,8 @@ archivedTreeSetting :: Monad m
archivedTreeSetting =
genericExportSetting $ archivedTreesHeadlineSetting <|> archivedTreesBoolean
where
- archivedTreesHeadlineSetting = try $ do
- _ <- string "headline"
- lookAhead (newline <|> spaceChar)
- return ArchivedTreesHeadlineOnly
+ archivedTreesHeadlineSetting =
+ ArchivedTreesHeadlineOnly <$ optionString "headline"
archivedTreesBoolean = try $ do
exportBool <- elispBoolean
@@ -143,6 +143,22 @@ complementableListSetting = genericExportSetting $ choice
char '"'
*> manyTillChar alphaNum (char '"')
+-- | Parses either @t@, @nil@, or @verbatim@ into a 'TeXExport' value.
+texSetting :: Monad m
+ => Text
+ -> ExportSettingSetter TeXExport
+ -> OrgParser m ()
+texSetting = genericExportSetting $ texVerbatim <|> texBoolean
+ where
+ texVerbatim = TeXVerbatim <$ optionString "verbatim"
+
+ texBoolean = try $ do
+ exportBool <- elispBoolean
+ return $
+ if exportBool
+ then TeXExport
+ else TeXIgnore
+
-- | Read but ignore the export setting.
ignoredSetting :: Monad m => Text -> OrgParser m ()
ignoredSetting s = try (() <$ textStr s <* char ':' <* many1 nonspaceChar)
@@ -164,3 +180,11 @@ elispBoolean = try $ do
"{}" -> False
"()" -> False
_ -> True
+
+-- | Try to parse a literal string as the option value. Returns the
+-- string on success.
+optionString :: Monad m => Text -> OrgParser m Text
+optionString s = try $ do
+ _ <- string (unpack s)
+ lookAhead (newline <|> spaceChar)
+ return s