git.iko.soy/typeable/pandoc
on master help sign in
Org reader: omit, but warn about unknown export options
00ef038Albert Krewinkel
src/Text/Pandoc/Logging.hs+6
@@ -86,6 +86,7 @@ data LogMessage =
86 | NoTranslation String
86 | NoTranslation String
87 | CouldNotLoadTranslations String String
87 | CouldNotLoadTranslations String String
88 | UnexpectedXmlElement String String
88 | UnexpectedXmlElement String String
89+ | UnknownOrgExportOption String
89 deriving (Show, Eq, Data, Ord, Typeable, Generic)
90 deriving (Show, Eq, Data, Ord, Typeable, Generic)
90
91
91instance ToJSON LogMessage where
92instance ToJSON LogMessage where
@@ -201,6 +202,8 @@ instance ToJSON LogMessage where
201 UnexpectedXmlElement element parent ->
202 UnexpectedXmlElement element parent ->
202 ["element" .= Text.pack element,
203 ["element" .= Text.pack element,
203 "parent" .= Text.pack parent]
204 "parent" .= Text.pack parent]
205+ UnknownOrgExportOption option ->
206+ ["option" .= Text.pack option]
204
207
205
208
206showPos :: SourcePos -> String
209showPos :: SourcePos -> String
@@ -300,6 +303,8 @@ showLogMessage msg =
300 if null m then "" else '\n' : m
303 if null m then "" else '\n' : m
301 UnexpectedXmlElement element parent ->
304 UnexpectedXmlElement element parent ->
302 "Unexpected XML element " ++ element ++ " in " ++ parent
305 "Unexpected XML element " ++ element ++ " in " ++ parent
306+ UnknownOrgExportOption option ->
307+ "Ignoring unknown Org export option: " ++ option
303
308
304messageVerbosity:: LogMessage -> Verbosity
309messageVerbosity:: LogMessage -> Verbosity
305messageVerbosity msg =
310messageVerbosity msg =
@@ -339,3 +344,4 @@ messageVerbosity msg =
339 NoTranslation{} -> WARNING
344 NoTranslation{} -> WARNING
340 CouldNotLoadTranslations{} -> WARNING
345 CouldNotLoadTranslations{} -> WARNING
341 UnexpectedXmlElement {} -> WARNING
346 UnexpectedXmlElement {} -> WARNING
347+ UnknownOrgExportOption {} -> WARNING
src/Text/Pandoc/Readers/Org/ExportSettings.hs+13−3
@@ -13,6 +13,8 @@ module Text.Pandoc.Readers.Org.ExportSettings
13 ) where
13 ) where
14
14
15import Prelude
15import Prelude
16+import Text.Pandoc.Class (PandocMonad, report)
17+import Text.Pandoc.Logging (LogMessage (UnknownOrgExportOption))
16import Text.Pandoc.Readers.Org.ParserState
18import Text.Pandoc.Readers.Org.ParserState
17import Text.Pandoc.Readers.Org.Parsing
19import Text.Pandoc.Readers.Org.Parsing
18
20
@@ -21,14 +23,14 @@ import Data.Char (toLower)
21import Data.Maybe (listToMaybe)
23import Data.Maybe (listToMaybe)
22
24
23-- | Read and handle space separated org-mode export settings.
25-- | Read and handle space separated org-mode export settings.
24−exportSettings :: Monad m => OrgParser m ()
26+exportSettings :: PandocMonad m => OrgParser m ()
25−exportSettings = void $ sepBy spaces exportSetting
27+exportSettings = void $ sepBy skipSpaces exportSetting
26
28
27-- | Setter function for export settings.
29-- | Setter function for export settings.
28type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
30type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
29
31
30-- | Read and process a single org-mode export option.
32-- | Read and process a single org-mode export option.
31−exportSetting :: Monad m => OrgParser m ()
33+exportSetting :: PandocMonad m => OrgParser m ()
32exportSetting = choice
34exportSetting = choice
33 [ booleanSetting "^" (\val es -> es { exportSubSuperscripts = val })
35 [ booleanSetting "^" (\val es -> es { exportSubSuperscripts = val })
34 , booleanSetting "'" (\val es -> es { exportSmartQuotes = val })
36 , booleanSetting "'" (\val es -> es { exportSmartQuotes = val })
@@ -63,6 +65,7 @@ exportSetting = choice
63 , ignoredSetting "toc"
65 , ignoredSetting "toc"
64 , booleanSetting "todo" (\val es -> es { exportWithTodoKeywords = val })
66 , booleanSetting "todo" (\val es -> es { exportWithTodoKeywords = val })
65 , ignoredSetting "|"
67 , ignoredSetting "|"
68+ , ignoreAndWarn
66 ] <?> "export setting"
69 ] <?> "export setting"
67
70
68genericExportSetting :: Monad m
71genericExportSetting :: Monad m
@@ -144,6 +147,13 @@ complementableListSetting = genericExportSetting $ choice
144ignoredSetting :: Monad m => String -> OrgParser m ()
147ignoredSetting :: Monad m => String -> OrgParser m ()
145ignoredSetting s = try (() <$ string s <* char ':' <* many1 nonspaceChar)
148ignoredSetting s = try (() <$ string s <* char ':' <* many1 nonspaceChar)
146
149
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+
147-- | Read an elisp boolean. Only NIL is treated as false, non-NIL values are
157-- | Read an elisp boolean. Only NIL is treated as false, non-NIL values are
148-- interpreted as true.
158-- interpreted as true.
149elispBoolean :: Monad m => OrgParser m Bool
159elispBoolean :: Monad m => OrgParser m Bool
src/Text/Pandoc/Readers/Org/Meta.hs+1−1
@@ -131,7 +131,7 @@ accumulatingList key p = do
131--
131--
132-- export options
132-- export options
133--
133--
134−optionLine :: Monad m => OrgParser m ()
134+optionLine :: PandocMonad m => OrgParser m ()
135optionLine = try $ do
135optionLine = try $ do
136 key <- metaKey
136 key <- metaKey
137 case key of
137 case key of
test/Tests/Readers/Org/Directive.hs+18
@@ -184,6 +184,24 @@ tests =
184 ] =?>
184 ] =?>
185 headerWith ("wichtig", mempty, mempty) 1 "Wichtig"
185 headerWith ("wichtig", mempty, mempty) 1 "Wichtig"
186 ]
186 ]
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+ ]
187 ]
205 ]
188
206
189 , testGroup "Include"
207 , testGroup "Include"