aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-11-19 22:45:36 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-11-19 22:46:32 +0100
commitd905551b12ebbf1071c26a404e24dcbd4577488f (patch)
tree8a80c82f974b563ba0a89acda501b5b16bbca581 /src/Text/Pandoc/Readers
parentf255625ad77ca02a48d0ff5c79d772da00f6164a (diff)
downloadpandoc-d905551b12ebbf1071c26a404e24dcbd4577488f.tar.gz
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.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs17
1 files changed, 13 insertions, 4 deletions
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