git.iko.soy/typeable/pandoc
on master help sign in
HLint: use fromMaybe
3d70059Henry de Valence
src/Text/Pandoc/PDF.hs+2−1
@@ -41,6 +41,7 @@ import System.Directory
41import System.Environment
41import System.Environment
42import Control.Monad (unless)
42import Control.Monad (unless)
43import Data.List (isInfixOf)
43import Data.List (isInfixOf)
44+import Data.Maybe (fromMaybe)
44import qualified Data.ByteString.Base64 as B64
45import qualified Data.ByteString.Base64 as B64
45import qualified Text.Pandoc.UTF8 as UTF8
46import qualified Text.Pandoc.UTF8 as UTF8
46import Text.Pandoc.Definition
47import Text.Pandoc.Definition
@@ -87,7 +88,7 @@ handleImage' baseURL tmpdir (Image ils (src,tit)) = do
87 res <- fetchItem baseURL src
88 res <- fetchItem baseURL src
88 case res of
89 case res of
89 Right (contents, Just mime) -> do
90 Right (contents, Just mime) -> do
90− let ext = maybe (takeExtension src) id $
91+ let ext = fromMaybe (takeExtension src) $
91 extensionFromMimeType mime
92 extensionFromMimeType mime
92 let basename = UTF8.toString $ B64.encode $ UTF8.fromString src
93 let basename = UTF8.toString $ B64.encode $ UTF8.fromString src
93 let fname = tmpdir </> basename <.> ext
94 let fname = tmpdir </> basename <.> ext
src/Text/Pandoc/Readers/DocBook.hs+4−3
@@ -12,6 +12,7 @@ import Data.Char (isSpace)
12import Control.Monad.State
12import Control.Monad.State
13import Control.Applicative ((<$>))
13import Control.Applicative ((<$>))
14import Data.List (intersperse)
14import Data.List (intersperse)
15+import Data.Maybe (fromMaybe)
15
16
16{-
17{-
17
18
@@ -683,7 +684,7 @@ parseBlock (Elem e) =
683 "lowerroman" -> LowerRoman
684 "lowerroman" -> LowerRoman
684 "upperroman" -> UpperRoman
685 "upperroman" -> UpperRoman
685 _ -> Decimal
686 _ -> Decimal
686− let start = maybe 1 id $
687+ let start = fromMaybe 1 $
687 (attrValue "override" <$> filterElement (named "listitem") e)
688 (attrValue "override" <$> filterElement (named "listitem") e)
688 >>= safeRead
689 >>= safeRead
689 orderedListWith (start,listStyle,DefaultDelim)
690 orderedListWith (start,listStyle,DefaultDelim)
@@ -779,7 +780,7 @@ parseBlock (Elem e) =
779 caption <- case filterChild isCaption e of
780 caption <- case filterChild isCaption e of
780 Just t -> getInlines t
781 Just t -> getInlines t
781 Nothing -> return mempty
782 Nothing -> return mempty
782− let e' = maybe e id $ filterChild (named "tgroup") e
783+ let e' = fromMaybe e $ filterChild (named "tgroup") e
783 let isColspec x = named "colspec" x || named "col" x
784 let isColspec x = named "colspec" x || named "col" x
784 let colspecs = case filterChild (named "colgroup") e' of
785 let colspecs = case filterChild (named "colgroup") e' of
785 Just c -> filterChildren isColspec c
786 Just c -> filterChildren isColspec c
@@ -801,7 +802,7 @@ parseBlock (Elem e) =
801 Just "center" -> AlignCenter
802 Just "center" -> AlignCenter
802 _ -> AlignDefault
803 _ -> AlignDefault
803 let toWidth c = case findAttr (unqual "colwidth") c of
804 let toWidth c = case findAttr (unqual "colwidth") c of
804− Just w -> maybe 0 id
805+ Just w -> fromMaybe 0
805 $ safeRead $ '0': filter (\x ->
806 $ safeRead $ '0': filter (\x ->
806 (x >= '0' && x <= '9')
807 (x >= '0' && x <= '9')
807 || x == '.') w
808 || x == '.') w
src/Text/Pandoc/Readers/HTML.hs+2−2
@@ -207,7 +207,7 @@ pHeader = try $ do
207 let bodyTitle = TagOpen tagtype attr ~== TagOpen "h1" [("class","title")]
207 let bodyTitle = TagOpen tagtype attr ~== TagOpen "h1" [("class","title")]
208 let level = read (drop 1 tagtype)
208 let level = read (drop 1 tagtype)
209 contents <- liftM concat $ manyTill inline (pCloses tagtype <|> eof)
209 contents <- liftM concat $ manyTill inline (pCloses tagtype <|> eof)
210− let ident = maybe "" id $ lookup "id" attr
210+ let ident = fromMaybe "" $ lookup "id" attr
211 let classes = maybe [] words $ lookup "class" attr
211 let classes = maybe [] words $ lookup "class" attr
212 let keyvals = [(k,v) | (k,v) <- attr, k /= "class", k /= "id"]
212 let keyvals = [(k,v) | (k,v) <- attr, k /= "class", k /= "id"]
213 return $ if bodyTitle
213 return $ if bodyTitle
@@ -257,7 +257,7 @@ pCol = try $ do
257 skipMany pBlank
257 skipMany pBlank
258 return $ case lookup "width" attribs of
258 return $ case lookup "width" attribs of
259 Just x | not (null x) && last x == '%' ->
259 Just x | not (null x) && last x == '%' ->
260− maybe 0.0 id $ safeRead ('0':'.':init x)
260+ fromMaybe 0.0 $ safeRead ('0':'.':init x)
261 _ -> 0.0
261 _ -> 0.0
262
262
263pColgroup :: TagParser [Double]
263pColgroup :: TagParser [Double]
src/Text/Pandoc/Readers/Markdown.hs+2−2
@@ -1722,7 +1722,7 @@ spanHtml = try $ do
1722 guardEnabled Ext_markdown_in_html_blocks
1722 guardEnabled Ext_markdown_in_html_blocks
1723 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "span" [])
1723 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "span" [])
1724 contents <- mconcat <$> manyTill inline (htmlTag (~== TagClose "span"))
1724 contents <- mconcat <$> manyTill inline (htmlTag (~== TagClose "span"))
1725− let ident = maybe "" id $ lookup "id" attrs
1725+ let ident = fromMaybe "" $ lookup "id" attrs
1726 let classes = maybe [] words $ lookup "class" attrs
1726 let classes = maybe [] words $ lookup "class" attrs
1727 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1727 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1728 return $ B.spanWith (ident, classes, keyvals) <$> contents
1728 return $ B.spanWith (ident, classes, keyvals) <$> contents
@@ -1732,7 +1732,7 @@ divHtml = try $ do
1732 guardEnabled Ext_markdown_in_html_blocks
1732 guardEnabled Ext_markdown_in_html_blocks
1733 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "div" [])
1733 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "div" [])
1734 contents <- mconcat <$> manyTill block (htmlTag (~== TagClose "div"))
1734 contents <- mconcat <$> manyTill block (htmlTag (~== TagClose "div"))
1735− let ident = maybe "" id $ lookup "id" attrs
1735+ let ident = fromMaybe "" $ lookup "id" attrs
1736 let classes = maybe [] words $ lookup "class" attrs
1736 let classes = maybe [] words $ lookup "class" attrs
1737 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1737 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1738 return $ B.divWith (ident, classes, keyvals) <$> contents
1738 return $ B.divWith (ident, classes, keyvals) <$> contents
src/Text/Pandoc/Readers/MediaWiki.hs+4−3
@@ -54,6 +54,7 @@ import Data.Sequence (viewl, ViewL(..), (<|))
54import qualified Data.Foldable as F
54import qualified Data.Foldable as F
55import qualified Data.Map as M
55import qualified Data.Map as M
56import Data.Char (isDigit, isSpace)
56import Data.Char (isDigit, isSpace)
57+import Data.Maybe (fromMaybe)
57
58
58-- | Read mediawiki from an input string and return a Pandoc document.
59-- | Read mediawiki from an input string and return a Pandoc document.
59readMediaWiki :: ReaderOptions -- ^ Reader options
60readMediaWiki :: ReaderOptions -- ^ Reader options
@@ -204,7 +205,7 @@ table = do
204 tableStart
205 tableStart
205 styles <- option [] parseAttrs <* blankline
206 styles <- option [] parseAttrs <* blankline
206 let tableWidth = case lookup "width" styles of
207 let tableWidth = case lookup "width" styles of
207− Just w -> maybe 1.0 id $ parseWidth w
208+ Just w -> fromMaybe 1.0 $ parseWidth w
208 Nothing -> 1.0
209 Nothing -> 1.0
209 caption <- option mempty tableCaption
210 caption <- option mempty tableCaption
210 optional rowsep
211 optional rowsep
@@ -285,7 +286,7 @@ tableCell = try $ do
285 Just "center" -> AlignCenter
286 Just "center" -> AlignCenter
286 _ -> AlignDefault
287 _ -> AlignDefault
287 let width = case lookup "width" attrs of
288 let width = case lookup "width" attrs of
288− Just xs -> maybe 0.0 id $ parseWidth xs
289+ Just xs -> fromMaybe 0.0 $ parseWidth xs
289 Nothing -> 0.0
290 Nothing -> 0.0
290 return ((align, width), bs)
291 return ((align, width), bs)
291
292
@@ -387,7 +388,7 @@ orderedList =
387 spaces
388 spaces
388 items <- many (listItem '#' <|> li)
389 items <- many (listItem '#' <|> li)
389 optional (htmlTag (~== TagClose "ol"))
390 optional (htmlTag (~== TagClose "ol"))
390− let start = maybe 1 id $ safeRead $ fromAttrib "start" tag
391+ let start = fromMaybe 1 $ safeRead $ fromAttrib "start" tag
391 return $ B.orderedListWith (start, DefaultStyle, DefaultDelim) items
392 return $ B.orderedListWith (start, DefaultStyle, DefaultDelim) items
392
393
393definitionList :: MWParser Blocks
394definitionList :: 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
29Conversion of 'Pandoc' documents to docx.
29Conversion of 'Pandoc' documents to docx.
30-}
30-}
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
32+import Data.Maybe (fromMaybe)
32import Data.List ( intercalate, groupBy )
33import Data.List ( intercalate, groupBy )
33import qualified Data.ByteString as B
34import qualified Data.ByteString as B
34import qualified Data.ByteString.Lazy as BL
35import qualified Data.ByteString.Lazy as BL
@@ -130,7 +131,8 @@ writeDocx opts doc@(Pandoc meta _) = do
130 let mkOverrideNode (part', contentType') = mknode "Override"
131 let mkOverrideNode (part', contentType') = mknode "Override"
131 [("PartName",part'),("ContentType",contentType')] ()
132 [("PartName",part'),("ContentType",contentType')] ()
132 let mkImageOverride (_, imgpath, mbMimeType, _, _) =
133 let mkImageOverride (_, imgpath, mbMimeType, _, _) =
134+ mkOverrideNode ("/word/" ++ imgpath,
133− mkOverrideNode ("/word/" ++ imgpath, maybe "application/octet-stream" id mbMimeType)
135+ fromMaybe "application/octet-stream" mbMimeType)
134 let overrides = map mkOverrideNode
136 let overrides = map mkOverrideNode
135 [("/word/webSettings.xml",
137 [("/word/webSettings.xml",
136 "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml")
138 "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml")
@@ -322,7 +324,7 @@ mkNum markers marker numid =
322 NumberMarker _ _ start ->
324 NumberMarker _ _ start ->
323 map (\lvl -> mknode "w:lvlOverride" [("w:ilvl",show (lvl :: Int))]
325 map (\lvl -> mknode "w:lvlOverride" [("w:ilvl",show (lvl :: Int))]
324 $ mknode "w:startOverride" [("w:val",show start)] ()) [0..6]
326 $ 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
326
328
327mkAbstractNum :: (ListMarker,Int) -> IO Element
329mkAbstractNum :: (ListMarker,Int) -> IO Element
328mkAbstractNum (marker,numid) = do
330mkAbstractNum (marker,numid) = do
src/Text/Pandoc/Writers/EPUB.hs+6−6
@@ -176,8 +176,8 @@ addMetadataFromXML e@(Element (QName name _ (Just "dc")) attrs _ _) md
176 , titleFileAs = getAttr "file-as"
176 , titleFileAs = getAttr "file-as"
177 , titleType = getAttr "type"
177 , titleType = getAttr "type"
178 } : epubTitle md }
178 } : epubTitle md }
179− | name == "date" = md{ epubDate = maybe "" id $ normalizeDate'
179+ | name == "date" = md{ epubDate = fromMaybe "" $ normalizeDate'
180− $ strContent e }
180+ $ strContent e }
181 | name == "language" = md{ epubLanguage = strContent e }
181 | name == "language" = md{ epubLanguage = strContent e }
182 | name == "creator" = md{ epubCreator =
182 | name == "creator" = md{ epubCreator =
183 Creator{ creatorText = strContent e
183 Creator{ creatorText = strContent e
@@ -271,7 +271,7 @@ metadataFromMeta opts meta = EPUBMetadata{
271 }
271 }
272 where identifiers = getIdentifier meta
272 where identifiers = getIdentifier meta
273 titles = getTitle meta
273 titles = getTitle meta
274− date = maybe "" id $
274+ date = fromMaybe "" $
275 (metaValueToString <$> lookupMeta "date" meta) >>= normalizeDate'
275 (metaValueToString <$> lookupMeta "date" meta) >>= normalizeDate'
276 language = maybe "" metaValueToString $
276 language = maybe "" metaValueToString $
277 lookupMeta "language" meta `mplus` lookupMeta "lang" meta
277 lookupMeta "language" meta `mplus` lookupMeta "lang" meta
@@ -297,7 +297,7 @@ writeEPUB :: WriterOptions -- ^ Writer options
297 -> Pandoc -- ^ Document to convert
297 -> Pandoc -- ^ Document to convert
298 -> IO B.ByteString
298 -> IO B.ByteString
299writeEPUB opts doc@(Pandoc meta _) = do
299writeEPUB opts doc@(Pandoc meta _) = do
300− let version = maybe EPUB2 id (writerEpubVersion opts)
300+ let version = fromMaybe EPUB2 (writerEpubVersion opts)
301 let epub3 = version == EPUB3
301 let epub3 = version == EPUB3
302 epochtime <- floor `fmap` getPOSIXTime
302 epochtime <- floor `fmap` getPOSIXTime
303 let mkEntry path content = toEntry path epochtime content
303 let mkEntry path content = toEntry path epochtime content
@@ -401,7 +401,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
401 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
401 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
402 $ renderHtml
402 $ renderHtml
403 $ writeHtml opts'{ writerNumberOffset =
403 $ writeHtml opts'{ writerNumberOffset =
404− maybe [] id mbnum }
404+ fromMaybe [] mbnum }
405 $ case bs of
405 $ case bs of
406 (Header _ _ xs : _) ->
406 (Header _ _ xs : _) ->
407 Pandoc (setMeta "title" (fromList xs) nullMeta) bs
407 Pandoc (setMeta "title" (fromList xs) nullMeta) bs
@@ -436,7 +436,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
436 let fontNode ent = unode "item" !
436 let fontNode ent = unode "item" !
437 [("id", takeBaseName $ eRelativePath ent),
437 [("id", takeBaseName $ eRelativePath ent),
438 ("href", eRelativePath ent),
438 ("href", eRelativePath ent),
439− ("media-type", maybe "" id $ getMimeType $ eRelativePath ent)] $ ()
439+ ("media-type", fromMaybe "" $ getMimeType $ eRelativePath ent)] $ ()
440 let plainTitle = case docTitle meta of
440 let plainTitle = case docTitle meta of
441 [] -> case epubTitle metadata of
441 [] -> case epubTitle metadata of
442 [] -> "UNTITLED"
442 [] -> "UNTITLED"
src/Text/Pandoc/Writers/HTML.hs+2−2
@@ -45,7 +45,7 @@ import Numeric ( showHex )
45import Data.Char ( ord, toLower )
45import Data.Char ( ord, toLower )
46import Data.List ( isPrefixOf, intersperse )
46import Data.List ( isPrefixOf, intersperse )
47import Data.String ( fromString )
47import Data.String ( fromString )
48−import Data.Maybe ( catMaybes )
48+import Data.Maybe ( catMaybes, fromMaybe )
49import Control.Monad.State
49import Control.Monad.State
50import Text.Blaze.Html hiding(contents)
50import Text.Blaze.Html hiding(contents)
51import Text.Blaze.Internal(preEscapedString)
51import Text.Blaze.Internal(preEscapedString)
@@ -118,7 +118,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
118 let stringifyHTML = escapeStringForXML . stringify
118 let stringifyHTML = escapeStringForXML . stringify
119 let authsMeta = map stringifyHTML $ docAuthors meta
119 let authsMeta = map stringifyHTML $ docAuthors meta
120 let dateMeta = stringifyHTML $ docDate meta
120 let dateMeta = stringifyHTML $ docDate meta
121− let slideLevel = maybe (getSlideLevel blocks) id $ writerSlideLevel opts
121+ let slideLevel = fromMaybe (getSlideLevel blocks) $ writerSlideLevel opts
122 let sects = hierarchicalize $
122 let sects = hierarchicalize $
123 if writerSlideVariant opts == NoSlides
123 if writerSlideVariant opts == NoSlides
124 then blocks
124 then blocks
src/Text/Pandoc/Writers/LaTeX.hs+2−1
@@ -40,6 +40,7 @@ import Network.URI ( isURI, unEscapeString )
40import Data.List ( (\\), isSuffixOf, isInfixOf,
40import Data.List ( (\\), isSuffixOf, isInfixOf,
41 isPrefixOf, intercalate, intersperse )
41 isPrefixOf, intercalate, intersperse )
42import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
42import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
43+import Data.Maybe ( fromMaybe )
43import Control.Applicative ((<|>))
44import Control.Applicative ((<|>))
44import Control.Monad.State
45import Control.Monad.State
45import Text.Pandoc.Pretty
46import Text.Pandoc.Pretty
@@ -240,7 +241,7 @@ inCmd cmd contents = char '\\' <> text cmd <> braces contents
240toSlides :: [Block] -> State WriterState [Block]
241toSlides :: [Block] -> State WriterState [Block]
241toSlides bs = do
242toSlides bs = do
242 opts <- gets stOptions
243 opts <- gets stOptions
243− let slideLevel = maybe (getSlideLevel bs) id $ writerSlideLevel opts
244+ let slideLevel = fromMaybe (getSlideLevel bs) $ writerSlideLevel opts
244 let bs' = prepSlides slideLevel bs
245 let bs' = prepSlides slideLevel bs
245 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
246 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
246
247
src/Text/Pandoc/Writers/ODT.hs+2−1
@@ -31,6 +31,7 @@ Conversion of 'Pandoc' documents to ODT.
31module Text.Pandoc.Writers.ODT ( writeODT ) where
31module Text.Pandoc.Writers.ODT ( writeODT ) where
32import Data.IORef
32import Data.IORef
33import Data.List ( isPrefixOf )
33import Data.List ( isPrefixOf )
34+import Data.Maybe ( fromMaybe )
34import qualified Data.ByteString.Lazy as B
35import qualified Data.ByteString.Lazy as B
35import Text.Pandoc.UTF8 ( fromStringLazy )
36import Text.Pandoc.UTF8 ( fromStringLazy )
36import Codec.Archive.Zip
37import Codec.Archive.Zip
@@ -127,7 +128,7 @@ transformPic opts entriesRef (Image lab (src,_)) = do
127 return $ Emph lab
128 return $ Emph lab
128 Right (img, _) -> do
129 Right (img, _) -> do
129 let size = imageSize img
130 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
131 let tit' = show w ++ "x" ++ show h
132 let tit' = show w ++ "x" ++ show h
132 entries <- readIORef entriesRef
133 entries <- readIORef entriesRef
133 let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src
134 let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src