diff options
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 66 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 2 |
2 files changed, 43 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 0bafa0d19..cae7a23b7 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -2078,33 +2078,40 @@ addImageCaption = walkM go case attr' of ("", _, _) -> return () (ident, _, _) -> do - st <- getState - let chapnum = - case (sHasChapters st, sLastHeaderNum st) of - (True, DottedNum (n:_)) -> Just n - _ -> Nothing - let num = case sLastFigureNum st of - DottedNum [m,n] -> - case chapnum of - Just m' | m' == m -> DottedNum [m, n+1] - | otherwise -> DottedNum [m', 1] - Nothing -> DottedNum [1] - -- shouldn't happen - DottedNum [n] -> - case chapnum of - Just m -> DottedNum [m, 1] - Nothing -> DottedNum [n + 1] - _ -> - case chapnum of - Just n -> DottedNum [n, 1] - Nothing -> DottedNum [1] - setState $ + num <- getNextNumber sLastFigureNum + updateState $ \st -> st{ sLastFigureNum = num , sLabels = M.insert ident [Str (renderDottedNum num)] (sLabels st) } return $ Image attr' alt' (src, tit') go x = return x +getNextNumber :: Monad m + => (LaTeXState -> DottedNum) -> LP m DottedNum +getNextNumber getCurrentNum = do + st <- getState + let chapnum = + case (sHasChapters st, sLastHeaderNum st) of + (True, DottedNum (n:_)) -> Just n + _ -> Nothing + return $ + case getCurrentNum st of + DottedNum [m,n] -> + case chapnum of + Just m' | m' == m -> DottedNum [m, n+1] + | otherwise -> DottedNum [m', 1] + Nothing -> DottedNum [1] + -- shouldn't happen + DottedNum [n] -> + case chapnum of + Just m -> DottedNum [m, 1] + Nothing -> DottedNum [n + 1] + _ -> + case chapnum of + Just n -> DottedNum [n, 1] + Nothing -> DottedNum [1] + + coloredBlock :: PandocMonad m => Text -> LP m Blocks coloredBlock stylename = try $ do skipopts @@ -2379,10 +2386,19 @@ simpTable envname hasWidthParameter = try $ do addTableCaption :: PandocMonad m => Blocks -> LP m Blocks addTableCaption = walkM go where go (Table c als ws hs rs) = do - (mbcapt, _) <- sCaption <$> getState - return $ case mbcapt of - Just ils -> Table (toList ils) als ws hs rs - Nothing -> Table c als ws hs rs + (mbcapt, mblabel) <- sCaption <$> getState + capt <- case (mbcapt, mblabel) of + (Just ils, Nothing) -> return $ toList ils + (Just ils, Just lab) -> do + num <- getNextNumber sLastTableNum + updateState $ \st -> + st{ sLastTableNum = num + , sLabels = M.insert lab + [Str (renderDottedNum num)] + (sLabels st) } + return $ toList ils -- add number?? + (Nothing, _) -> return c + return $ Table capt als ws hs rs go x = return x diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index a6836c3c1..4aa9976c9 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -120,6 +120,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions , sInTableCell :: Bool , sLastHeaderNum :: DottedNum , sLastFigureNum :: DottedNum + , sLastTableNum :: DottedNum , sLabels :: M.Map Text [Inline] , sHasChapters :: Bool , sToggles :: M.Map Text Bool @@ -141,6 +142,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def , sInTableCell = False , sLastHeaderNum = DottedNum [] , sLastFigureNum = DottedNum [] + , sLastTableNum = DottedNum [] , sLabels = M.empty , sHasChapters = False , sToggles = M.empty |