git.iko.soy/typeable/pandoc
on master help sign in
HLint: use fromMaybe

Replace uses of `maybe x id` with `fromMaybe x`.

commit3d70059a4896c66cab59832a3ed9eb8334b84a2f authorHenry de Valence <hdevalence@hdevalence.ca> dateThu 19 Dec 2013, 21:07 (13 years ago) parentc8fc0a0
10 files changed+30−23
src/Text/Pandoc/PDF.hs+2−1 src/Text/Pandoc/Readers/DocBook.hs+4−3 src/Text/Pandoc/Readers/HTML.hs+2−2 src/Text/Pandoc/Readers/Markdown.hs+2−2 src/Text/Pandoc/Readers/MediaWiki.hs+4−3 src/Text/Pandoc/Writers/Docx.hs+4−2 src/Text/Pandoc/Writers/EPUB.hs+6−6 src/Text/Pandoc/Writers/HTML.hs+2−2 src/Text/Pandoc/Writers/LaTeX.hs+2−1 src/Text/Pandoc/Writers/ODT.hs+2−1
src/Text/Pandoc/PDF.hs+2−1
@@ -41,6 +41,7 @@ import System.Directory
4141import System.Environment
4242import Control.Monad (unless)
4343import Data.List (isInfixOf)
44+import Data.Maybe (fromMaybe)
4445import qualified Data.ByteString.Base64 as B64
4546import qualified Text.Pandoc.UTF8 as UTF8
4647import Text.Pandoc.Definition
@@ -87,7 +88,7 @@ handleImage' baseURL tmpdir (Image ils (src,tit)) = do
8788 res <- fetchItem baseURL src
8889 case res of
8990 Right (contents, Just mime) -> do
90− let ext = maybe (takeExtension src) id $
91+ let ext = fromMaybe (takeExtension src) $
9192 extensionFromMimeType mime
9293 let basename = UTF8.toString $ B64.encode $ UTF8.fromString src
9394 let fname = tmpdir </> basename <.> ext
src/Text/Pandoc/Readers/DocBook.hs+4−3
@@ -12,6 +12,7 @@ import Data.Char (isSpace)
1212import Control.Monad.State
1313import Control.Applicative ((<$>))
1414import Data.List (intersperse)
15+import Data.Maybe (fromMaybe)
1516
1617{-
1718
@@ -683,7 +684,7 @@ parseBlock (Elem e) =
683684 "lowerroman" -> LowerRoman
684685 "upperroman" -> UpperRoman
685686 _ -> Decimal
686− let start = maybe 1 id $
687+ let start = fromMaybe 1 $
687688 (attrValue "override" <$> filterElement (named "listitem") e)
688689 >>= safeRead
689690 orderedListWith (start,listStyle,DefaultDelim)
@@ -779,7 +780,7 @@ parseBlock (Elem e) =
779780 caption <- case filterChild isCaption e of
780781 Just t -> getInlines t
781782 Nothing -> return mempty
782− let e' = maybe e id $ filterChild (named "tgroup") e
783+ let e' = fromMaybe e $ filterChild (named "tgroup") e
783784 let isColspec x = named "colspec" x || named "col" x
784785 let colspecs = case filterChild (named "colgroup") e' of
785786 Just c -> filterChildren isColspec c
@@ -801,7 +802,7 @@ parseBlock (Elem e) =
801802 Just "center" -> AlignCenter
802803 _ -> AlignDefault
803804 let toWidth c = case findAttr (unqual "colwidth") c of
804− Just w -> maybe 0 id
805+ Just w -> fromMaybe 0
805806 $ safeRead $ '0': filter (\x ->
806807 (x >= '0' && x <= '9')
807808 || x == '.') w
src/Text/Pandoc/Readers/HTML.hs+2−2
@@ -207,7 +207,7 @@ pHeader = try $ do
207207 let bodyTitle = TagOpen tagtype attr ~== TagOpen "h1" [("class","title")]
208208 let level = read (drop 1 tagtype)
209209 contents <- liftM concat $ manyTill inline (pCloses tagtype <|> eof)
210− let ident = maybe "" id $ lookup "id" attr
210+ let ident = fromMaybe "" $ lookup "id" attr
211211 let classes = maybe [] words $ lookup "class" attr
212212 let keyvals = [(k,v) | (k,v) <- attr, k /= "class", k /= "id"]
213213 return $ if bodyTitle
@@ -257,7 +257,7 @@ pCol = try $ do
257257 skipMany pBlank
258258 return $ case lookup "width" attribs of
259259 Just x | not (null x) && last x == '%' ->
260− maybe 0.0 id $ safeRead ('0':'.':init x)
260+ fromMaybe 0.0 $ safeRead ('0':'.':init x)
261261 _ -> 0.0
262262
263263pColgroup :: TagParser [Double]
src/Text/Pandoc/Readers/Markdown.hs+2−2
@@ -1722,7 +1722,7 @@ spanHtml = try $ do
17221722 guardEnabled Ext_markdown_in_html_blocks
17231723 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "span" [])
17241724 contents <- mconcat <$> manyTill inline (htmlTag (~== TagClose "span"))
1725− let ident = maybe "" id $ lookup "id" attrs
1725+ let ident = fromMaybe "" $ lookup "id" attrs
17261726 let classes = maybe [] words $ lookup "class" attrs
17271727 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
17281728 return $ B.spanWith (ident, classes, keyvals) <$> contents
@@ -1732,7 +1732,7 @@ divHtml = try $ do
17321732 guardEnabled Ext_markdown_in_html_blocks
17331733 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "div" [])
17341734 contents <- mconcat <$> manyTill block (htmlTag (~== TagClose "div"))
1735− let ident = maybe "" id $ lookup "id" attrs
1735+ let ident = fromMaybe "" $ lookup "id" attrs
17361736 let classes = maybe [] words $ lookup "class" attrs
17371737 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
17381738 return $ B.divWith (ident, classes, keyvals) <$> contents
src/Text/Pandoc/Readers/MediaWiki.hs+4−3
@@ -54,6 +54,7 @@ import Data.Sequence (viewl, ViewL(..), (<|))
5454import qualified Data.Foldable as F
5555import qualified Data.Map as M
5656import Data.Char (isDigit, isSpace)
57+import Data.Maybe (fromMaybe)
5758
5859-- | Read mediawiki from an input string and return a Pandoc document.
5960readMediaWiki :: ReaderOptions -- ^ Reader options
@@ -204,7 +205,7 @@ table = do
204205 tableStart
205206 styles <- option [] parseAttrs <* blankline
206207 let tableWidth = case lookup "width" styles of
207− Just w -> maybe 1.0 id $ parseWidth w
208+ Just w -> fromMaybe 1.0 $ parseWidth w
208209 Nothing -> 1.0
209210 caption <- option mempty tableCaption
210211 optional rowsep
@@ -285,7 +286,7 @@ tableCell = try $ do
285286 Just "center" -> AlignCenter
286287 _ -> AlignDefault
287288 let width = case lookup "width" attrs of
288− Just xs -> maybe 0.0 id $ parseWidth xs
289+ Just xs -> fromMaybe 0.0 $ parseWidth xs
289290 Nothing -> 0.0
290291 return ((align, width), bs)
291292
@@ -387,7 +388,7 @@ orderedList =
387388 spaces
388389 items <- many (listItem '#' <|> li)
389390 optional (htmlTag (~== TagClose "ol"))
390− let start = maybe 1 id $ safeRead $ fromAttrib "start" tag
391+ let start = fromMaybe 1 $ safeRead $ fromAttrib "start" tag
391392 return $ B.orderedListWith (start, DefaultStyle, DefaultDelim) items
392393
393394definitionList :: MWParser Blocks
src/Text/Pandoc/Writers/Docx.hs+4−2
@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2929Conversion of 'Pandoc' documents to docx.
3030-}
3131module Text.Pandoc.Writers.Docx ( writeDocx ) where
32+import Data.Maybe (fromMaybe)
3233import Data.List ( intercalate, groupBy )
3334import qualified Data.ByteString as B
3435import qualified Data.ByteString.Lazy as BL
@@ -130,7 +131,8 @@ writeDocx opts doc@(Pandoc meta _) = do
130131 let mkOverrideNode (part', contentType') = mknode "Override"
131132 [("PartName",part'),("ContentType",contentType')] ()
132133 let mkImageOverride (_, imgpath, mbMimeType, _, _) =
133− mkOverrideNode ("/word/" ++ imgpath, maybe "application/octet-stream" id mbMimeType)
134+ mkOverrideNode ("/word/" ++ imgpath,
135+ fromMaybe "application/octet-stream" mbMimeType)
134136 let overrides = map mkOverrideNode
135137 [("/word/webSettings.xml",
136138 "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml")
@@ -322,7 +324,7 @@ mkNum markers marker numid =
322324 NumberMarker _ _ start ->
323325 map (\lvl -> mknode "w:lvlOverride" [("w:ilvl",show (lvl :: Int))]
324326 $ mknode "w:startOverride" [("w:val",show start)] ()) [0..6]
325− where absnumid = maybe 0 id $ M.lookup marker markers
327+ where absnumid = fromMaybe 0 $ M.lookup marker markers
326328
327329mkAbstractNum :: (ListMarker,Int) -> IO Element
328330mkAbstractNum (marker,numid) = do
src/Text/Pandoc/Writers/EPUB.hs+6−6
@@ -176,8 +176,8 @@ addMetadataFromXML e@(Element (QName name _ (Just "dc")) attrs _ _) md
176176 , titleFileAs = getAttr "file-as"
177177 , titleType = getAttr "type"
178178 } : epubTitle md }
179− | name == "date" = md{ epubDate = maybe "" id $ normalizeDate'
180− $ strContent e }
179+ | name == "date" = md{ epubDate = fromMaybe "" $ normalizeDate'
180+ $ strContent e }
181181 | name == "language" = md{ epubLanguage = strContent e }
182182 | name == "creator" = md{ epubCreator =
183183 Creator{ creatorText = strContent e
@@ -271,7 +271,7 @@ metadataFromMeta opts meta = EPUBMetadata{
271271 }
272272 where identifiers = getIdentifier meta
273273 titles = getTitle meta
274− date = maybe "" id $
274+ date = fromMaybe "" $
275275 (metaValueToString <$> lookupMeta "date" meta) >>= normalizeDate'
276276 language = maybe "" metaValueToString $
277277 lookupMeta "language" meta `mplus` lookupMeta "lang" meta
@@ -297,7 +297,7 @@ writeEPUB :: WriterOptions -- ^ Writer options
297297 -> Pandoc -- ^ Document to convert
298298 -> IO B.ByteString
299299writeEPUB opts doc@(Pandoc meta _) = do
300− let version = maybe EPUB2 id (writerEpubVersion opts)
300+ let version = fromMaybe EPUB2 (writerEpubVersion opts)
301301 let epub3 = version == EPUB3
302302 epochtime <- floor `fmap` getPOSIXTime
303303 let mkEntry path content = toEntry path epochtime content
@@ -401,7 +401,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
401401 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
402402 $ renderHtml
403403 $ writeHtml opts'{ writerNumberOffset =
404− maybe [] id mbnum }
404+ fromMaybe [] mbnum }
405405 $ case bs of
406406 (Header _ _ xs : _) ->
407407 Pandoc (setMeta "title" (fromList xs) nullMeta) bs
@@ -436,7 +436,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
436436 let fontNode ent = unode "item" !
437437 [("id", takeBaseName $ eRelativePath ent),
438438 ("href", eRelativePath ent),
439− ("media-type", maybe "" id $ getMimeType $ eRelativePath ent)] $ ()
439+ ("media-type", fromMaybe "" $ getMimeType $ eRelativePath ent)] $ ()
440440 let plainTitle = case docTitle meta of
441441 [] -> case epubTitle metadata of
442442 [] -> "UNTITLED"
src/Text/Pandoc/Writers/HTML.hs+2−2
@@ -45,7 +45,7 @@ import Numeric ( showHex )
4545import Data.Char ( ord, toLower )
4646import Data.List ( isPrefixOf, intersperse )
4747import Data.String ( fromString )
48−import Data.Maybe ( catMaybes )
48+import Data.Maybe ( catMaybes, fromMaybe )
4949import Control.Monad.State
5050import Text.Blaze.Html hiding(contents)
5151import Text.Blaze.Internal(preEscapedString)
@@ -118,7 +118,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
118118 let stringifyHTML = escapeStringForXML . stringify
119119 let authsMeta = map stringifyHTML $ docAuthors meta
120120 let dateMeta = stringifyHTML $ docDate meta
121− let slideLevel = maybe (getSlideLevel blocks) id $ writerSlideLevel opts
121+ let slideLevel = fromMaybe (getSlideLevel blocks) $ writerSlideLevel opts
122122 let sects = hierarchicalize $
123123 if writerSlideVariant opts == NoSlides
124124 then blocks
src/Text/Pandoc/Writers/LaTeX.hs+2−1
@@ -40,6 +40,7 @@ import Network.URI ( isURI, unEscapeString )
4040import Data.List ( (\\), isSuffixOf, isInfixOf,
4141 isPrefixOf, intercalate, intersperse )
4242import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
43+import Data.Maybe ( fromMaybe )
4344import Control.Applicative ((<|>))
4445import Control.Monad.State
4546import Text.Pandoc.Pretty
@@ -240,7 +241,7 @@ inCmd cmd contents = char '\\' <> text cmd <> braces contents
240241toSlides :: [Block] -> State WriterState [Block]
241242toSlides bs = do
242243 opts <- gets stOptions
243− let slideLevel = maybe (getSlideLevel bs) id $ writerSlideLevel opts
244+ let slideLevel = fromMaybe (getSlideLevel bs) $ writerSlideLevel opts
244245 let bs' = prepSlides slideLevel bs
245246 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
246247
src/Text/Pandoc/Writers/ODT.hs+2−1
@@ -31,6 +31,7 @@ Conversion of 'Pandoc' documents to ODT.
3131module Text.Pandoc.Writers.ODT ( writeODT ) where
3232import Data.IORef
3333import Data.List ( isPrefixOf )
34+import Data.Maybe ( fromMaybe )
3435import qualified Data.ByteString.Lazy as B
3536import Text.Pandoc.UTF8 ( fromStringLazy )
3637import Codec.Archive.Zip
@@ -127,7 +128,7 @@ transformPic opts entriesRef (Image lab (src,_)) = do
127128 return $ Emph lab
128129 Right (img, _) -> do
129130 let size = imageSize img
130− let (w,h) = maybe (0,0) id $ sizeInPoints `fmap` size
131+ let (w,h) = fromMaybe (0,0) $ sizeInPoints `fmap` size
131132 let tit' = show w ++ "x" ++ show h
132133 entries <- readIORef entriesRef
133134 let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src