git.iko.soy/typeable/pandoc
on master help sign in
Org reader: omit, but warn about unknown export options

Unknown export options are properly ignored and omitted from the output.

commit00ef03827e4ab77a1213b2adf261c818ddae076d authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 13 May 2019, 22:25 (7 years ago) parent1d033a2
4 files changed+38−4
src/Text/Pandoc/Logging.hs+6 src/Text/Pandoc/Readers/Org/ExportSettings.hs+13−3 src/Text/Pandoc/Readers/Org/Meta.hs+1−1 test/Tests/Readers/Org/Directive.hs+18
src/Text/Pandoc/Logging.hs+6
@@ -86,6 +86,7 @@ data LogMessage =
8686 | NoTranslation String
8787 | CouldNotLoadTranslations String String
8888 | UnexpectedXmlElement String String
89+ | UnknownOrgExportOption String
8990 deriving (Show, Eq, Data, Ord, Typeable, Generic)
9091
9192instance ToJSON LogMessage where
@@ -201,6 +202,8 @@ instance ToJSON LogMessage where
201202 UnexpectedXmlElement element parent ->
202203 ["element" .= Text.pack element,
203204 "parent" .= Text.pack parent]
205+ UnknownOrgExportOption option ->
206+ ["option" .= Text.pack option]
204207
205208
206209showPos :: SourcePos -> String
@@ -300,6 +303,8 @@ showLogMessage msg =
300303 if null m then "" else '\n' : m
301304 UnexpectedXmlElement element parent ->
302305 "Unexpected XML element " ++ element ++ " in " ++ parent
306+ UnknownOrgExportOption option ->
307+ "Ignoring unknown Org export option: " ++ option
303308
304309messageVerbosity:: LogMessage -> Verbosity
305310messageVerbosity msg =
@@ -339,3 +344,4 @@ messageVerbosity msg =
339344 NoTranslation{} -> WARNING
340345 CouldNotLoadTranslations{} -> WARNING
341346 UnexpectedXmlElement {} -> WARNING
347+ UnknownOrgExportOption {} -> WARNING
src/Text/Pandoc/Readers/Org/ExportSettings.hs+13−3
@@ -13,6 +13,8 @@ module Text.Pandoc.Readers.Org.ExportSettings
1313 ) where
1414
1515import Prelude
16+import Text.Pandoc.Class (PandocMonad, report)
17+import Text.Pandoc.Logging (LogMessage (UnknownOrgExportOption))
1618import Text.Pandoc.Readers.Org.ParserState
1719import Text.Pandoc.Readers.Org.Parsing
1820
@@ -21,14 +23,14 @@ import Data.Char (toLower)
2123import Data.Maybe (listToMaybe)
2224
2325-- | Read and handle space separated org-mode export settings.
24−exportSettings :: Monad m => OrgParser m ()
25−exportSettings = void $ sepBy spaces exportSetting
26+exportSettings :: PandocMonad m => OrgParser m ()
27+exportSettings = void $ sepBy skipSpaces exportSetting
2628
2729-- | Setter function for export settings.
2830type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
2931
3032-- | Read and process a single org-mode export option.
31−exportSetting :: Monad m => OrgParser m ()
33+exportSetting :: PandocMonad m => OrgParser m ()
3234exportSetting = choice
3335 [ booleanSetting "^" (\val es -> es { exportSubSuperscripts = val })
3436 , booleanSetting "'" (\val es -> es { exportSmartQuotes = val })
@@ -63,6 +65,7 @@ exportSetting = choice
6365 , ignoredSetting "toc"
6466 , booleanSetting "todo" (\val es -> es { exportWithTodoKeywords = val })
6567 , ignoredSetting "|"
68+ , ignoreAndWarn
6669 ] <?> "export setting"
6770
6871genericExportSetting :: Monad m
@@ -144,6 +147,13 @@ complementableListSetting = genericExportSetting $ choice
144147ignoredSetting :: Monad m => String -> OrgParser m ()
145148ignoredSetting s = try (() <$ string s <* char ':' <* many1 nonspaceChar)
146149
150+-- | Read any setting string, but ignore it and emit a warning.
151+ignoreAndWarn :: PandocMonad m => OrgParser m ()
152+ignoreAndWarn = try $ do
153+ opt <- many1 nonspaceChar
154+ report (UnknownOrgExportOption opt)
155+ return ()
156+
147157-- | Read an elisp boolean. Only NIL is treated as false, non-NIL values are
148158-- interpreted as true.
149159elispBoolean :: Monad m => OrgParser m Bool
src/Text/Pandoc/Readers/Org/Meta.hs+1−1
@@ -131,7 +131,7 @@ accumulatingList key p = do
131131--
132132-- export options
133133--
134−optionLine :: Monad m => OrgParser m ()
134+optionLine :: PandocMonad m => OrgParser m ()
135135optionLine = try $ do
136136 key <- metaKey
137137 case key of
test/Tests/Readers/Org/Directive.hs+18
@@ -184,6 +184,24 @@ tests =
184184 ] =?>
185185 headerWith ("wichtig", mempty, mempty) 1 "Wichtig"
186186 ]
187+
188+ , testGroup "unknown options"
189+ [ "unknown options are ignored" =:
190+ T.unlines [ "#+OPTIONS: does-not-exist:t "] =?>
191+ (mempty :: Pandoc)
192+
193+ , "highlighting after unknown option" =:
194+ T.unlines [ "#+OPTIONS: nope"
195+ , "/yup/"
196+ ] =?>
197+ para (emph "yup")
198+
199+ , "unknown option interleaved with known" =:
200+ T.unlines [ "#+OPTIONS: tags:nil foo:bar todo:nil"
201+ , "* DONE ignore things :easy:"
202+ ] =?>
203+ headerWith ("ignore-things", [], mempty) 1 "ignore things"
204+ ]
187205 ]
188206
189207 , testGroup "Include"