@@ -478,16 +478,24 @@ addMarkdownAttribute s =
478478
479479pipeTable :: Bool -> [Alignment] -> [Doc] -> [[Doc]] -> State WriterState Doc
480480pipeTable headless aligns rawHeaders rawRows = do
481+ let sp = text " "
482+ let blockFor AlignLeft x y = lblock (x + 2) (sp <> y) <> lblock 0 empty
483+ blockFor AlignCenter x y = cblock (x + 2) (sp <> y) <> lblock 0 empty
484+ blockFor AlignRight x y = rblock (x + 2) (sp <> y) <> lblock 0 empty
485+ blockFor _ x y = lblock (x + 2) (sp <> y) <> lblock 0 empty
486+ let widths = map (max 3 . maximum . map offset) $ transpose (rawHeaders : rawRows)
481487 let torow cs = nowrap $ text "|" <>
482− hcat (intersperse (text "|") $ map chomp cs) <> text "|"
483− let toborder (a, h) = let wid = max (offset h) 3
484− in text $ case a of
485− AlignLeft -> ':':replicate (wid - 1) '-'
486− AlignCenter -> ':':replicate (wid - 2) '-' ++ ":"
487− AlignRight -> replicate (wid - 1) '-' ++ ":"
488− AlignDefault -> replicate wid '-'
488+ hcat (intersperse (text "|") $
489+ zipWith3 blockFor aligns widths (map chomp cs))
490+ <> text "|"
491+ let toborder (a, w) = text $ case a of
492+ AlignLeft -> ':':replicate (w + 1) '-'
493+ AlignCenter -> ':':replicate w '-' ++ ":"
494+ AlignRight -> replicate (w + 1) '-' ++ ":"
495+ AlignDefault -> replicate (w + 2) '-'
489496 let header = if headless then empty else torow rawHeaders
490− let border = torow $ map toborder $ zip aligns rawHeaders
497+ let border = nowrap $ text "|" <> hcat (intersperse (text "|") $
498+ map toborder $ zip aligns widths) <> text "|"
491499 let body = vcat $ map torow rawRows
492500 return $ header $$ border $$ body
493501