git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: improved table handling.

We can now parse all of the tables emitted by pandoc in our tests. The only thing we don't get yet are alignments and column widths in more complex tables. See #2669.

commitd905551b12ebbf1071c26a404e24dcbd4577488f authorJohn MacFarlane <jgm@berkeley.edu> dateSat 19 Nov 2016, 22:45 (10 years ago) parentf255625
1 file changed+13−4
src/Text/Pandoc/Readers/LaTeX.hs+13−4
src/Text/Pandoc/Readers/LaTeX.hs+13−4
@@ -340,6 +340,7 @@ blockCommands = M.fromList $
340340 , ("closing", skipopts *> closing)
341341 --
342342 , ("hrule", pure horizontalRule)
343+ , ("strut", pure mempty)
343344 , ("rule", skipopts *> tok *> tok *> pure horizontalRule)
344345 , ("item", skipopts *> looseItem)
345346 , ("documentclass", skipopts *> braced *> preamble)
@@ -1085,7 +1086,7 @@ environments = M.fromList
10851086 , ("abstract", mempty <$ (env "abstract" blocks >>= addMeta "abstract"))
10861087 , ("letter", env "letter" letterContents)
10871088 , ("minipage", env "minipage" $
1088− skipopts *> optional tok *> blocks)
1089+ skipopts *> spaces' *> optional braced *> spaces' *> blocks)
10891090 , ("figure", env "figure" $
10901091 resetCaption *> skipopts *> blocks >>= addImageCaption)
10911092 , ("center", env "center" blocks)
@@ -1370,7 +1371,9 @@ hline = try $ do
13701371 -- booktabs rules:
13711372 controlSeq "toprule" <|>
13721373 controlSeq "bottomrule" <|>
1373− controlSeq "midrule"
1374+ controlSeq "midrule" <|>
1375+ controlSeq "endhead" <|>
1376+ controlSeq "endfirsthead"
13741377 spaces'
13751378 optional $ bracketed (many1 (satisfy (/=']')))
13761379 return ()
@@ -1381,13 +1384,17 @@ lbreak = () <$ try (spaces' *>
13811384 spaces')
13821385
13831386amp :: LP ()
1384−amp = () <$ try (spaces' *> char '&')
1387+amp = () <$ try (spaces' *> char '&' <* spaces')
13851388
13861389parseTableRow :: Int -- ^ number of columns
13871390 -> LP [Blocks]
13881391parseTableRow cols = try $ do
13891392 let tableCellInline = notFollowedBy (amp <|> lbreak) >> inline
1390− let tableCell = (plain . trimInlines . mconcat) <$> many tableCellInline
1393+ let minipage = try $ controlSeq "begin" *> string "{minipage}" *>
1394+ env "minipage"
1395+ (skipopts *> spaces' *> optional braced *> spaces' *> blocks)
1396+ let tableCell = minipage <|>
1397+ ((plain . trimInlines . mconcat) <$> many tableCellInline)
13911398 cells' <- sepBy1 tableCell amp
13921399 let numcells = length cells'
13931400 guard $ numcells <= cols && numcells >= 1
@@ -1410,7 +1417,9 @@ simpTable hasWidthParameter = try $ do
14101417 optional lbreak
14111418 spaces'
14121419 skipMany hline
1420+ spaces'
14131421 header' <- option [] $ try (parseTableRow cols <* lbreak <* many1 hline)
1422+ spaces'
14141423 rows <- sepEndBy (parseTableRow cols) (lbreak <* optional (skipMany hline))
14151424 spaces'
14161425 optional $ controlSeq "caption" *> skipopts *> setCaption