@@ -840,7 +840,6 @@ simpleTable headless = do
840840 Table c a _w h l <- tableWith (simpleTableHeader headless) tableLine
841841 (return ())
842842 (if headless then tableFooter else tableFooter <|> blanklines)
843− tableCaption
844843 -- Simple tables get 0s for relative column widths (i.e., use default)
845844 return $ Table c a (replicate (length a) 0) h l
846845
@@ -851,7 +850,7 @@ simpleTable headless = do
851850multilineTable :: Bool -- ^ Headerless table
852851 -> Parser [Char] ParserState Block
853852multilineTable headless =
854− tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter tableCaption
853+ tableWith (multilineTableHeader headless) multilineRow blanklines tableFooter
855854
856855multilineTableHeader :: Bool -- ^ Headerless table
857856 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
@@ -903,12 +902,12 @@ alignType strLst len =
903902
904903gridTable :: Bool -- ^ Headerless table
905904 -> Parser [Char] ParserState Block
906−gridTable = gridTableWith block tableCaption
905+gridTable = gridTableWith block
907906
908907pipeTable :: Bool -- ^ Headerless table
909908 -> Parser [Char] ParserState Block
910909pipeTable headless = tableWith (pipeTableHeader headless)
911− (\_ -> pipeTableRow) (return ()) blanklines tableCaption
910+ (\_ -> pipeTableRow) (return ()) blanklines
912911
913912-- | Parse header for an pipe table.
914913pipeTableHeader :: Bool -- ^ Headerless table
@@ -961,12 +960,19 @@ scanForPipe :: Parser [Char] st ()
961960scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return ()
962961
963962table :: Parser [Char] ParserState Block
964−table = multilineTable False <|> simpleTable True <|>
965− simpleTable False <|> multilineTable True <|>
966− pipeTable False <|> pipeTable True <|>
967− gridTable False <|> gridTable True <?> "table"
963+table = try $ do
964+ frontCaption <- option [] tableCaption
965+ Table _ aligns widths heads lines' <-
966+ multilineTable False <|> simpleTable True <|>
967+ simpleTable False <|> multilineTable True <|>
968+ pipeTable False <|> pipeTable True <|>
969+ gridTable False <|> gridTable True <?> "table"
970+ caption <- if null frontCaption
971+ then option [] tableCaption
972+ else return frontCaption
973+ return $ Table caption aligns widths heads lines'
968974
969−--
975+--
970976-- inline
971977--
972978