@@ -519,6 +519,8 @@ blockToMarkdown' opts (BlockQuote blocks) = do
519519 contents <- blockListToMarkdown opts blocks
520520 return $ (prefixed leader contents) <> blankline
521521blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
522+ let numcols = maximum (length aligns : length widths :
523+ map length (headers:rows))
522524 caption' <- inlineListToMarkdown opts caption
523525 let caption'' = if null caption || not (isEnabled Ext_table_captions opts)
524526 then blankline
@@ -530,30 +532,38 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
530532 let isPlainBlock (Plain _) = True
531533 isPlainBlock _ = False
532534 let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
533− rawHeaders <- mapM (blockListToMarkdown opts) headers
534− rawRows <- mapM (mapM (blockListToMarkdown opts)) rows
535+ let padRow r = case numcols - length r of
536+ x | x > 0 -> r ++ replicate x empty
537+ | otherwise -> r
538+ rawHeaders <- padRow <$> mapM (blockListToMarkdown opts) headers
539+ rawRows <- mapM (fmap padRow . mapM (blockListToMarkdown opts)) rows
540+ let aligns' = case numcols - length aligns of
541+ x | x > 0 -> aligns ++ replicate x AlignDefault
542+ | otherwise -> aligns
543+ let widths' = case numcols - length widths of
544+ x | x > 0 -> widths ++ replicate x 0.0
545+ | otherwise -> widths
535546 (nst,tbl) <-
536547 case True of
537548 _ | isSimple &&
538549 isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
539− pandocTable opts (all null headers) aligns widths
550+ pandocTable opts (all null headers) aligns' widths'
540551 rawHeaders rawRows
541552 | isSimple &&
542553 isEnabled Ext_pipe_tables opts -> fmap (id,) $
543− pipeTable (all null headers) aligns rawHeaders rawRows
554+ pipeTable (all null headers) aligns' rawHeaders rawRows
544555 | not hasBlocks &&
545556 isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
546− pandocTable opts (all null headers) aligns widths
557+ pandocTable opts (all null headers) aligns' widths'
547558 rawHeaders rawRows
548559 | isEnabled Ext_grid_tables opts &&
549− writerColumns opts >= 8 * length headers -> do
550− let numcols = length headers
551− let widths' = if all (==0) widths
552− then replicate numcols
560+ writerColumns opts >= 8 * numcols -> do
561+ let widths'' = if all (==0) widths'
562+ then replicate numcols
553563 (1.0 / fromIntegral numcols)
554− else widths
564+ else widths'
555565 let widthsInChars = map ((\x -> x - 3) . floor .
556− (fromIntegral (writerColumns opts) *)) widths'
566+ (fromIntegral (writerColumns opts) *)) widths''
557567 rawHeaders' <- zipWithM
558568 blockListToMarkdown
559569 (map (\w -> opts{writerColumns =
@@ -569,7 +579,7 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
569579 cs)
570580 rows
571581 fmap (id,) $
572− gridTable (all null headers) aligns widthsInChars
582+ gridTable (all null headers) aligns' widthsInChars
573583 rawHeaders' rawRows'
574584 | isEnabled Ext_raw_html opts -> fmap (id,) $
575585 text <$>