@@ -1320,7 +1320,7 @@ removeOneLeadingSpace xs =
13201320gridTableFooter :: MarkdownParser [Char]
13211321gridTableFooter = blanklines
13221322
1323−pipeBreak :: MarkdownParser [Alignment]
1323+pipeBreak :: MarkdownParser ([Alignment], [Int])
13241324pipeBreak = try $ do
13251325 nonindentSpaces
13261326 openPipe <- (True <$ char '|') <|> return False
@@ -1330,16 +1330,22 @@ pipeBreak = try $ do
13301330 guard $ not (null rest && not openPipe)
13311331 optional (char '|')
13321332 blankline
1333− return (first:rest)
1333+ return $ unzip (first:rest)
13341334
13351335pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
13361336pipeTable = try $ do
13371337 nonindentSpaces
13381338 lookAhead nonspaceChar
1339− (heads,aligns) <- (,) <$> pipeTableRow <*> pipeBreak
1340− lines' <- sequence <$> many pipeTableRow
1341− let widths = replicate (length aligns) 0.0
1342− return $ (aligns, widths, heads, lines')
1339+ (heads,(aligns, seplengths)) <- (,) <$> pipeTableRow <*> pipeBreak
1340+ (lines', rawRows) <- unzip <$> many (withRaw pipeTableRow)
1341+ let maxlength = maximum $ map length rawRows
1342+ numColumns <- getOption readerColumns
1343+ let widths = if maxlength > numColumns
1344+ then map (\len ->
1345+ fromIntegral (len + 1) / fromIntegral numColumns)
1346+ seplengths
1347+ else replicate (length aligns) 0.0
1348+ return $ (aligns, widths, heads, sequence lines')
13431349
13441350sepPipe :: MarkdownParser ()
13451351sepPipe = try $ do
@@ -1368,19 +1374,20 @@ pipeTableRow = do
13681374 ils' | B.isNull ils' -> mempty
13691375 | otherwise -> B.plain $ ils') cells'
13701376
1371−pipeTableHeaderPart :: Parser [Char] st Alignment
1377+pipeTableHeaderPart :: Parser [Char] st (Alignment, Int)
13721378pipeTableHeaderPart = try $ do
13731379 skipMany spaceChar
13741380 left <- optionMaybe (char ':')
1375− many1 (char '-')
1381+ pipe <- many1 (char '-')
13761382 right <- optionMaybe (char ':')
13771383 skipMany spaceChar
1384+ let len = length pipe + maybe 0 (const 1) left + maybe 0 (const 1) right
13781385 return $
1379− case (left,right) of
1380− (Nothing,Nothing) -> AlignDefault
1381− (Just _,Nothing) -> AlignLeft
1382− (Nothing,Just _) -> AlignRight
1383− (Just _,Just _) -> AlignCenter
1386+ ((case (left,right) of
1387+ (Nothing,Nothing) -> AlignDefault
1388+ (Just _,Nothing) -> AlignLeft
1389+ (Nothing,Just _) -> AlignRight
1390+ (Just _,Just _) -> AlignCenter), len)
13841391
13851392-- Succeed only if current line contains a pipe.
13861393scanForPipe :: Parser [Char] st ()