git.iko.soy/typeable/pandoc
on master help sign in
LaTeX Reader: parse figure label into Image id (#4704)

closes #4700

commit7e477db95cfb02d155b3a0ede86094143b5ab7ee authorMauro Bieg <mb21@users.noreply.github.com> dateWed 13 Jun 2018, 19:41 (8 years ago) parent2c1a309
3 files changed+22−16
src/Text/Pandoc/Readers/LaTeX.hs+20−14 test/command/2118.md+1−1 test/command/refs.md+1−1
src/Text/Pandoc/Readers/LaTeX.hs+20−14
@@ -159,7 +159,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
159159 , sLogMessages :: [LogMessage]
160160 , sIdentifiers :: Set.Set String
161161 , sVerbatimMode :: Bool
162− , sCaption :: Maybe Inlines
162+ , sCaption :: (Maybe Inlines, Maybe String)
163163 , sInListItem :: Bool
164164 , sInTableCell :: Bool
165165 , sLastHeaderNum :: HeaderNum
@@ -179,7 +179,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
179179 , sLogMessages = []
180180 , sIdentifiers = Set.empty
181181 , sVerbatimMode = False
182− , sCaption = Nothing
182+ , sCaption = (Nothing, Nothing)
183183 , sInListItem = False
184184 , sInTableCell = False
185185 , sLastHeaderNum = HeaderNum []
@@ -2100,11 +2100,13 @@ setCaption = do
21002100 ils <- tok
21012101 mblabel <- option Nothing $
21022102 try $ spaces >> controlSeq "label" >> (Just <$> tok)
2103− let ils' = case mblabel of
2104− Just lab -> ils <> spanWith
2105− ("",[],[("label", stringify lab)]) mempty
2106− Nothing -> ils
2107− updateState $ \st -> st{ sCaption = Just ils' }
2103+ let capt = case mblabel of
2104+ Just lab -> let slab = stringify lab
2105+ ils' = ils <> spanWith
2106+ ("",[],[("label", slab)]) mempty
2107+ in (Just ils', Just slab)
2108+ Nothing -> (Just ils, Nothing)
2109+ updateState $ \st -> st{ sCaption = capt }
21082110 return mempty
21092111
21102112looseItem :: PandocMonad m => LP m Blocks
@@ -2115,7 +2117,7 @@ looseItem = do
21152117 return mempty
21162118
21172119resetCaption :: PandocMonad m => LP m ()
2118−resetCaption = updateState $ \st -> st{ sCaption = Nothing }
2120+resetCaption = updateState $ \st -> st{ sCaption = (Nothing, Nothing) }
21192121
21202122section :: PandocMonad m => Bool -> Attr -> Int -> LP m Blocks
21212123section starred (ident, classes, kvs) lvl = do
@@ -2405,12 +2407,16 @@ figure = try $ do
24052407
24062408addImageCaption :: PandocMonad m => Blocks -> LP m Blocks
24072409addImageCaption = walkM go
2408− where go (Image attr alt (src,tit))
2410+ where go (Image attr@(_, cls, kvs) alt (src,tit))
24092411 | not ("fig:" `isPrefixOf` tit) = do
2410− mbcapt <- sCaption <$> getState
2411− return $ case mbcapt of
2412− Just ils -> Image attr (toList ils) (src, "fig:" ++ tit)
2413− Nothing -> Image attr alt (src,tit)
2412+ (mbcapt, mblab) <- sCaption <$> getState
2413+ let (alt', tit') = case mbcapt of
2414+ Just ils -> (toList ils, "fig:" ++ tit)
2415+ Nothing -> (alt, tit)
2416+ attr' = case mblab of
2417+ Just lab -> (lab, cls, kvs)
2418+ Nothing -> attr
2419+ return $ Image attr' alt' (src, tit')
24142420 go x = return x
24152421
24162422coloredBlock :: PandocMonad m => String -> LP m Blocks
@@ -2682,7 +2688,7 @@ simpTable envname hasWidthParameter = try $ do
26822688addTableCaption :: PandocMonad m => Blocks -> LP m Blocks
26832689addTableCaption = walkM go
26842690 where go (Table c als ws hs rs) = do
2685− mbcapt <- sCaption <$> getState
2691+ (mbcapt, _) <- sCaption <$> getState
26862692 return $ case mbcapt of
26872693 Just ils -> Table (toList ils) als ws hs rs
26882694 Nothing -> Table c als ws hs rs
test/command/2118.md+1−1
@@ -7,5 +7,5 @@
77 \label{fig:setminus}
88\end{figure}
99^D
10−[Para [Image ("",[],[("width","80%")]) [Str "Set",Space,Str "subtraction",Span ("",[],[("label","fig:setminus")]) []] ("setminus.png","fig:")]]
10+[Para [Image ("fig:setminus",[],[("width","80%")]) [Str "Set",Space,Str "subtraction",Span ("",[],[("label","fig:setminus")]) []] ("setminus.png","fig:")]]
1111```
test/command/refs.md+1−1
@@ -42,7 +42,7 @@ Accuracy~\eqref{eq:Accuracy} is the proportion, measuring true results among all
4242
4343Figure \ref{fig:Logo} illustrated the SVG logo
4444^D
45−[Para [Image ("",[],[]) [Str "Logo",Span ("",[],[("label","fig:Logo")]) []] ("command/SVG_logo.svg","fig:")]
45+[Para [Image ("fig:Logo",[],[]) [Str "Logo",Span ("",[],[("label","fig:Logo")]) []] ("command/SVG_logo.svg","fig:")]
4646,Para [Str "Figure",Space,Link ("",[],[("reference-type","ref"),("reference","fig:Logo")]) [Str "[fig:Logo]"] ("#fig:Logo",""),Space,Str "illustrated",Space,Str "the",Space,Str "SVG",Space,Str "logo"]]
4747```
4848