@@ -1271,14 +1271,22 @@ gridTableSplitLine :: [Int] -> String -> [String]
1271gridTableSplitLine indices line = map removeFinalBar $ tail $
1271gridTableSplitLine indices line = map removeFinalBar $ tail $
1272 splitStringByIndices (init indices) $ trimr line
1272 splitStringByIndices (init indices) $ trimr line
1274−gridPart :: Char -> Parser [Char] st (Int, Int)
1274+gridPart :: Char -> Parser [Char] st ((Int, Int), Alignment)
1275gridPart ch = do
1275gridPart ch = do
1276+ leftColon <- option False (True <$ char ':')
1276 dashes <- many1 (char ch)
1277 dashes <- many1 (char ch)
1278+ rightColon <- option False (True <$ char ':')
1277 char '+'
1279 char '+'
1278− let lengthDashes = length dashes
1280+ let lengthDashes = length dashes + (if leftColon then 1 else 0) +
1281+ (if rightColon then 1 else 0)
1282+ let alignment = case (leftColon, rightColon) of
1283+ (True, True) -> AlignCenter
1284+ (True, False) -> AlignLeft
1285+ (False, True) -> AlignRight
1286+ (False, False) -> AlignDefault
1279− return (lengthDashes, lengthDashes + 1)
1287+ return ((lengthDashes, lengthDashes + 1), alignment)
1281−gridDashedLines :: Char -> Parser [Char] st [(Int,Int)]
1289+gridDashedLines :: Char -> Parser [Char] st [((Int, Int), Alignment)]
1282gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) <* blankline
1290gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) <* blankline
1284removeFinalBar :: String -> String
1292removeFinalBar :: String -> String
@@ -1296,19 +1304,17 @@ gridTableHeader headless = try $ do
1296 optional blanklines
1304 optional blanklines
1297 dashes <- gridDashedLines '-'
1305 dashes <- gridDashedLines '-'
1298 rawContent <- if headless
1306 rawContent <- if headless
1299− then return $ repeat ""
1307+ then return []
1300− else many1
1308+ else many1 (try (char '|' >> anyLine))
1301− (notFollowedBy (gridTableSep '=') >> char '|' >>
1302− many1Till anyChar newline)
1303− if headless
1309+ underDashes <- if headless
1304− then return ()
1310+ then return dashes
1305− else gridTableSep '=' >> return ()
1311+ else gridDashedLines '='
1312+ guard $ length dashes == length underDashes
1306− let lines' = map snd dashes
1313+ let lines' = map (snd . fst) underDashes
1307 let indices = scanl (+) 0 lines'
1314 let indices = scanl (+) 0 lines'
1308− let aligns = replicate (length lines') AlignDefault
1315+ let aligns = map snd underDashes
1309− -- RST does not have a notion of alignments
1310 let rawHeads = if headless
1316 let rawHeads = if headless
1311− then replicate (length dashes) ""
1317+ then replicate (length underDashes) ""
1312 else map (unlines . map trim) $ transpose
1318 else map (unlines . map trim) $ transpose
1313 $ map (gridTableSplitLine indices) rawContent
1319 $ map (gridTableSplitLine indices) rawContent
1314 heads <- fmap sequence $ mapM (parseFromString parseBlocks . trim) rawHeads
1320 heads <- fmap sequence $ mapM (parseFromString parseBlocks . trim) rawHeads
@@ -1317,7 +1323,7 @@ gridTableHeader headless = try $ do
1317gridTableRawLine :: [Int] -> MarkdownParser [String]
1323gridTableRawLine :: [Int] -> MarkdownParser [String]
1318gridTableRawLine indices = do
1324gridTableRawLine indices = do
1319 char '|'
1325 char '|'
1320− line <- many1Till anyChar newline
1326+ line <- anyLine
1321 return (gridTableSplitLine indices line)
1327 return (gridTableSplitLine indices line)
1323-- | Parse row of grid table.
1329-- | Parse row of grid table.