git.iko.soy/typeable/pandoc
on master help sign in
RST reader: support :widths: attribute for table directive.
commit606a8e2af42df39591df37a1be1a2ef4101d1dcf authorJohn MacFarlane <jgm@berkeley.edu> dateTue 8 Aug 2017, 20:48 (9 years ago) parent2f0bff0
1 file changed+13−3
src/Text/Pandoc/Readers/RST.hs+13−3
src/Text/Pandoc/Readers/RST.hs+13−3
@@ -765,15 +765,25 @@ directive' = do
765765
766766tableDirective :: PandocMonad m
767767 => String -> [(String, String)] -> String -> RSTParser m Blocks
768−tableDirective top _fields body = do
768+tableDirective top fields body = do
769769 bs <- parseFromString' parseBlocks body
770770 case B.toList bs of
771771 [Table _ aligns' widths' header' rows'] -> do
772772 title <- parseFromString' (trimInlines . mconcat <$> many inline) top
773− -- TODO widths
773+ columns <- getOption readerColumns
774+ let numOfCols = length header'
775+ let normWidths ws =
776+ map (/ max 1.0 (fromIntegral (columns - numOfCols))) ws
777+ let widths = case trim <$> lookup "widths" fields of
778+ Just "auto" -> replicate numOfCols 0.0
779+ Just "grid" -> widths'
780+ Just specs -> normWidths
781+ $ map (fromMaybe (0 :: Double) . safeRead)
782+ $ splitBy (`elem` (" ," :: String)) specs
783+ Nothing -> widths'
774784 -- align is not applicable since we can't represent whole table align
775785 return $ B.singleton $ Table (B.toList title)
776− aligns' widths' header' rows'
786+ aligns' widths header' rows'
777787 _ -> return mempty
778788
779789