From d905551b12ebbf1071c26a404e24dcbd4577488f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 19 Nov 2016 22:45:36 +0100 Subject: 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. --- src/Text/Pandoc/Readers/LaTeX.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 403e3d222..882609a13 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -340,6 +340,7 @@ blockCommands = M.fromList $ , ("closing", skipopts *> closing) -- , ("hrule", pure horizontalRule) + , ("strut", pure mempty) , ("rule", skipopts *> tok *> tok *> pure horizontalRule) , ("item", skipopts *> looseItem) , ("documentclass", skipopts *> braced *> preamble) @@ -1085,7 +1086,7 @@ environments = M.fromList , ("abstract", mempty <$ (env "abstract" blocks >>= addMeta "abstract")) , ("letter", env "letter" letterContents) , ("minipage", env "minipage" $ - skipopts *> optional tok *> blocks) + skipopts *> spaces' *> optional braced *> spaces' *> blocks) , ("figure", env "figure" $ resetCaption *> skipopts *> blocks >>= addImageCaption) , ("center", env "center" blocks) @@ -1370,7 +1371,9 @@ hline = try $ do -- booktabs rules: controlSeq "toprule" <|> controlSeq "bottomrule" <|> - controlSeq "midrule" + controlSeq "midrule" <|> + controlSeq "endhead" <|> + controlSeq "endfirsthead" spaces' optional $ bracketed (many1 (satisfy (/=']'))) return () @@ -1381,13 +1384,17 @@ lbreak = () <$ try (spaces' *> spaces') amp :: LP () -amp = () <$ try (spaces' *> char '&') +amp = () <$ try (spaces' *> char '&' <* spaces') parseTableRow :: Int -- ^ number of columns -> LP [Blocks] parseTableRow cols = try $ do let tableCellInline = notFollowedBy (amp <|> lbreak) >> inline - let tableCell = (plain . trimInlines . mconcat) <$> many tableCellInline + let minipage = try $ controlSeq "begin" *> string "{minipage}" *> + env "minipage" + (skipopts *> spaces' *> optional braced *> spaces' *> blocks) + let tableCell = minipage <|> + ((plain . trimInlines . mconcat) <$> many tableCellInline) cells' <- sepBy1 tableCell amp let numcells = length cells' guard $ numcells <= cols && numcells >= 1 @@ -1410,7 +1417,9 @@ simpTable hasWidthParameter = try $ do optional lbreak spaces' skipMany hline + spaces' header' <- option [] $ try (parseTableRow cols <* lbreak <* many1 hline) + spaces' rows <- sepEndBy (parseTableRow cols) (lbreak <* optional (skipMany hline)) spaces' optional $ controlSeq "caption" *> skipopts *> setCaption -- cgit v1.2.3