git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Handle block structure inside table cells.

minipage is no longer required. Closes #3709.

commit1e7ba5ccd7febff6cd43736109cf62b8ff54eecc authorJohn MacFarlane <jgm@berkeley.edu> dateThu 1 Jun 2017, 11:16 (9 years ago) parenta61dce8
1 file changed+18−18
src/Text/Pandoc/Readers/LaTeX.hs+18−18
src/Text/Pandoc/Readers/LaTeX.hs+18−18
@@ -276,8 +276,6 @@ block = (mempty <$ comment)
276276 <|> blockCommand
277277 <|> paragraph
278278 <|> grouped block
279− <|> (mempty <$ char '&') -- loose & in table environment
280−
281279
282280blocks :: PandocMonad m => LP m Blocks
283281blocks = mconcat <$> many block
@@ -1168,12 +1166,12 @@ environments = M.fromList
11681166 , ("subfigure", env "subfigure" $ skipopts *> tok *> figure)
11691167 , ("center", env "center" blocks)
11701168 , ("longtable", env "longtable" $
1171− resetCaption *> simpTable False >>= addTableCaption)
1169+ resetCaption *> simpTable "longtable" False >>= addTableCaption)
11721170 , ("table", env "table" $
11731171 resetCaption *> skipopts *> blocks >>= addTableCaption)
1174− , ("tabular*", env "tabular" $ simpTable True)
1175− , ("tabularx", env "tabularx" $ simpTable True)
1176− , ("tabular", env "tabular" $ simpTable False)
1172+ , ("tabular*", env "tabular" $ simpTable "tabular*" True)
1173+ , ("tabularx", env "tabularx" $ simpTable "tabularx" True)
1174+ , ("tabular", env "tabular" $ simpTable "tabular" False)
11771175 , ("quote", blockQuote <$> env "quote" blocks)
11781176 , ("quotation", blockQuote <$> env "quotation" blocks)
11791177 , ("verse", blockQuote <$> env "verse" blocks)
@@ -1489,25 +1487,27 @@ amp :: PandocMonad m => LP m ()
14891487amp = () <$ try (spaces' *> char '&' <* spaces')
14901488
14911489parseTableRow :: PandocMonad m
1492− => Int -- ^ number of columns
1490+ => String -- ^ table environment name
1491+ -> Int -- ^ number of columns
14931492 -> [String] -- ^ prefixes
14941493 -> [String] -- ^ suffixes
14951494 -> LP m [Blocks]
1496−parseTableRow cols prefixes suffixes = try $ do
1495+parseTableRow envname cols prefixes suffixes = try $ do
14971496 let tableCellRaw = concat <$> many
1498− (do notFollowedBy (amp <|> lbreak <|> (() <$ try (string "\\end")))
1497+ (do notFollowedBy amp
1498+ notFollowedBy lbreak
1499+ notFollowedBy $ () <$ try (string ("\\end{" ++ envname ++ "}"))
14991500 many1 (noneOf "&%\n\r\\")
15001501 <|> try (string "\\&")
15011502 <|> count 1 anyChar)
1502− let minipage = try $ controlSeq "begin" *> string "{minipage}" *>
1503− env "minipage"
1504− (skipopts *> spaces' *> optional braced *> spaces' *> blocks)
1505− let tableCell = minipage <|>
1506− ((plain . trimInlines . mconcat) <$> many inline)
1503+ let plainify bs = case toList bs of
1504+ [Para ils] -> plain (fromList ils)
1505+ _ -> bs
15071506 rawcells <- sepBy1 tableCellRaw amp
15081507 guard $ length rawcells == cols
15091508 let rawcells' = zipWith3 (\c p s -> p ++ trim c ++ s)
15101509 rawcells prefixes suffixes
1510+ let tableCell = plainify <$> blocks
15111511 cells' <- mapM (parseFromString' tableCell) rawcells'
15121512 let numcells = length cells'
15131513 guard $ numcells <= cols && numcells >= 1
@@ -1520,8 +1520,8 @@ parseTableRow cols prefixes suffixes = try $ do
15201520spaces' :: PandocMonad m => LP m ()
15211521spaces' = spaces *> skipMany (comment *> spaces)
15221522
1523−simpTable :: PandocMonad m => Bool -> LP m Blocks
1524−simpTable hasWidthParameter = try $ do
1523+simpTable :: PandocMonad m => String -> Bool -> LP m Blocks
1524+simpTable envname hasWidthParameter = try $ do
15251525 when hasWidthParameter $ () <$ (spaces' >> tok)
15261526 skipopts
15271527 (prefixes, aligns, suffixes) <- unzip3 <$> parseAligns
@@ -1531,10 +1531,10 @@ simpTable hasWidthParameter = try $ do
15311531 spaces'
15321532 skipMany hline
15331533 spaces'
1534− header' <- option [] $ try (parseTableRow cols prefixes suffixes <*
1534+ header' <- option [] $ try (parseTableRow envname cols prefixes suffixes <*
15351535 lbreak <* many1 hline)
15361536 spaces'
1537− rows <- sepEndBy (parseTableRow cols prefixes suffixes)
1537+ rows <- sepEndBy (parseTableRow envname cols prefixes suffixes)
15381538 (lbreak <* optional (skipMany hline))
15391539 spaces'
15401540 optional $ controlSeq "caption" *> skipopts *> setCaption