aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-08-08 20:48:30 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-08 20:48:30 -0700
commit606a8e2af42df39591df37a1be1a2ef4101d1dcf (patch)
treee5352672833e221000b94ab7fa64dabefe099aec /src/Text/Pandoc/Readers
parent2f0bff0f541db82d04c03240af643770dabf9a03 (diff)
downloadpandoc-606a8e2af42df39591df37a1be1a2ef4101d1dcf.tar.gz
RST reader: support :widths: attribute for table directive.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 2daf60a89..6cc3b7472 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -765,15 +765,25 @@ directive' = do
tableDirective :: PandocMonad m
=> String -> [(String, String)] -> String -> RSTParser m Blocks
-tableDirective top _fields body = do
+tableDirective top fields body = do
bs <- parseFromString' parseBlocks body
case B.toList bs of
[Table _ aligns' widths' header' rows'] -> do
title <- parseFromString' (trimInlines . mconcat <$> many inline) top
- -- TODO widths
+ columns <- getOption readerColumns
+ let numOfCols = length header'
+ let normWidths ws =
+ map (/ max 1.0 (fromIntegral (columns - numOfCols))) ws
+ let widths = case trim <$> lookup "widths" fields of
+ Just "auto" -> replicate numOfCols 0.0
+ Just "grid" -> widths'
+ Just specs -> normWidths
+ $ map (fromMaybe (0 :: Double) . safeRead)
+ $ splitBy (`elem` (" ," :: String)) specs
+ Nothing -> widths'
-- align is not applicable since we can't represent whole table align
return $ B.singleton $ Table (B.toList title)
- aligns' widths' header' rows'
+ aligns' widths header' rows'
_ -> return mempty