From 606a8e2af42df39591df37a1be1a2ef4101d1dcf Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 Aug 2017 20:48:30 -0700 Subject: RST reader: support :widths: attribute for table directive. --- src/Text/Pandoc/Readers/RST.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc/Readers') 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 -- cgit v1.2.3