git.iko.soy/typeable/pandoc
on master help sign in
Fixed bug parsing LaTeX tables with one column.

Thanks to Steven Solie for finding the bug.

commit1db909e49bca332800bd6de38c22722ea559d40f authorJohn MacFarlane <jgm@berkeley.edu> dateMon 19 Mar 2012, 08:18 (15 years ago) parent13eebc6
1 file changed+14−10
src/Text/Pandoc/Readers/LaTeX.hs+14−10
src/Text/Pandoc/Readers/LaTeX.hs+14−10
@@ -919,9 +919,9 @@ parseAligns :: LP [Alignment]
919919parseAligns = try $ do
920920 char '{'
921921 optional $ char '|'
922− let cAlign = char 'c' >> return AlignCenter
923− let lAlign = char 'l' >> return AlignLeft
924− let rAlign = char 'r' >> return AlignRight
922+ let cAlign = AlignCenter <$ char 'c'
923+ let lAlign = AlignLeft <$ char 'l'
924+ let rAlign = AlignRight <$ char 'r'
925925 let alignChar = optional sp *> (cAlign <|> lAlign <|> rAlign)
926926 aligns' <- sepEndBy alignChar (optional $ char '|')
927927 spaces
@@ -932,16 +932,20 @@ parseAligns = try $ do
932932hline :: LP ()
933933hline = () <$ (try $ spaces >> controlSeq "hline")
934934
935+lbreak :: LP ()
936+lbreak = () <$ (try $ spaces *> controlSeq "\\")
937+
938+amp :: LP ()
939+amp = () <$ (try $ spaces *> char '&')
940+
935941parseTableRow :: Int -- ^ number of columns
936942 -> LP [Blocks]
937943parseTableRow cols = try $ do
938− let amp = try $ spaces *> string "&"
939− let tableCellInline = notFollowedBy (amp <|> controlSeq "\\") >> inline
940− cells' <- sepBy ((plain . trimInlines . mconcat) <$> many tableCellInline) amp
944+ let tableCellInline = notFollowedBy (amp <|> lbreak) >> inline
945+ let tableCell = (plain . trimInlines . mconcat) <$> many tableCellInline
946+ cells' <- sepBy tableCell amp
941947 guard $ length cells' == cols
942948 spaces
943− optional $ controlSeq "\\"
944− spaces
945949 return cells'
946950
947951simpTable :: LP Blocks
@@ -950,8 +954,8 @@ simpTable = try $ do
950954 aligns <- parseAligns
951955 let cols = length aligns
952956 optional hline
953− header' <- option [] $ try (parseTableRow cols <* hline)
954− rows <- many (parseTableRow cols <* optional hline)
957+ header' <- option [] $ try (parseTableRow cols <* lbreak <* hline)
958+ rows <- sepEndBy (parseTableRow cols) (lbreak <* optional hline)
955959 spaces
956960 let header'' = if null header'
957961 then replicate cols mempty