git.iko.soy/typeable/pandoc
on master help sign in
Class: rename addWarning[WithPos] to warning[WithPos].

There's already a function addWarning in Parsing! Maybe we can dispense with that now, but I still like 'warning' better as a name.

commita4bd650277ac8fd2c952f2330e4d23a200d691a5 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 3 Dec 2016, 18:42 (10 years ago) parent63dc6bd
11 files changed+40−42
src/Text/Pandoc/Class.hs+10−12 src/Text/Pandoc/Readers/Docx.hs+2−2 src/Text/Pandoc/Readers/Markdown.hs+5−5 src/Text/Pandoc/Readers/RST.hs+7−7 src/Text/Pandoc/Readers/TWiki.hs+1−1 src/Text/Pandoc/Writers/Docx.hs+1−1 src/Text/Pandoc/Writers/EPUB.hs+2−2 src/Text/Pandoc/Writers/ICML.hs+2−2 src/Text/Pandoc/Writers/Math.hs+2−2 src/Text/Pandoc/Writers/ODT.hs+2−2 src/Text/Pandoc/Writers/RTF.hs+6−6
src/Text/Pandoc/Class.hs+10−12
@@ -36,8 +36,8 @@ module Text.Pandoc.Class ( PandocMonad(..)
3636 , PureState(..)
3737 , getPOSIXTime
3838 , getZonedTime
39− , addWarning
40− , addWarningWithPos
39+ , warning
40+ , warningWithPos
4141 , getWarnings
4242 , getMediaBag
4343 , setMediaBag
@@ -121,8 +121,8 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m, MonadState C
121121
122122-- Functions defined for all PandocMonad instances
123123
124−addWarning :: PandocMonad m => String -> m ()
125−addWarning msg = modify $ \st -> st{stWarnings = msg : stWarnings st}
124+warning :: PandocMonad m => String -> m ()
125+warning msg = modify $ \st -> st{stWarnings = msg : stWarnings st}
126126
127127getWarnings :: PandocMonad m => m [String]
128128getWarnings = gets stWarnings
@@ -152,14 +152,12 @@ getZonedTime = do
152152 tz <- getCurrentTimeZone
153153 return $ utcToZonedTime tz t
154154
155−addWarningWithPos :: PandocMonad m
156− => Maybe SourcePos
157− -> String
158− -> ParserT [Char] ParserState m ()
159−addWarningWithPos mbpos msg =
160− lift $
161− addWarning $
162− msg ++ maybe "" (\pos -> " " ++ show pos) mbpos
155+warningWithPos :: PandocMonad m
156+ => Maybe SourcePos
157+ -> String
158+ -> ParserT [Char] ParserState m ()
159+warningWithPos mbpos msg =
160+ lift $ warning $ msg ++ maybe "" (\pos -> " " ++ show pos) mbpos
163161
164162--
165163
src/Text/Pandoc/Readers/Docx.hs+2−2
@@ -108,7 +108,7 @@ readDocx :: PandocMonad m
108108readDocx opts bytes
109109 | Right archive <- toArchiveOrFail bytes
110110 , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do
111− mapM_ P.addWarning parserWarnings
111+ mapM_ P.warning parserWarnings
112112 (meta, blks) <- docxToOutput opts docx
113113 return $ Pandoc meta blks
114114readDocx _ _ =
@@ -334,7 +334,7 @@ blocksToInlinesWarn cmtId blks = do
334334 notParaOrPlain (Plain _) = False
335335 notParaOrPlain _ = True
336336 when (not $ null $ filter notParaOrPlain blkList)
337− ((lift . lift) $ P.addWarning $ "Docx comment " ++ cmtId ++ " will not retain formatting")
337+ ((lift . lift) $ P.warning $ "Docx comment " ++ cmtId ++ " will not retain formatting")
338338 return $ fromList $ blocksToInlines blkList
339339
340340parPartToInlines :: PandocMonad m => ParPart -> DocxContext m Inlines
src/Text/Pandoc/Readers/Markdown.hs+5−5
@@ -280,7 +280,7 @@ yamlMetaBlock = try $ do
280280 ) nullMeta hashmap
281281 Right Yaml.Null -> return nullMeta
282282 Right _ -> do
283− P.addWarningWithPos (Just pos) "YAML header is not an object"
283+ P.warningWithPos (Just pos) "YAML header is not an object"
284284 return nullMeta
285285 Left err' -> do
286286 case err' of
@@ -291,13 +291,13 @@ yamlMetaBlock = try $ do
291291 yamlLine = yline
292292 , yamlColumn = ycol
293293 }}) ->
294− P.addWarningWithPos (Just $ setSourceLine
294+ P.warningWithPos (Just $ setSourceLine
295295 (setSourceColumn pos
296296 (sourceColumn pos + ycol))
297297 (sourceLine pos + 1 + yline))
298298 $ "Could not parse YAML header: " ++
299299 problem
300− _ -> P.addWarningWithPos (Just pos)
300+ _ -> P.warningWithPos (Just pos)
301301 $ "Could not parse YAML header: " ++
302302 show err'
303303 return nullMeta
@@ -420,7 +420,7 @@ referenceKey = try $ do
420420 let oldkeys = stateKeys st
421421 let key = toKey raw
422422 case M.lookup key oldkeys of
423− Just _ -> P.addWarningWithPos (Just pos) $ "Duplicate link reference `" ++ raw ++ "'"
423+ Just _ -> P.warningWithPos (Just pos) $ "Duplicate link reference `" ++ raw ++ "'"
424424 Nothing -> return ()
425425 updateState $ \s -> s { stateKeys = M.insert key (target, attr') oldkeys }
426426 return $ return mempty
@@ -486,7 +486,7 @@ noteBlock = try $ do
486486 let newnote = (ref, parsed)
487487 oldnotes <- stateNotes' <$> getState
488488 case lookup ref oldnotes of
489− Just _ -> P.addWarningWithPos (Just pos) $ "Duplicate note reference `" ++ ref ++ "'"
489+ Just _ -> P.warningWithPos (Just pos) $ "Duplicate note reference `" ++ ref ++ "'"
490490 Nothing -> return ()
491491 updateState $ \s -> s { stateNotes' = newnote : oldnotes }
492492 return mempty
src/Text/Pandoc/Readers/RST.hs+7−7
@@ -626,7 +626,7 @@ directive' = do
626626 return $ B.divWith attrs children
627627 other -> do
628628 pos <- getPosition
629− P.addWarningWithPos (Just pos) $ "ignoring unknown directive: " ++ other
629+ P.warningWithPos (Just pos) $ "ignoring unknown directive: " ++ other
630630 return mempty
631631
632632-- TODO:
@@ -654,20 +654,20 @@ addNewRole roleString fields = do
654654
655655 -- warn about syntax we ignore
656656 flip mapM_ fields $ \(key, _) -> case key of
657− "language" -> when (baseRole /= "code") $ lift $ P.addWarning $
657+ "language" -> when (baseRole /= "code") $ lift $ P.warning $
658658 "ignoring :language: field because the parent of role :" ++
659659 role ++ ": is :" ++ baseRole ++ ": not :code:"
660− "format" -> when (baseRole /= "raw") $ lift $ P.addWarning $
660+ "format" -> when (baseRole /= "raw") $ lift $ P.warning $
661661 "ignoring :format: field because the parent of role :" ++
662662 role ++ ": is :" ++ baseRole ++ ": not :raw:"
663− _ -> lift $ P.addWarning $ "ignoring unknown field :" ++ key ++
663+ _ -> lift $ P.warning $ "ignoring unknown field :" ++ key ++
664664 ": in definition of role :" ++ role ++ ": in"
665665 when (parentRole == "raw" && countKeys "format" > 1) $
666− lift $ P.addWarning $
666+ lift $ P.warning $
667667 "ignoring :format: fields after the first in the definition of role :"
668668 ++ role ++": in"
669669 when (parentRole == "code" && countKeys "language" > 1) $
670− lift $ P.addWarning $
670+ lift $ P.warning $
671671 "ignoring :language: fields after the first in the definition of role :"
672672 ++ role ++": in"
673673
@@ -1065,7 +1065,7 @@ renderRole contents fmt role attr = case role of
10651065 renderRole contents newFmt newRole newAttr
10661066 Nothing -> do
10671067 pos <- getPosition
1068− P.addWarningWithPos (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in"
1068+ P.warningWithPos (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in"
10691069 return $ B.str contents -- Undefined role
10701070 where
10711071 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
src/Text/Pandoc/Readers/TWiki.hs+1−1
@@ -58,7 +58,7 @@ readTWiki :: PandocMonad m
5858 -> m Pandoc
5959readTWiki opts s = case readTWikiWithWarnings' opts s of
6060 Right (doc, warns) -> do
61− mapM_ P.addWarning warns
61+ mapM_ P.warning warns
6262 return doc
6363 Left e -> throwError e
6464
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -1182,7 +1182,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
11821182 res <- (lift . lift) $ P.fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
11831183 case res of
11841184 Left (_ :: E.SomeException) -> do
1185− (lift . lift) $ P.addWarning ("Could not find image `" ++ src ++ "', skipping...")
1185+ (lift . lift) $ P.warning ("Could not find image `" ++ src ++ "', skipping...")
11861186 -- emit alt text
11871187 inlinesToOpenXML opts alt
11881188 Right (img, mt) -> do
src/Text/Pandoc/Writers/EPUB.hs+2−2
@@ -398,7 +398,7 @@ pandocToEPUB opts doc@(Pandoc meta _) = do
398398 let matchingGlob f = do
399399 xs <- lift $ P.glob f
400400 when (null xs) $
401− lift $ P.addWarning $ f ++ " did not match any font files."
401+ lift $ P.warning $ f ++ " did not match any font files."
402402 return xs
403403 let mkFontEntry f = mkEntry (takeFileName f) `fmap` (lift $ P.readFileLazy f)
404404 fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
@@ -864,7 +864,7 @@ modifyMediaRef opts oldsrc = do
864864 (new, mbEntry) <-
865865 case res of
866866 Left _ -> do
867− lift $ P.addWarning $ "Could not find media `" ++ oldsrc ++ "', skipping..."
867+ lift $ P.warning $ "Could not find media `" ++ oldsrc ++ "', skipping..."
868868 return (oldsrc, Nothing)
869869 Right (img,mbMime) -> do
870870 let new = "media/file" ++ show (length media) ++
src/Text/Pandoc/Writers/ICML.hs+2−2
@@ -537,13 +537,13 @@ imageICML opts style attr (src, _) = do
537537 res <- lift $ P.fetchItem (writerSourceURL opts) src
538538 imgS <- case res of
539539 Left (_) -> do
540− lift $ P.addWarning $ "Could not find image `" ++ src ++ "', skipping..."
540+ lift $ P.warning $ "Could not find image `" ++ src ++ "', skipping..."
541541 return def
542542 Right (img, _) -> do
543543 case imageSize img of
544544 Right size -> return size
545545 Left msg -> do
546− lift $ P.addWarning $ "Could not determine image size in `" ++
546+ lift $ P.warning $ "Could not determine image size in `" ++
547547 src ++ "': " ++ msg
548548 return def
549549 let (ow, oh) = sizeInPoints imgS
src/Text/Pandoc/Writers/Math.hs+2−2
@@ -20,7 +20,7 @@ texMathToInlines mt inp = do
2020 case res of
2121 Right (Just ils) -> return ils
2222 Right (Nothing) -> do
23− addWarning $ "Could not render TeX math as unicode, rendering as raw TeX:\n" ++ inp
23+ warning $ "Could not render TeX math as unicode, rendering as raw TeX:\n" ++ inp
2424 return [mkFallback mt inp]
2525 Left il -> return [il]
2626
@@ -40,7 +40,7 @@ convertMath writer mt str = do
4040 case writer dt <$> readTeX str of
4141 Right r -> return (Right r)
4242 Left e -> do
43− addWarning $ "Could not convert TeX math, rendering as raw TeX:\n" ++
43+ warning $ "Could not convert TeX math, rendering as raw TeX:\n" ++
4444 str ++ "\n" ++ e
4545 return (Left $ mkFallback mt str)
4646 where dt = case mt of
src/Text/Pandoc/Writers/ODT.hs+2−2
@@ -147,13 +147,13 @@ transformPicMath opts (Image attr@(id', cls, _) lab (src,t)) = do
147147 res <- lift $ P.fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
148148 case res of
149149 Left (_ :: E.SomeException) -> do
150− lift $ P.addWarning $ "Could not find image `" ++ src ++ "', skipping..."
150+ lift $ P.warning $ "Could not find image `" ++ src ++ "', skipping..."
151151 return $ Emph lab
152152 Right (img, mbMimeType) -> do
153153 (ptX, ptY) <- case imageSize img of
154154 Right s -> return $ sizeInPoints s
155155 Left msg -> do
156− lift $ P.addWarning $ "Could not determine image size in `" ++
156+ lift $ P.warning $ "Could not determine image size in `" ++
157157 src ++ "': " ++ msg
158158 return (100, 100)
159159 let dims =
src/Text/Pandoc/Writers/RTF.hs+6−6
@@ -36,7 +36,7 @@ import Text.Pandoc.Writers.Shared
3636import Text.Pandoc.Writers.Math
3737import Text.Pandoc.Templates (renderTemplate')
3838import Text.Pandoc.Walk
39−import Text.Pandoc.Class (addWarning)
39+import Text.Pandoc.Class (warning)
4040import Data.List ( isSuffixOf, intercalate )
4141import Data.Char ( ord, chr, isDigit )
4242import qualified Data.ByteString as B
@@ -64,7 +64,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
6464 _ -> throwError $ PandocSomeError "Unknown file type"
6565 sizeSpec <- case imageSize imgdata of
6666 Left msg -> do
67− addWarning $ "Could not determine image size in `" ++
67+ warning $ "Could not determine image size in `" ++
6868 src ++ "': " ++ msg
6969 return ""
7070 Right sz -> return $ "\\picw" ++ show xpx ++
@@ -78,17 +78,17 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
7878 concat bytes ++ "}"
7979 if B.null imgdata
8080 then do
81− addWarning $ "Image " ++ src ++ " contained no data, skipping."
81+ warning $ "Image " ++ src ++ " contained no data, skipping."
8282 return x
8383 else return $ RawInline (Format "rtf") raw
8484 | otherwise -> do
85− addWarning $ "Image " ++ src ++ " is not a jpeg or png, skipping."
85+ warning $ "Image " ++ src ++ " is not a jpeg or png, skipping."
8686 return x
8787 Right (_, Nothing) -> do
88− addWarning $ "Could not determine image type for " ++ src ++ ", skipping."
88+ warning $ "Could not determine image type for " ++ src ++ ", skipping."
8989 return x
9090 Left e -> do
91− addWarning $ "Could not fetch image " ++ src ++ "\n" ++ show e
91+ warning $ "Could not fetch image " ++ src ++ "\n" ++ show e
9292 return x
9393rtfEmbedImage _ x = return x
9494