Skip to content

Commit 70393b4

Browse files
committed
RST reader: fix regression in simple table parsing.
Closes #11150.
1 parent 4f2a383 commit 70393b4

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

src/Text/Pandoc/Readers/RST.hs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Conversion from reStructuredText to 'Pandoc' document.
1515
-}
1616
module Text.Pandoc.Readers.RST ( readRST ) where
1717
import Control.Arrow (second)
18-
import Control.Monad (forM_, guard, liftM, mplus, mzero, when, unless)
18+
import Control.Monad (forM_, guard, liftM, mplus, mzero, when, unless, void)
1919
import Control.Monad.Except (throwError)
2020
import Control.Monad.Identity (Identity (..))
2121
import Data.Char (isHexDigit, isSpace, toUpper, isAlphaNum, generalCategory,
@@ -288,7 +288,7 @@ rawFieldListItem minIndent = try $ do
288288
guard $ indent >= minIndent
289289
char ':'
290290
name <- many1TillChar (noneOf "\n") (char ':')
291-
(() <$ lookAhead newline) <|> skipMany1 spaceChar
291+
(void (lookAhead newline)) <|> skipMany1 spaceChar
292292
first <- anyLine
293293
rest <- option "" $ try $ do lookAhead (count indent (char ' ') >> spaceChar)
294294
indentedBlock
@@ -343,7 +343,7 @@ optArg :: PandocMonad m => RSTParser m ()
343343
optArg = do
344344
c <- letter <|> char '<'
345345
if c == '<'
346-
then () <$ manyTill (noneOf "<>") (char '>')
346+
then void $ manyTill (noneOf "<>") (char '>')
347347
else skipMany (alphaNum <|> char '_' <|> char '-')
348348

349349
longOpt :: PandocMonad m => RSTParser m ()
@@ -672,7 +672,7 @@ listItem :: PandocMonad m
672672
listItem start = try $ do
673673
(markerLength, first) <- rawListItem start
674674
rest <- many (listContinuation markerLength)
675-
skipMany1 blankline <|> () <$ lookAhead start
675+
skipMany1 blankline <|> void (lookAhead start)
676676
-- parsing with ListItemState forces markers at beginning of lines to
677677
-- count as list item markers, even if not separated by blank space.
678678
-- see definition of "endline"
@@ -710,7 +710,7 @@ bulletList = B.bulletList . compactify <$> many1 (listItem bulletListStart)
710710
comment :: Monad m => RSTParser m Blocks
711711
comment = try $ do
712712
string ".."
713-
skipMany1 spaceChar <|> (() <$ lookAhead newline)
713+
skipMany1 spaceChar <|> void (lookAhead newline)
714714
-- notFollowedBy' directiveLabel -- comment comes after directive so unnec.
715715
_ <- anyLine
716716
optional indentedBlock
@@ -1373,8 +1373,10 @@ dashedLine ch = do
13731373
return (length dashes, length sp)
13741374

13751375
simpleDashedLines :: Monad m => Char -> ParsecT Sources st m [(Int,Int)]
1376-
simpleDashedLines ch = do
1377-
lines' <- try $ many1 (dashedLine ch)
1376+
simpleDashedLines ch = try $ do
1377+
lines' <- many1 (dashedLine ch)
1378+
skipMany spaceChar
1379+
newline
13781380
return $ addSpaces lines'
13791381
where
13801382
addSpaces [] = []
@@ -1383,12 +1385,12 @@ simpleDashedLines ch = do
13831385
(dashes, dashes + sp) : addSpaces moreLines
13841386

13851387
-- Parse a table row separator
1386-
simpleTableSep :: Monad m => Char -> RSTParser m Char
1387-
simpleTableSep ch = try $ simpleDashedLines ch >> newline
1388+
simpleTableSep :: Monad m => Char -> RSTParser m ()
1389+
simpleTableSep ch = void (simpleDashedLines ch)
13881390

13891391
-- Parse a table footer
1390-
simpleTableFooter :: Monad m => RSTParser m Text
1391-
simpleTableFooter = try $ simpleTableSep '=' >> blanklines
1392+
simpleTableFooter :: Monad m => RSTParser m ()
1393+
simpleTableFooter = try $ simpleTableSep '=' >> void blanklines
13921394

13931395
-- Parse a raw line and split it into chunks by indices.
13941396
simpleTableRawLine :: Monad m => [Int] -> RSTParser m [(Text, ColSpan)]
@@ -1410,7 +1412,7 @@ simpleTableRawLineWithInitialEmptyCell indices = try $ do
14101412
-- Parse a table row and return a list of blocks (columns).
14111413
simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [(Blocks, RowSpan, ColSpan)]
14121414
simpleTableRow indices = do
1413-
notFollowedBy' (blanklines <|> simpleTableFooter)
1415+
notFollowedBy' (void blanklines <|> simpleTableFooter)
14141416
firstLine <- simpleTableRawLine indices
14151417
conLines <- many $ simpleTableRawLineWithInitialEmptyCell indices
14161418
let cols = map T.unlines . transpose $ (map fst firstLine) : (map (map fst) conLines) ++
@@ -1434,15 +1436,12 @@ simpleTableHeader :: PandocMonad m
14341436
simpleTableHeader headless = try $ do
14351437
optional blanklines
14361438
dashes <- simpleDashedLines '='
1437-
newline
14381439

14391440
rawContent <- if headless
14401441
then return [("", Nothing)]
14411442
else many1 $ notFollowedBy (simpleDashedLines '=') >> rowWithOptionalColSpan
14421443

1443-
if headless
1444-
then return ' '
1445-
else simpleTableSep '='
1444+
unless headless $ simpleTableSep '='
14461445

14471446
let (lines', indices) = dashedLinesToLinesWithIndices dashes
14481447
let aligns = replicate (length lines') AlignDefault
@@ -1463,10 +1462,7 @@ rowWithOptionalColSpan :: Monad m
14631462
=> RSTParser m (Text, Maybe [Int])
14641463
rowWithOptionalColSpan = do
14651464
line <- anyLine
1466-
colSpanHyphens <- optionMaybe $ do
1467-
colHyphens <- simpleDashedLines '-'
1468-
newline
1469-
return colHyphens
1465+
colSpanHyphens <- optionMaybe $ simpleDashedLines '-'
14701466

14711467
let colSpan = fmap colSpanFromHyphens colSpanHyphens
14721468
return (line, colSpan)
@@ -1703,7 +1699,7 @@ unmarkedInterpretedText = try $ do
17031699
<|> (char '\\' >> ((\c -> ['\\',c]) <$> noneOf "\n"))
17041700
<|> (string "\n" <* notFollowedBy blankline)
17051701
<|> try (string "`" <*
1706-
notFollowedBy (() <$ roleMarker) <*
1702+
notFollowedBy (void roleMarker) <*
17071703
lookAhead (satisfy isAlphaNum))
17081704
)
17091705
char '`'

test/command/11150.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
```
2+
% pandoc -f rst
3+
=== =====
4+
int float
5+
=== =====
6+
10 9.90
7+
-10 9.90
8+
=== =====
9+
^D
10+
<table>
11+
<thead>
12+
<tr>
13+
<th>int</th>
14+
<th>float</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
<tr>
19+
<td>10</td>
20+
<td>9.90</td>
21+
</tr>
22+
<tr>
23+
<td>-10</td>
24+
<td>9.90</td>
25+
</tr>
26+
</tbody>
27+
</table>
28+
29+
```

0 commit comments

Comments
 (0)