git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Handle block structure inside table cells.
1e7ba5cJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+18−18
@@ -276,8 +276,6 @@ block = (mempty <$ comment)
276 <|> blockCommand
276 <|> blockCommand
277 <|> paragraph
277 <|> paragraph
278 <|> grouped block
278 <|> grouped block
279− <|> (mempty <$ char '&') -- loose & in table environment
280−
281
279
282blocks :: PandocMonad m => LP m Blocks
280blocks :: PandocMonad m => LP m Blocks
283blocks = mconcat <$> many block
281blocks = mconcat <$> many block
@@ -1168,12 +1166,12 @@ environments = M.fromList
1168 , ("subfigure", env "subfigure" $ skipopts *> tok *> figure)
1166 , ("subfigure", env "subfigure" $ skipopts *> tok *> figure)
1169 , ("center", env "center" blocks)
1167 , ("center", env "center" blocks)
1170 , ("longtable", env "longtable" $
1168 , ("longtable", env "longtable" $
1171− resetCaption *> simpTable False >>= addTableCaption)
1169+ resetCaption *> simpTable "longtable" False >>= addTableCaption)
1172 , ("table", env "table" $
1170 , ("table", env "table" $
1173 resetCaption *> skipopts *> blocks >>= addTableCaption)
1171 resetCaption *> skipopts *> blocks >>= addTableCaption)
1174− , ("tabular*", env "tabular" $ simpTable True)
1172+ , ("tabular*", env "tabular" $ simpTable "tabular*" True)
1175− , ("tabularx", env "tabularx" $ simpTable True)
1173+ , ("tabularx", env "tabularx" $ simpTable "tabularx" True)
1176− , ("tabular", env "tabular" $ simpTable False)
1174+ , ("tabular", env "tabular" $ simpTable "tabular" False)
1177 , ("quote", blockQuote <$> env "quote" blocks)
1175 , ("quote", blockQuote <$> env "quote" blocks)
1178 , ("quotation", blockQuote <$> env "quotation" blocks)
1176 , ("quotation", blockQuote <$> env "quotation" blocks)
1179 , ("verse", blockQuote <$> env "verse" blocks)
1177 , ("verse", blockQuote <$> env "verse" blocks)
@@ -1489,25 +1487,27 @@ amp :: PandocMonad m => LP m ()
1489amp = () <$ try (spaces' *> char '&' <* spaces')
1487amp = () <$ try (spaces' *> char '&' <* spaces')
1490
1488
1491parseTableRow :: PandocMonad m
1489parseTableRow :: PandocMonad m
1490+ => String -- ^ table environment name
1492− => Int -- ^ number of columns
1491+ -> Int -- ^ number of columns
1493 -> [String] -- ^ prefixes
1492 -> [String] -- ^ prefixes
1494 -> [String] -- ^ suffixes
1493 -> [String] -- ^ suffixes
1495 -> LP m [Blocks]
1494 -> LP m [Blocks]
1496−parseTableRow cols prefixes suffixes = try $ do
1495+parseTableRow envname cols prefixes suffixes = try $ do
1497 let tableCellRaw = concat <$> many
1496 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 ++ "}"))
1499 many1 (noneOf "&%\n\r\\")
1500 many1 (noneOf "&%\n\r\\")
1500 <|> try (string "\\&")
1501 <|> try (string "\\&")
1501 <|> count 1 anyChar)
1502 <|> count 1 anyChar)
1502− let minipage = try $ controlSeq "begin" *> string "{minipage}" *>
1503+ let plainify bs = case toList bs of
1503− env "minipage"
1504+ [Para ils] -> plain (fromList ils)
1504− (skipopts *> spaces' *> optional braced *> spaces' *> blocks)
1505+ _ -> bs
1505− let tableCell = minipage <|>
1506− ((plain . trimInlines . mconcat) <$> many inline)
1507 rawcells <- sepBy1 tableCellRaw amp
1506 rawcells <- sepBy1 tableCellRaw amp
1508 guard $ length rawcells == cols
1507 guard $ length rawcells == cols
1509 let rawcells' = zipWith3 (\c p s -> p ++ trim c ++ s)
1508 let rawcells' = zipWith3 (\c p s -> p ++ trim c ++ s)
1510 rawcells prefixes suffixes
1509 rawcells prefixes suffixes
1510+ let tableCell = plainify <$> blocks
1511 cells' <- mapM (parseFromString' tableCell) rawcells'
1511 cells' <- mapM (parseFromString' tableCell) rawcells'
1512 let numcells = length cells'
1512 let numcells = length cells'
1513 guard $ numcells <= cols && numcells >= 1
1513 guard $ numcells <= cols && numcells >= 1
@@ -1520,8 +1520,8 @@ parseTableRow cols prefixes suffixes = try $ do
1520spaces' :: PandocMonad m => LP m ()
1520spaces' :: PandocMonad m => LP m ()
1521spaces' = spaces *> skipMany (comment *> spaces)
1521spaces' = spaces *> skipMany (comment *> spaces)
1522
1522
1523−simpTable :: PandocMonad m => Bool -> LP m Blocks
1523+simpTable :: PandocMonad m => String -> Bool -> LP m Blocks
1524−simpTable hasWidthParameter = try $ do
1524+simpTable envname hasWidthParameter = try $ do
1525 when hasWidthParameter $ () <$ (spaces' >> tok)
1525 when hasWidthParameter $ () <$ (spaces' >> tok)
1526 skipopts
1526 skipopts
1527 (prefixes, aligns, suffixes) <- unzip3 <$> parseAligns
1527 (prefixes, aligns, suffixes) <- unzip3 <$> parseAligns
@@ -1531,10 +1531,10 @@ simpTable hasWidthParameter = try $ do
1531 spaces'
1531 spaces'
1532 skipMany hline
1532 skipMany hline
1533 spaces'
1533 spaces'
1534− header' <- option [] $ try (parseTableRow cols prefixes suffixes <*
1534+ header' <- option [] $ try (parseTableRow envname cols prefixes suffixes <*
1535 lbreak <* many1 hline)
1535 lbreak <* many1 hline)
1536 spaces'
1536 spaces'
1537− rows <- sepEndBy (parseTableRow cols prefixes suffixes)
1537+ rows <- sepEndBy (parseTableRow envname cols prefixes suffixes)
1538 (lbreak <* optional (skipMany hline))
1538 (lbreak <* optional (skipMany hline))
1539 spaces'
1539 spaces'
1540 optional $ controlSeq "caption" *> skipopts *> setCaption
1540 optional $ controlSeq "caption" *> skipopts *> setCaption