git.iko.soy/typeable/pandoc
on master help sign in
FB2 reader: replace some errors with warnings
5ce91a7Alexander Krotov
src/Text/Pandoc/Logging.hs+7
@@ -101,6 +101,7 @@ data LogMessage =
101 | Deprecated String String
101 | Deprecated String String
102 | NoTranslation String
102 | NoTranslation String
103 | CouldNotLoadTranslations String String
103 | CouldNotLoadTranslations String String
104+ | UnexpectedXmlElement String String
104 deriving (Show, Eq, Data, Ord, Typeable, Generic)
105 deriving (Show, Eq, Data, Ord, Typeable, Generic)
105
106
106instance ToJSON LogMessage where
107instance ToJSON LogMessage where
@@ -211,6 +212,9 @@ instance ToJSON LogMessage where
211 CouldNotLoadTranslations lang msg ->
212 CouldNotLoadTranslations lang msg ->
212 ["lang" .= Text.pack lang,
213 ["lang" .= Text.pack lang,
213 "message" .= Text.pack msg]
214 "message" .= Text.pack msg]
215+ UnexpectedXmlElement element parent ->
216+ ["element" .= Text.pack element,
217+ "parent" .= Text.pack parent]
214
218
215
219
216showPos :: SourcePos -> String
220showPos :: SourcePos -> String
@@ -305,6 +309,8 @@ showLogMessage msg =
305 CouldNotLoadTranslations lang m ->
309 CouldNotLoadTranslations lang m ->
306 "Could not load translations for " ++ lang ++
310 "Could not load translations for " ++ lang ++
307 if null m then "" else '\n' : m
311 if null m then "" else '\n' : m
312+ UnexpectedXmlElement element parent ->
313+ "Unexpected XML element " ++ element ++ " in " ++ parent
308
314
309messageVerbosity:: LogMessage -> Verbosity
315messageVerbosity:: LogMessage -> Verbosity
310messageVerbosity msg =
316messageVerbosity msg =
@@ -342,3 +348,4 @@ messageVerbosity msg =
342 Deprecated{} -> WARNING
348 Deprecated{} -> WARNING
343 NoTranslation{} -> WARNING
349 NoTranslation{} -> WARNING
344 CouldNotLoadTranslations{} -> WARNING
350 CouldNotLoadTranslations{} -> WARNING
351+ UnexpectedXmlElement {} -> WARNING
src/Text/Pandoc/Readers/FB2.hs+11−9
@@ -46,6 +46,7 @@ import Control.Monad.State.Strict
46import Data.ByteString.Lazy.Char8 ( pack )
46import Data.ByteString.Lazy.Char8 ( pack )
47import Data.ByteString.Base64.Lazy
47import Data.ByteString.Base64.Lazy
48import Data.Char (isSpace, toUpper)
48import Data.Char (isSpace, toUpper)
49+import Data.Functor
49import Data.List (dropWhileEnd, intersperse)
50import Data.List (dropWhileEnd, intersperse)
50import Data.List.Split (splitOn)
51import Data.List.Split (splitOn)
51import Data.Text (Text)
52import Data.Text (Text)
@@ -53,8 +54,9 @@ import Data.Default
53import Data.Maybe
54import Data.Maybe
54import Text.HTML.TagSoup.Entity (lookupEntity)
55import Text.HTML.TagSoup.Entity (lookupEntity)
55import Text.Pandoc.Builder
56import Text.Pandoc.Builder
56−import Text.Pandoc.Class (PandocMonad, insertMedia)
57+import Text.Pandoc.Class (PandocMonad, insertMedia, report)
57import Text.Pandoc.Error
58import Text.Pandoc.Error
59+import Text.Pandoc.Logging
58import Text.Pandoc.Options
60import Text.Pandoc.Options
59import Text.Pandoc.Shared (crFilter)
61import Text.Pandoc.Shared (crFilter)
60import Text.XML.Light
62import Text.XML.Light
@@ -122,7 +124,7 @@ parseBlock (Elem e) =
122 case qName $ elName e of
124 case qName $ elName e of
123 "?xml" -> pure mempty
125 "?xml" -> pure mempty
124 "FictionBook" -> mconcat <$> mapM parseFictionBookChild (elChildren e)
126 "FictionBook" -> mconcat <$> mapM parseFictionBookChild (elChildren e)
125− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ ".")
127+ name -> report (UnexpectedXmlElement name "root") $> mempty
126parseBlock _ = pure mempty
128parseBlock _ = pure mempty
127
129
128-- | Parse a child of @\<FictionBook>@ element.
130-- | Parse a child of @\<FictionBook>@ element.
@@ -133,7 +135,7 @@ parseFictionBookChild e =
133 "description" -> mempty <$ mapM_ parseDescriptionChild (elChildren e)
135 "description" -> mempty <$ mapM_ parseDescriptionChild (elChildren e)
134 "body" -> mconcat <$> mapM parseBodyChild (elChildren e)
136 "body" -> mconcat <$> mapM parseBodyChild (elChildren e)
135 "binary" -> mempty <$ parseBinaryElement e
137 "binary" -> mempty <$ parseBinaryElement e
136− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ "in FictionBook.")
138+ name -> report (UnexpectedXmlElement name "FictionBook") $> mempty
137
139
138-- | Parse a child of @\<description>@ element.
140-- | Parse a child of @\<description>@ element.
139parseDescriptionChild :: PandocMonad m => Element -> FB2 m ()
141parseDescriptionChild :: PandocMonad m => Element -> FB2 m ()
@@ -226,7 +228,7 @@ parseCiteChild e =
226 "subtitle" -> parseSubtitle e
228 "subtitle" -> parseSubtitle e
227 "table" -> parseTable e
229 "table" -> parseTable e
228 "text-author" -> para <$> parsePType e
230 "text-author" -> para <$> parsePType e
229− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ " in cite.")
231+ name -> report (UnexpectedXmlElement name "cite") $> mempty
230
232
231-- | Parse @poemType@
233-- | Parse @poemType@
232parsePoem :: PandocMonad m => Element -> FB2 m Blocks
234parsePoem :: PandocMonad m => Element -> FB2 m Blocks
@@ -241,7 +243,7 @@ parsePoemChild e =
241 "stanza" -> parseStanza e
243 "stanza" -> parseStanza e
242 "text-author" -> para <$> parsePType e
244 "text-author" -> para <$> parsePType e
243 "date" -> pure $ para $ text $ strContent e
245 "date" -> pure $ para $ text $ strContent e
244− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ " in poem.")
246+ name -> report (UnexpectedXmlElement name "poem") $> mempty
245
247
246parseStanza :: PandocMonad m => Element -> FB2 m Blocks
248parseStanza :: PandocMonad m => Element -> FB2 m Blocks
247parseStanza e = fromList . joinLineBlocks . toList . mconcat <$> mapM parseStanzaChild (elChildren e)
249parseStanza e = fromList . joinLineBlocks . toList . mconcat <$> mapM parseStanzaChild (elChildren e)
@@ -257,7 +259,7 @@ parseStanzaChild e =
257 "title" -> parseTitle e
259 "title" -> parseTitle e
258 "subtitle" -> parseSubtitle e
260 "subtitle" -> parseSubtitle e
259 "v" -> lineBlock . (:[]) <$> parsePType e
261 "v" -> lineBlock . (:[]) <$> parsePType e
260− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ " in stanza.")
262+ name -> report (UnexpectedXmlElement name "stanza") $> mempty
261
263
262-- | Parse @epigraphType@
264-- | Parse @epigraphType@
263parseEpigraph :: PandocMonad m => Element -> FB2 m Blocks
265parseEpigraph :: PandocMonad m => Element -> FB2 m Blocks
@@ -273,7 +275,7 @@ parseEpigraphChild e =
273 "cite" -> parseCite e
275 "cite" -> parseCite e
274 "empty-line" -> pure horizontalRule
276 "empty-line" -> pure horizontalRule
275 "text-author" -> para <$> parsePType e
277 "text-author" -> para <$> parsePType e
276− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ " in epigraph.")
278+ name -> report (UnexpectedXmlElement name "epigraph") $> mempty
277
279
278-- | Parse @annotationType@
280-- | Parse @annotationType@
279parseAnnotation :: PandocMonad m => Element -> FB2 m Blocks
281parseAnnotation :: PandocMonad m => Element -> FB2 m Blocks
@@ -288,7 +290,7 @@ parseAnnotationChild e =
288 "subtitle" -> parseSubtitle e
290 "subtitle" -> parseSubtitle e
289 "table" -> parseTable e
291 "table" -> parseTable e
290 "empty-line" -> pure horizontalRule
292 "empty-line" -> pure horizontalRule
291− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ " in annotation.")
293+ name -> report (UnexpectedXmlElement name "annotation") $> mempty
292
294
293-- | Parse @sectionType@
295-- | Parse @sectionType@
294parseSection :: PandocMonad m => Element -> FB2 m Blocks
296parseSection :: PandocMonad m => Element -> FB2 m Blocks
@@ -314,7 +316,7 @@ parseSectionChild e =
314 "subtitle" -> parseSubtitle e
316 "subtitle" -> parseSubtitle e
315 "p" -> para <$> parsePType e
317 "p" -> para <$> parsePType e
316 "section" -> parseSection e
318 "section" -> parseSection e
317− name -> throwError $ PandocParseError ("Couldn't parse FB2 file: unexpected element " ++ name ++ " in section.")
319+ name -> report (UnexpectedXmlElement name "section") $> mempty
318
320
319-- | parse @styleType@
321-- | parse @styleType@
320parseStyleType :: PandocMonad m => Element -> FB2 m Inlines
322parseStyleType :: PandocMonad m => Element -> FB2 m Inlines