git.iko.soy/typeable/pandoc
on master help sign in
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.

commit117d3f4d92d5096cfa51305db6d2fa261ef87d24 authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 29 Aug 2016, 14:10 (10 years ago) parentad62578
5 files changed+29−4
src/Text/Pandoc/Readers/Org/Blocks.hs+3−3 src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1 src/Text/Pandoc/Readers/Org/Meta.hs+17 src/Text/Pandoc/Readers/Org/ParserState.hs+2 tests/Tests/Readers/Org.hs+6
src/Text/Pandoc/Readers/Org/Blocks.hs+3−3
@@ -35,7 +35,7 @@ module Text.Pandoc.Readers.Org.Blocks
3535
3636import Text.Pandoc.Readers.Org.BlockStarts
3737import Text.Pandoc.Readers.Org.Inlines
38−import Text.Pandoc.Readers.Org.Meta ( metaLine )
38+import Text.Pandoc.Readers.Org.Meta ( metaExport, metaLine )
3939import Text.Pandoc.Readers.Org.ParserState
4040import Text.Pandoc.Readers.Org.Parsing
4141import Text.Pandoc.Readers.Org.Shared
@@ -230,8 +230,8 @@ blockList = do
230230-- | Get the meta information safed in the state.
231231meta :: OrgParser Meta
232232meta = do
233− st <- getState
234− return $ runF (orgStateMeta st) st
233+ meta' <- metaExport
234+ runF meta' <$> getState
235235
236236blocks :: OrgParser (F Blocks)
237237blocks = mconcat <$> manyTill block (void (lookAhead headerStart) <|> eof)
src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1
@@ -54,7 +54,7 @@ exportSetting = choice
5454 , ignoredSetting "<"
5555 , ignoredSetting "\\n"
5656 , archivedTreeSetting "arch" (\val es -> es { exportArchivedTrees = val })
57− , ignoredSetting "author"
57+ , booleanSetting "author" (\val es -> es { exportWithAuthor = val })
5858 , ignoredSetting "c"
5959 , ignoredSetting "creator"
6060 , complementableListSetting "d" (\val es -> es { exportDrawers = val })
src/Text/Pandoc/Readers/Org/Meta.hs+17
@@ -29,6 +29,7 @@ Parsers for Org-mode meta declarations.
2929-}
3030module Text.Pandoc.Readers.Org.Meta
3131 ( metaLine
32+ , metaExport
3233 ) where
3334
3435import Text.Pandoc.Readers.Org.BlockStarts
@@ -48,6 +49,22 @@ import Data.List ( intersperse )
4849import qualified Data.Map as M
4950import Network.HTTP ( urlEncode )
5051
52+-- | Returns the current meta, respecting export options.
53+metaExport :: OrgParser (F Meta)
54+metaExport = do
55+ st <- getState
56+ let withAuthor = extractExportOption exportWithAuthor st
57+ return $ (if withAuthor then id else removeMeta "author")
58+ <$> orgStateMeta st
59+
60+removeMeta :: String -> Meta -> Meta
61+removeMeta key meta' =
62+ let metaMap = unMeta meta'
63+ in Meta $ M.delete key metaMap
64+
65+extractExportOption :: (ExportSettings -> a) -> OrgParserState -> a
66+extractExportOption ex = ex . orgStateExportSettings
67+
5168-- | Parse and handle a single line containing meta information
5269-- The order, in which blocks are tried, makes sure that we're not looking at
5370-- the beginning of a block, so we don't need to check for it
src/Text/Pandoc/Readers/Org/ParserState.hs+2
@@ -163,6 +163,7 @@ data ExportSettings = ExportSettings
163163 , exportSmartQuotes :: Bool -- ^ Parse quotes smartly
164164 , exportSpecialStrings :: Bool -- ^ Parse ellipses and dashes smartly
165165 , exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
166+ , exportWithAuthor :: Bool -- ^ Include author in final meta-data
166167 }
167168
168169instance Default ExportSettings where
@@ -177,6 +178,7 @@ defaultExportSettings = ExportSettings
177178 , exportSmartQuotes = True
178179 , exportSpecialStrings = True
179180 , exportSubSuperscripts = True
181+ , exportWithAuthor = True
180182 }
181183
182184
tests/Tests/Readers/Org.hs+6
@@ -668,6 +668,12 @@ tests =
668668 , headerWith ("subsection", [], []) 2 "subsection"
669669 , orderedList [ para "list item 1", para "list item 2" ]
670670 ]
671+
672+ , "disable author export" =:
673+ unlines [ "#+OPTIONS: author:nil"
674+ , "#+AUTHOR: ShyGuy"
675+ ] =?>
676+ Pandoc nullMeta mempty
671677 ]
672678 ]
673679