aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-10-21 11:44:12 -0700
committerJohn MacFarlane <[email protected]>2022-10-21 11:44:12 -0700
commit400d4e1387d9bc26a3c2a58e2a6c34cde80d2018 (patch)
tree220e2120b153541fa2cd5d750a86744d56f7e1fd
parente243cd696f97410ba7d25ffd2800936c16d160bf (diff)
LaTeX reader: parse short table caption.
See jgm/pandoc-types#103. This is not too useful yet, because writers don't do anything with the short caption.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs5
-rw-r--r--src/Text/Pandoc/Readers/LaTeX/Parsing.hs7
-rw-r--r--src/Text/Pandoc/Readers/LaTeX/Table.hs10
-rw-r--r--test/command/short-caption.md42
4 files changed, 54 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index b12e65eaf..a84186aa9 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -1171,7 +1171,7 @@ addImageCaption = walkM go
st <- getState
case sCaption st of
Nothing -> return p
- Just figureCaption -> do
+ Just (Caption _mbshort bs) -> do
let mblabel = sLastLabel st
let attr' = case mblabel of
Just lab -> (lab, cls, kvs)
@@ -1186,7 +1186,8 @@ addImageCaption = walkM go
[Str (renderDottedNum num)] (sLabels st) }
return $ SimpleFigure attr'
- (maybe id removeLabel mblabel (B.toList figureCaption))
+ (maybe id removeLabel mblabel
+ (blocksToInlines bs))
(src, tit)
go x = return x
diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
index 90dcabd75..c4102fbbb 100644
--- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
+++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
@@ -157,7 +157,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
, sLogMessages :: [LogMessage]
, sIdentifiers :: Set.Set Text
, sVerbatimMode :: Bool
- , sCaption :: Maybe Inlines
+ , sCaption :: Maybe Caption
, sInListItem :: Bool
, sInTableCell :: Bool
, sLastHeaderNum :: DottedNum
@@ -1072,10 +1072,11 @@ label = do
setCaption :: PandocMonad m => LP m Inlines -> LP m ()
setCaption inline = try $ do
- skipopts
+ mbshort <- Just . toList <$> bracketed inline <|> pure Nothing
ils <- tokWith inline
optional $ try $ spaces *> label
- updateState $ \st -> st{ sCaption = Just ils }
+ updateState $ \st -> st{ sCaption = Just $
+ Caption mbshort [Plain $ toList ils] }
resetCaption :: PandocMonad m => LP m ()
resetCaption = updateState $ \st -> st{ sCaption = Nothing
diff --git a/src/Text/Pandoc/Readers/LaTeX/Table.hs b/src/Text/Pandoc/Readers/LaTeX/Table.hs
index 98feaa865..718ff2dbe 100644
--- a/src/Text/Pandoc/Readers/LaTeX/Table.hs
+++ b/src/Text/Pandoc/Readers/LaTeX/Table.hs
@@ -355,18 +355,18 @@ addTableCaption :: PandocMonad m => Blocks -> LP m Blocks
addTableCaption = walkM go
where go (Table attr c spec th tb tf) = do
st <- getState
+ let capt = fromMaybe c $ sCaption st
let mblabel = sLastLabel st
- capt <- case (sCaption st, mblabel) of
- (Just ils, Nothing) -> return $ caption Nothing (plain ils)
- (Just ils, Just lab) -> do
+ case mblabel of
+ Nothing -> return ()
+ Just lab -> do
num <- getNextNumber sLastTableNum
setState
st{ sLastTableNum = num
, sLabels = M.insert lab
[Str (renderDottedNum num)]
(sLabels st) }
- return $ caption Nothing (plain ils) -- add number??
- (Nothing, _) -> return c
+ -- add num to caption?
let attr' = case (attr, mblabel) of
((_,classes,kvs), Just ident) ->
(ident,classes,kvs)
diff --git a/test/command/short-caption.md b/test/command/short-caption.md
new file mode 100644
index 000000000..0fb71290f
--- /dev/null
+++ b/test/command/short-caption.md
@@ -0,0 +1,42 @@
+```
+% pandoc -f latex -t native
+\begin{table}
+\caption[short caption]{long caption}
+\begin{tabular}{ll}
+hi & hi \\
+\end{tabular}
+\end{table}
+^D
+[ Table
+ ( "" , [] , [] )
+ (Caption
+ (Just [ Str "short" , Space , Str "caption" ])
+ [ Plain [ Str "long" , Space , Str "caption" ] ])
+ [ ( AlignLeft , ColWidthDefault )
+ , ( AlignLeft , ColWidthDefault )
+ ]
+ (TableHead ( "" , [] , [] ) [])
+ [ TableBody
+ ( "" , [] , [] )
+ (RowHeadColumns 0)
+ []
+ [ Row
+ ( "" , [] , [] )
+ [ Cell
+ ( "" , [] , [] )
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "hi" ] ]
+ , Cell
+ ( "" , [] , [] )
+ AlignDefault
+ (RowSpan 1)
+ (ColSpan 1)
+ [ Plain [ Str "hi" ] ]
+ ]
+ ]
+ ]
+ (TableFoot ( "" , [] , [] ) [])
+]
+```