aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJoseph C. Sible <josephcsible@users.noreply.github.com>2020-02-03 23:31:05 -0500
committerGitHub <noreply@github.com>2020-02-03 20:31:05 -0800
commit1ea5b1802072fe2724977fa859c0e5b48f15917d (patch)
treef675b874a02776c8b5809a5dfa73fa2ca967c1ef /src/Text/Pandoc/Writers
parentd9b1776336db06306562c4b5648716196261b548 (diff)
downloadpandoc-1ea5b1802072fe2724977fa859c0e5b48f15917d.tar.gz
Swap suboptimal uses of maybe and fromMaybe (#6111)
Anywhere "maybe" is used with "id" as its second argument, using "fromMaybe" instead will simplify the code. Conversely, anywhere "fromMaybe" is used with the result of "fmap" or "<$>" as its second argument, using "maybe" instead will simplify the code.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs8
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs6
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs6
3 files changed, 10 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index b3cf79ba2..7934e27c3 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -356,7 +356,7 @@ metadataFromMeta opts meta = EPUBMetadata{
(writerVariables opts))
`mplus` (metaValueToString <$> lookupMeta "cover-image" meta)
mCss = lookupMeta "css" meta <|> lookupMeta "stylesheet" meta
- stylesheets = fromMaybe [] (metaValueToPaths <$> mCss) ++
+ stylesheets = maybe [] metaValueToPaths mCss ++
case lookupContext "css" (writerVariables opts) of
Just xs -> map TS.unpack xs
Nothing ->
@@ -659,8 +659,8 @@ pandocToEPUB version opts doc = do
("media-type", maybe "" TS.unpack $
getMimeType $ eRelativePath ent)] $ ()
- let tocTitle = fromMaybe plainTitle $
- metaValueToString <$> lookupMeta "toc-title" meta
+ let tocTitle = maybe plainTitle
+ metaValueToString $ lookupMeta "toc-title" meta
uuid <- case epubIdentifier metadata of
(x:_) -> return $ identifierText x -- use first identifier as UUID
[] -> throwError $ PandocShouldNeverHappenError "epubIdentifier is null" -- shouldn't happen
@@ -1400,7 +1400,7 @@ relatorMap =
]
docTitle' :: Meta -> [Inline]
-docTitle' meta = fromMaybe [] $ go <$> lookupMeta "title" meta
+docTitle' meta = maybe [] go $ lookupMeta "title" meta
where go (MetaString s) = [Str s]
go (MetaInlines xs) = xs
go (MetaBlocks [Para xs]) = xs
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index e6d7579d3..10ab3dfe1 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -194,9 +194,9 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
(blockListToMarkdown opts)
(inlineListToMarkdown opts)
meta
- let title' = maybe empty id $ getField "title" metadata
- let authors' = maybe [] id $ getField "author" metadata
- let date' = maybe empty id $ getField "date" metadata
+ let title' = fromMaybe empty $ getField "title" metadata
+ let authors' = fromMaybe [] $ getField "author" metadata
+ let date' = fromMaybe empty $ getField "date" metadata
let titleblock = case writerTemplate opts of
Just _ | isPlain ->
plainTitleBlock title' authors' date'
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index b3f4fa1a0..19eb87f89 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -26,7 +26,7 @@ import Control.Monad.State.Strict
import Data.Char (isLower, isUpper, ord)
import Data.List (intercalate, intersperse)
import qualified Data.Map as Map
-import Data.Maybe (catMaybes, fromMaybe)
+import Data.Maybe (catMaybes)
import Data.Text (Text)
import qualified Data.Text as T
import Network.URI (escapeURIString, isAllowedInURI)
@@ -507,8 +507,8 @@ toMacro sty toktype =
tokSty = Map.lookup toktype (tokenStyles sty)
tokCol = (tokSty >>= tokenColor) `mplus` defaultColor sty
-- tokBg = (tokSty >>= tokenBackground) `mplus` backgroundColor sty
- tokBold = fromMaybe False (tokenBold <$> tokSty)
- tokItalic = fromMaybe False (tokenItalic <$> tokSty)
+ tokBold = maybe False tokenBold tokSty
+ tokItalic = maybe False tokenItalic tokSty
-- tokUnderline = fromMaybe False (tokSty >>= tokUnderline)
-- lnColor = lineNumberColor sty
-- lnBkgColor = lineNumberBackgroundColor sty