@@ -54,8 +54,7 @@ import Data.List (intercalate, isPrefixOf)
5454import Data.List.Split (wordsBy)
5555import qualified Data.Map as M
5656import Data.Maybe (fromMaybe, isJust, isNothing)
57−import Data.Monoid (First (..))
58−import Data.Monoid ((<>))
57+import Data.Monoid (First (..), (<>))
5958import qualified Data.Set as Set
6059import Data.Text (Text)
6160import qualified Data.Text as T
@@ -89,7 +88,7 @@ readHtml opts inp = do
8988 parseTagsOptions parseOptions{ optTagPosition = True }
9089 (crFilter inp)
9190 parseDoc = do
92− blocks <- (fixPlains False) . mconcat <$> manyTill block eof
91+ blocks <- fixPlains False . mconcat <$> manyTill block eof
9392 meta <- stateMeta . parserState <$> getState
9493 bs' <- replaceNotes (B.toList blocks)
9594 reportLogMessages
@@ -223,10 +222,10 @@ eSwitch constructor parser = try $ do
223222eCase :: PandocMonad m => TagParser m (Maybe Inlines)
224223eCase = do
225224 skipMany pBlank
226− TagOpen _ attr' <- lookAhead $ pSatisfy $ (matchTagOpen "case" [])
225+ TagOpen _ attr' <- lookAhead $ pSatisfy (matchTagOpen "case" [])
227226 let attr = toStringAttr attr'
228− case (flip lookup namespaces) =<< lookup "required-namespace" attr of
229− Just p -> Just <$> (pInTags "case" (skipMany pBlank *> p <* skipMany pBlank))
227+ case flip lookup namespaces =<< lookup "required-namespace" attr of
228+ Just p -> Just <$> pInTags "case" (skipMany pBlank *> p <* skipMany pBlank)
230229 Nothing -> Nothing <$ manyTill pAnyTag (pSatisfy (matchTagClose "case"))
231230
232231eFootnote :: PandocMonad m => TagParser m ()
@@ -235,20 +234,20 @@ eFootnote = try $ do
235234 guardEnabled Ext_epub_html_exts
236235 (TagOpen tag attr') <- lookAhead pAnyTag
237236 let attr = toStringAttr attr'
238− guard (maybe False (flip elem notes) (lookup "type" attr))
237+ guard $ maybe False (`elem` notes) (lookup "type" attr)
239238 let ident = fromMaybe "" (lookup "id" attr)
240239 content <- pInTags tag block
241240 addNote ident content
242241
243242addNote :: PandocMonad m => String -> Blocks -> TagParser m ()
244−addNote uid cont = updateState (\s -> s {noteTable = (uid, cont) : (noteTable s)})
243+addNote uid cont = updateState (\s -> s {noteTable = (uid, cont) : noteTable s})
245244
246245eNoteref :: PandocMonad m => TagParser m Inlines
247246eNoteref = try $ do
248247 guardEnabled Ext_epub_html_exts
249− TagOpen tag attr' <- lookAhead $ pAnyTag
248+ TagOpen tag attr' <- lookAhead pAnyTag
250249 let attr = toStringAttr attr'
251− guard (maybe False (== "noteref") (lookup "type" attr))
250+ guard $ lookup "type" attr == Just "noteref"
252251 let ident = maybe "" (dropWhile (== '#')) (lookup "href" attr)
253252 guard (not (null ident))
254253 pInTags tag block
@@ -258,8 +257,8 @@ eNoteref = try $ do
258257eTOC :: PandocMonad m => TagParser m ()
259258eTOC = try $ do
260259 guardEnabled Ext_epub_html_exts
261− (TagOpen tag attr) <- lookAhead $ pAnyTag
262− guard (maybe False (== "toc") (lookup "type" attr))
260+ (TagOpen tag attr) <- lookAhead pAnyTag
261+ guard $ lookup "type" attr == Just "toc"
263262 void (pInTags tag block)
264263
265264pList :: PandocMonad m => TagParser m Blocks
@@ -285,7 +284,7 @@ pListItem nonItem = do
285284 (Plain ils:xs) -> B.fromList (Plain
286285 [Span (ident, [], []) ils] : xs)
287286 _ -> B.divWith (ident, [], []) bs
288− (maybe id addId (lookup "id" attr)) <$>
287+ maybe id addId (lookup "id" attr) <$>
289288 pInTags "li" block <* skipMany nonItem
290289
291290parseListStyleType :: String -> ListNumberStyle
@@ -356,14 +355,14 @@ fixPlains :: Bool -> Blocks -> Blocks
356355fixPlains inList bs = if any isParaish bs'
357356 then B.fromList $ map plainToPara bs'
358357 else bs
359− where isParaish (Para _) = True
360− isParaish (CodeBlock _ _) = True
361− isParaish (Header _ _ _) = True
362− isParaish (BlockQuote _) = True
363− isParaish (BulletList _) = not inList
364− isParaish (OrderedList _ _) = not inList
365− isParaish (DefinitionList _) = not inList
366− isParaish _ = False
358+ where isParaish Para{} = True
359+ isParaish CodeBlock{} = True
360+ isParaish Header{} = True
361+ isParaish BlockQuote{} = True
362+ isParaish BulletList{} = not inList
363+ isParaish OrderedList{} = not inList
364+ isParaish DefinitionList{} = not inList
365+ isParaish _ = False
367366 plainToPara (Plain xs) = Para xs
368367 plainToPara x = x
369368 bs' = B.toList bs
@@ -427,10 +426,10 @@ eSection = try $ do
427426 setInChapter (pInTags tag block)
428427
429428headerLevel :: PandocMonad m => Text -> TagParser m Int
430−headerLevel tagtype = do
429+headerLevel tagtype =
431430 case safeRead (T.unpack (T.drop 1 tagtype)) of
432431 Just level ->
433− (try $ do
432+ try (do
434433 guardEnabled Ext_epub_html_exts
435434 asks inChapter >>= guard
436435 return (level - 1))
@@ -481,12 +480,12 @@ pTable = try $ do
481480 pTBody = pOptInTag "tbody" $ many1 pTr
482481 head'' <- pOptInTag "thead" pTh
483482 head' <- map snd <$>
484− (pOptInTag "tbody" $
485− if null head'' then pTh else return head'')
483+ pOptInTag "tbody"
484+ (if null head'' then pTh else return head'')
486485 rowsLs <- many pTBody
487486 rows' <- pOptInTag "tfoot" $ many pTr
488487 TagClose _ <- pSatisfy (matchTagClose "table")
489− let rows'' = (concat rowsLs) <> rows'
488+ let rows'' = concat rowsLs <> rows'
490489 let rows''' = map (map snd) rows''
491490 -- let rows''' = map (map snd) rows''
492491 -- fail on empty table
@@ -691,7 +690,7 @@ pSubscript :: PandocMonad m => TagParser m Inlines
691690pSubscript = pInlinesInTags "sub" B.subscript
692691
693692pStrikeout :: PandocMonad m => TagParser m Inlines
694−pStrikeout = do
693+pStrikeout =
695694 pInlinesInTags "s" B.strikeout <|>
696695 pInlinesInTags "strike" B.strikeout <|>
697696 pInlinesInTags "del" B.strikeout <|>
@@ -719,7 +718,7 @@ pLink = try $ do
719718 tag <- pSatisfy $ tagOpenLit "a" (const True)
720719 let title = T.unpack $ fromAttrib "title" tag
721720 -- take id from id attribute if present, otherwise name
722− let uid = maybe (T.unpack $ fromAttrib "name" tag) id $
721+ let uid = fromMaybe (T.unpack $ fromAttrib "name" tag) $
723722 maybeFromAttrib "id" tag
724723 let cls = words $ T.unpack $ fromAttrib "class" tag
725724 lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
@@ -750,7 +749,7 @@ pImage = do
750749 let getAtt k = case fromAttrib k tag of
751750 "" -> []
752751 v -> [(T.unpack k, T.unpack v)]
753− let kvs = concat $ map getAtt ["width", "height", "sizes", "srcset"]
752+ let kvs = concatMap getAtt ["width", "height", "sizes", "srcset"]
754753 return $ B.imageWith (uid, cls, kvs) (escapeURI url) title (B.text alt)
755754
756755pCode :: PandocMonad m => TagParser m Inlines
@@ -846,7 +845,7 @@ pCloses :: PandocMonad m => Text -> TagParser m ()
846845pCloses tagtype = try $ do
847846 t <- lookAhead $ pSatisfy $ \tag -> isTagClose tag || isTagOpen tag
848847 case t of
849− (TagClose t') | t' == tagtype -> pAnyTag >> return ()
848+ (TagClose t') | t' == tagtype -> void pAnyTag
850849 (TagOpen t' _) | t' `closes` tagtype -> return ()
851850 (TagClose "ul") | tagtype == "li" -> return ()
852851 (TagClose "ol") | tagtype == "li" -> return ()
@@ -1197,7 +1196,7 @@ htmlTag f = try $ do
11971196mkAttr :: [(String, String)] -> Attr
11981197mkAttr attr = (attribsId, attribsClasses, attribsKV)
11991198 where attribsId = fromMaybe "" $ lookup "id" attr
1200− attribsClasses = (words $ fromMaybe "" $ lookup "class" attr) <> epubTypes
1199+ attribsClasses = words (fromMaybe "" $ lookup "class" attr) <> epubTypes
12011200 attribsKV = filter (\(k,_) -> k /= "class" && k /= "id") attr
12021201 epubTypes = words $ fromMaybe "" $ lookup "epub:type" attr
12031202