Permalink
Browse files

Fixed bug parsing LaTeX tables with one column.

Thanks to Steven Solie for finding the bug.
  • Loading branch information...
jgm committed Mar 19, 2012
1 parent 13eebc6 commit 1db909e49bca332800bd6de38c22722ea559d40f
Showing with 14 additions and 10 deletions.
  1. +14 −10 src/Text/Pandoc/Readers/LaTeX.hs
@@ -919,9 +919,9 @@ parseAligns :: LP [Alignment]
parseAligns = try $ do
char '{'
optional $ char '|'
let cAlign = char 'c' >> return AlignCenter
let lAlign = char 'l' >> return AlignLeft
let rAlign = char 'r' >> return AlignRight
let cAlign = AlignCenter <$ char 'c'
let lAlign = AlignLeft <$ char 'l'
let rAlign = AlignRight <$ char 'r'
let alignChar = optional sp *> (cAlign <|> lAlign <|> rAlign)
aligns' <- sepEndBy alignChar (optional $ char '|')
spaces
@@ -932,16 +932,20 @@ parseAligns = try $ do
hline :: LP ()
hline = () <$ (try $ spaces >> controlSeq "hline")
lbreak :: LP ()
lbreak = () <$ (try $ spaces *> controlSeq "\\")
amp :: LP ()
amp = () <$ (try $ spaces *> char '&')
parseTableRow :: Int -- ^ number of columns
-> LP [Blocks]
parseTableRow cols = try $ do
let amp = try $ spaces *> string "&"
let tableCellInline = notFollowedBy (amp <|> controlSeq "\\") >> inline
cells' <- sepBy ((plain . trimInlines . mconcat) <$> many tableCellInline) amp
let tableCellInline = notFollowedBy (amp <|> lbreak) >> inline
let tableCell = (plain . trimInlines . mconcat) <$> many tableCellInline
cells' <- sepBy tableCell amp
guard $ length cells' == cols
spaces
optional $ controlSeq "\\"
spaces
return cells'
simpTable :: LP Blocks
@@ -950,8 +954,8 @@ simpTable = try $ do
aligns <- parseAligns
let cols = length aligns
optional hline
header' <- option [] $ try (parseTableRow cols <* hline)
rows <- many (parseTableRow cols <* optional hline)
header' <- option [] $ try (parseTableRow cols <* lbreak <* hline)
rows <- sepEndBy (parseTableRow cols) (lbreak <* optional hline)
spaces
let header'' = if null header'
then replicate cols mempty

0 comments on commit 1db909e

Please sign in to comment.