git.iko.soy/typeable/pandoc
on master help sign in
Org reader: respect `author` export option
117d3f4Albert Krewinkel
src/Text/Pandoc/Readers/Org/Blocks.hs+3−3
@@ -35,7 +35,7 @@ module Text.Pandoc.Readers.Org.Blocks
35
35
36import Text.Pandoc.Readers.Org.BlockStarts
36import Text.Pandoc.Readers.Org.BlockStarts
37import Text.Pandoc.Readers.Org.Inlines
37import Text.Pandoc.Readers.Org.Inlines
38−import Text.Pandoc.Readers.Org.Meta ( metaLine )
38+import Text.Pandoc.Readers.Org.Meta ( metaExport, metaLine )
39import Text.Pandoc.Readers.Org.ParserState
39import Text.Pandoc.Readers.Org.ParserState
40import Text.Pandoc.Readers.Org.Parsing
40import Text.Pandoc.Readers.Org.Parsing
41import Text.Pandoc.Readers.Org.Shared
41import Text.Pandoc.Readers.Org.Shared
@@ -230,8 +230,8 @@ blockList = do
230-- | Get the meta information safed in the state.
230-- | Get the meta information safed in the state.
231meta :: OrgParser Meta
231meta :: OrgParser Meta
232meta = do
232meta = do
233− st <- getState
233+ meta' <- metaExport
234− return $ runF (orgStateMeta st) st
234+ runF meta' <$> getState
235
235
236blocks :: OrgParser (F Blocks)
236blocks :: OrgParser (F Blocks)
237blocks = mconcat <$> manyTill block (void (lookAhead headerStart) <|> eof)
237blocks = mconcat <$> manyTill block (void (lookAhead headerStart) <|> eof)
src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1
@@ -54,7 +54,7 @@ exportSetting = choice
54 , ignoredSetting "<"
54 , ignoredSetting "<"
55 , ignoredSetting "\\n"
55 , ignoredSetting "\\n"
56 , archivedTreeSetting "arch" (\val es -> es { exportArchivedTrees = val })
56 , archivedTreeSetting "arch" (\val es -> es { exportArchivedTrees = val })
57− , ignoredSetting "author"
57+ , booleanSetting "author" (\val es -> es { exportWithAuthor = val })
58 , ignoredSetting "c"
58 , ignoredSetting "c"
59 , ignoredSetting "creator"
59 , ignoredSetting "creator"
60 , complementableListSetting "d" (\val es -> es { exportDrawers = val })
60 , 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.
29-}
29-}
30module Text.Pandoc.Readers.Org.Meta
30module Text.Pandoc.Readers.Org.Meta
31 ( metaLine
31 ( metaLine
32+ , metaExport
32 ) where
33 ) where
33
34
34import Text.Pandoc.Readers.Org.BlockStarts
35import Text.Pandoc.Readers.Org.BlockStarts
@@ -48,6 +49,22 @@ import Data.List ( intersperse )
48import qualified Data.Map as M
49import qualified Data.Map as M
49import Network.HTTP ( urlEncode )
50import Network.HTTP ( urlEncode )
50
51
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+
51-- | Parse and handle a single line containing meta information
68-- | Parse and handle a single line containing meta information
52-- The order, in which blocks are tried, makes sure that we're not looking at
69-- The order, in which blocks are tried, makes sure that we're not looking at
53-- the beginning of a block, so we don't need to check for it
70-- 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
163 , exportSmartQuotes :: Bool -- ^ Parse quotes smartly
163 , exportSmartQuotes :: Bool -- ^ Parse quotes smartly
164 , exportSpecialStrings :: Bool -- ^ Parse ellipses and dashes smartly
164 , exportSpecialStrings :: Bool -- ^ Parse ellipses and dashes smartly
165 , exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
165 , exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
166+ , exportWithAuthor :: Bool -- ^ Include author in final meta-data
166 }
167 }
167
168
168instance Default ExportSettings where
169instance Default ExportSettings where
@@ -177,6 +178,7 @@ defaultExportSettings = ExportSettings
177 , exportSmartQuotes = True
178 , exportSmartQuotes = True
178 , exportSpecialStrings = True
179 , exportSpecialStrings = True
179 , exportSubSuperscripts = True
180 , exportSubSuperscripts = True
181+ , exportWithAuthor = True
180 }
182 }
181
183
182
184
tests/Tests/Readers/Org.hs+6
@@ -668,6 +668,12 @@ tests =
668 , headerWith ("subsection", [], []) 2 "subsection"
668 , headerWith ("subsection", [], []) 2 "subsection"
669 , orderedList [ para "list item 1", para "list item 2" ]
669 , orderedList [ para "list item 1", para "list item 2" ]
670 ]
670 ]
671+
672+ , "disable author export" =:
673+ unlines [ "#+OPTIONS: author:nil"
674+ , "#+AUTHOR: ShyGuy"
675+ ] =?>
676+ Pandoc nullMeta mempty
671 ]
677 ]
672 ]
678 ]
673
679