aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Org
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2016-08-29 14:10:58 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2016-08-29 14:33:18 +0200
commit117d3f4d92d5096cfa51305db6d2fa261ef87d24 (patch)
tree4762cdde72958d0b5903af9aafe3084b6c002c9f /src/Text/Pandoc/Readers/Org
parentad625782b170f4cbbef206bc6ea736c082cb38d7 (diff)
downloadpandoc-117d3f4d92d5096cfa51305db6d2fa261ef87d24.tar.gz
Org reader: respect `author` export option
The `author` option controls whether the author should be included in the final markup. Setting `#+OPTIONS: author:nil` will drop the author from the final meta-data output.
Diffstat (limited to 'src/Text/Pandoc/Readers/Org')
-rw-r--r--src/Text/Pandoc/Readers/Org/Blocks.hs6
-rw-r--r--src/Text/Pandoc/Readers/Org/ExportSettings.hs2
-rw-r--r--src/Text/Pandoc/Readers/Org/Meta.hs17
-rw-r--r--src/Text/Pandoc/Readers/Org/ParserState.hs2
4 files changed, 23 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index b955dafa7..b1f56eed0 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -35,7 +35,7 @@ module Text.Pandoc.Readers.Org.Blocks
import Text.Pandoc.Readers.Org.BlockStarts
import Text.Pandoc.Readers.Org.Inlines
-import Text.Pandoc.Readers.Org.Meta ( metaLine )
+import Text.Pandoc.Readers.Org.Meta ( metaExport, metaLine )
import Text.Pandoc.Readers.Org.ParserState
import Text.Pandoc.Readers.Org.Parsing
import Text.Pandoc.Readers.Org.Shared
@@ -230,8 +230,8 @@ blockList = do
-- | Get the meta information safed in the state.
meta :: OrgParser Meta
meta = do
- st <- getState
- return $ runF (orgStateMeta st) st
+ meta' <- metaExport
+ runF meta' <$> getState
blocks :: OrgParser (F Blocks)
blocks = mconcat <$> manyTill block (void (lookAhead headerStart) <|> eof)
diff --git a/src/Text/Pandoc/Readers/Org/ExportSettings.hs b/src/Text/Pandoc/Readers/Org/ExportSettings.hs
index b48acc9c4..b539a8000 100644
--- a/src/Text/Pandoc/Readers/Org/ExportSettings.hs
+++ b/src/Text/Pandoc/Readers/Org/ExportSettings.hs
@@ -54,7 +54,7 @@ exportSetting = choice
, ignoredSetting "<"
, ignoredSetting "\\n"
, archivedTreeSetting "arch" (\val es -> es { exportArchivedTrees = val })
- , ignoredSetting "author"
+ , booleanSetting "author" (\val es -> es { exportWithAuthor = val })
, ignoredSetting "c"
, ignoredSetting "creator"
, complementableListSetting "d" (\val es -> es { exportDrawers = val })
diff --git a/src/Text/Pandoc/Readers/Org/Meta.hs b/src/Text/Pandoc/Readers/Org/Meta.hs
index 51fd2c9d8..4d74713d6 100644
--- a/src/Text/Pandoc/Readers/Org/Meta.hs
+++ b/src/Text/Pandoc/Readers/Org/Meta.hs
@@ -29,6 +29,7 @@ Parsers for Org-mode meta declarations.
-}
module Text.Pandoc.Readers.Org.Meta
( metaLine
+ , metaExport
) where
import Text.Pandoc.Readers.Org.BlockStarts
@@ -48,6 +49,22 @@ import Data.List ( intersperse )
import qualified Data.Map as M
import Network.HTTP ( urlEncode )
+-- | Returns the current meta, respecting export options.
+metaExport :: OrgParser (F Meta)
+metaExport = do
+ st <- getState
+ let withAuthor = extractExportOption exportWithAuthor st
+ return $ (if withAuthor then id else removeMeta "author")
+ <$> orgStateMeta st
+
+removeMeta :: String -> Meta -> Meta
+removeMeta key meta' =
+ let metaMap = unMeta meta'
+ in Meta $ M.delete key metaMap
+
+extractExportOption :: (ExportSettings -> a) -> OrgParserState -> a
+extractExportOption ex = ex . orgStateExportSettings
+
-- | Parse and handle a single line containing meta information
-- The order, in which blocks are tried, makes sure that we're not looking at
-- the beginning of a block, so we don't need to check for it
diff --git a/src/Text/Pandoc/Readers/Org/ParserState.hs b/src/Text/Pandoc/Readers/Org/ParserState.hs
index 48e7717cd..661ccc4ea 100644
--- a/src/Text/Pandoc/Readers/Org/ParserState.hs
+++ b/src/Text/Pandoc/Readers/Org/ParserState.hs
@@ -163,6 +163,7 @@ data ExportSettings = ExportSettings
, exportSmartQuotes :: Bool -- ^ Parse quotes smartly
, exportSpecialStrings :: Bool -- ^ Parse ellipses and dashes smartly
, exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
+ , exportWithAuthor :: Bool -- ^ Include author in final meta-data
}
instance Default ExportSettings where
@@ -177,6 +178,7 @@ defaultExportSettings = ExportSettings
, exportSmartQuotes = True
, exportSpecialStrings = True
, exportSubSuperscripts = True
+ , exportWithAuthor = True
}