git.iko.soy/typeable/pandoc
on master help sign in
A bit more cleanup (#6141)

* Remove unnecessary fmaps and only do toMilliseconds once * Share the input tuple intead of making a new one * Lift return out of if * Simplify case statements * Lift DottedNum out of the case statements * Use st instead of mbs * Use setState instead of updateState now that we have the whole state around

commit652ed0b82cd7095f418859356d7e5f8ada65eb49 authorJoseph C. Sible <josephcsible@users.noreply.github.com> dateFri 14 Feb 2020, 01:52 (7 years ago) parent29c2670
5 files changed+32−34
src/Text/Pandoc/Filter.hs+3−3 src/Text/Pandoc/Image.hs+3−3 src/Text/Pandoc/Readers/HTML.hs+4−5 src/Text/Pandoc/Readers/LaTeX.hs+21−22 src/Text/Pandoc/Writers/HTML.hs+1−1
src/Text/Pandoc/Filter.hs+3−3
@@ -75,10 +75,10 @@ applyFilters ropts filters args d = do
7575 withMessages f action = do
7676 verbosity <- getVerbosity
7777 when (verbosity == INFO) $ report $ RunningFilter f
78− starttime <- toMilliseconds <$> liftIO getCPUTime
78+ starttime <- liftIO getCPUTime
7979 res <- action
80− endtime <- toMilliseconds <$> liftIO getCPUTime
81− when (verbosity == INFO) $ report $ FilterCompleted f (endtime - starttime)
80+ endtime <- liftIO getCPUTime
81+ when (verbosity == INFO) $ report $ FilterCompleted f $ toMilliseconds $ endtime - starttime
8282 return res
8383 toMilliseconds picoseconds = picoseconds `div` 1000000000
8484
src/Text/Pandoc/Image.hs+3−3
@@ -33,8 +33,8 @@ svgToPng opts bs = do
3333 (do (exit, out) <- pipeProcess Nothing "rsvg-convert"
3434 ["-f","png","-a","--dpi-x",dpi,"--dpi-y",dpi]
3535 bs
36− if exit == ExitSuccess
37− then return $ Right out
38− else return $ Left "conversion from SVG failed")
36+ return $ if exit == ExitSuccess
37+ then Right out
38+ else Left "conversion from SVG failed")
3939 (\(e :: E.SomeException) -> return $ Left $
4040 "check that rsvg-convert is in path.\n" <> tshow e)
src/Text/Pandoc/Readers/HTML.hs+4−5
@@ -839,11 +839,10 @@ toStringAttr = map go
839839 where
840840 go (x,y) =
841841 case T.stripPrefix "data-" x of
842− Nothing -> (x,y)
843− Just x' -> if x' `Set.member` (html5Attributes <>
844− html4Attributes <> rdfaAttributes)
845− then (x,y)
846− else (x',y)
842+ Just x' | x' `Set.notMember` (html5Attributes <>
843+ html4Attributes <> rdfaAttributes)
844+ -> (x',y)
845+ _ -> (x,y)
847846
848847pScriptMath :: PandocMonad m => TagParser m Inlines
849848pScriptMath = try $ do
src/Text/Pandoc/Readers/LaTeX.hs+21−22
@@ -1405,8 +1405,8 @@ treatAsInline = Set.fromList
14051405label :: PandocMonad m => LP m ()
14061406label = do
14071407 controlSeq "label"
1408− t <- untokenize <$> braced
1409− updateState $ \st -> st{ sLastLabel = Just t }
1408+ t <- braced
1409+ updateState $ \st -> st{ sLastLabel = Just $ untokenize t }
14101410
14111411dolabel :: PandocMonad m => LP m Inlines
14121412dolabel = do
@@ -2070,19 +2070,18 @@ addImageCaption :: PandocMonad m => Blocks -> LP m Blocks
20702070addImageCaption = walkM go
20712071 where go (Image attr@(_, cls, kvs) alt (src,tit))
20722072 | not ("fig:" `T.isPrefixOf` tit) = do
2073− mbcapt <- sCaption <$> getState
2074− mblabel <- sLastLabel <$> getState
2075− let (alt', tit') = case mbcapt of
2073+ st <- getState
2074+ let (alt', tit') = case sCaption st of
20762075 Just ils -> (toList ils, "fig:" <> tit)
20772076 Nothing -> (alt, tit)
2078− attr' = case mblabel of
2077+ attr' = case sLastLabel st of
20792078 Just lab -> (lab, cls, kvs)
20802079 Nothing -> attr
20812080 case attr' of
20822081 ("", _, _) -> return ()
20832082 (ident, _, _) -> do
20842083 num <- getNextNumber sLastFigureNum
2085− updateState $ \st ->
2084+ setState
20862085 st{ sLastFigureNum = num
20872086 , sLabels = M.insert ident
20882087 [Str (renderDottedNum num)] (sLabels st) }
@@ -2094,25 +2093,25 @@ getNextNumber :: Monad m
20942093getNextNumber getCurrentNum = do
20952094 st <- getState
20962095 let chapnum =
2097− case (sHasChapters st, sLastHeaderNum st) of
2098− (True, DottedNum (n:_)) -> Just n
2099− _ -> Nothing
2100− return $
2096+ case sLastHeaderNum st of
2097+ DottedNum (n:_) | sHasChapters st -> Just n
2098+ _ -> Nothing
2099+ return . DottedNum $
21012100 case getCurrentNum st of
21022101 DottedNum [m,n] ->
21032102 case chapnum of
2104− Just m' | m' == m -> DottedNum [m, n+1]
2105− | otherwise -> DottedNum [m', 1]
2106− Nothing -> DottedNum [1]
2103+ Just m' | m' == m -> [m, n+1]
2104+ | otherwise -> [m', 1]
2105+ Nothing -> [1]
21072106 -- shouldn't happen
21082107 DottedNum [n] ->
21092108 case chapnum of
2110− Just m -> DottedNum [m, 1]
2111− Nothing -> DottedNum [n + 1]
2109+ Just m -> [m, 1]
2110+ Nothing -> [n + 1]
21122111 _ ->
21132112 case chapnum of
2114− Just n -> DottedNum [n, 1]
2115− Nothing -> DottedNum [1]
2113+ Just n -> [n, 1]
2114+ Nothing -> [1]
21162115
21172116
21182117coloredBlock :: PandocMonad m => Text -> LP m Blocks
@@ -2395,13 +2394,13 @@ simpTable envname hasWidthParameter = try $ do
23952394addTableCaption :: PandocMonad m => Blocks -> LP m Blocks
23962395addTableCaption = walkM go
23972396 where go (Table c als ws hs rs) = do
2398− mbcapt <- sCaption <$> getState
2399− mblabel <- sLastLabel <$> getState
2400− capt <- case (mbcapt, mblabel) of
2397+ st <- getState
2398+ let mblabel = sLastLabel st
2399+ capt <- case (sCaption st, mblabel) of
24012400 (Just ils, Nothing) -> return $ toList ils
24022401 (Just ils, Just lab) -> do
24032402 num <- getNextNumber sLastTableNum
2404− updateState $ \st ->
2403+ setState
24052404 st{ sLastTableNum = num
24062405 , sLabels = M.insert lab
24072406 [Str (renderDottedNum num)]
src/Text/Pandoc/Writers/HTML.hs+1−1
@@ -611,7 +611,7 @@ adjustNumbers opts doc =
611611 (writerNumberOffset opts ++ repeat 0)
612612 (map (fromMaybe 0 . safeRead) $
613613 T.split (=='.') num))
614− fixnum (k,v) = (k,v)
614+ fixnum x = x
615615 showSecNum = T.intercalate "." . map tshow
616616
617617-- | Convert Pandoc block element to HTML.