diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-06-01 11:56:59 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-06-01 11:56:59 +0200 |
commit | af6e8414c7d39d80831720d35a6d0d5f6e09bbd5 (patch) | |
tree | befc8a5683e0f0ef3af91a6ca63dd7ba339270e5 /src | |
parent | 58cfac84f01d86d45e31a02bc40ade8c88f5f7b2 (diff) | |
download | pandoc-af6e8414c7d39d80831720d35a6d0d5f6e09bbd5.tar.gz |
LaTeX reader: more table refactoring.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 087a26f51..a69c17ebc 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1434,7 +1434,7 @@ complexNatbibCitation mode = try $ do -- tables -parseAligns :: PandocMonad m => LP m [(Alignment, (String, String))] +parseAligns :: PandocMonad m => LP m [(Alignment, Double, (String, String))] parseAligns = try $ do bgroup let maybeBar = skipMany $ sp <|> () <$ char '|' <|> () <$ (char '@' >> braced) @@ -1455,11 +1455,13 @@ parseAligns = try $ do spaces pref <- option "" alignPrefix spaces - ch <- alignChar - _width <- option "" braced -- TODO parse this + al <- alignChar + let parseWidth :: String -> Double + parseWidth _ = 0.00 -- TODO actually parse the width + width <- parseWidth <$> option "" braced spaces suff <- option "" alignSuffix - return (ch, (pref, suff)) + return (al, width, (pref, suff)) aligns' <- sepEndBy alignSpec maybeBar spaces egroup @@ -1490,11 +1492,10 @@ amp = () <$ try (spaces' *> char '&' <* spaces') parseTableRow :: PandocMonad m => String -- ^ table environment name - -> [(Alignment, (String, String))] -- ^ colspecs + -> [(String, String)] -- ^ pref/suffixes -> LP m [Blocks] -parseTableRow envname colspecs = try $ do - let prefsufs = map snd colspecs - let cols = length colspecs +parseTableRow envname prefsufs = try $ do + let cols = length prefsufs let tableCellRaw = concat <$> many (do notFollowedBy amp notFollowedBy lbreak @@ -1526,16 +1527,17 @@ simpTable envname hasWidthParameter = try $ do when hasWidthParameter $ () <$ (spaces' >> tok) skipopts colspecs <- parseAligns + let (aligns, widths, prefsufs) = unzip3 colspecs let cols = length colspecs optional $ controlSeq "caption" *> skipopts *> setCaption optional lbreak spaces' skipMany hline spaces' - header' <- option [] $ try (parseTableRow envname colspecs <* + header' <- option [] $ try (parseTableRow envname prefsufs <* lbreak <* many1 hline) spaces' - rows <- sepEndBy (parseTableRow envname colspecs) + rows <- sepEndBy (parseTableRow envname prefsufs) (lbreak <* optional (skipMany hline)) spaces' optional $ controlSeq "caption" *> skipopts *> setCaption @@ -1545,8 +1547,7 @@ simpTable envname hasWidthParameter = try $ do then replicate cols mempty else header' lookAhead $ controlSeq "end" -- make sure we're at end - let (aligns, _) = unzip colspecs - return $ table mempty (zip aligns (repeat 0)) header'' rows + return $ table mempty (zip aligns widths) header'' rows removeDoubleQuotes :: String -> String removeDoubleQuotes ('"':xs) = |