@@ -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)]