git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Handle multiline cells in simple tables.

Closes #1166.

commit4d25bba5f7a620ee6fe43c43d1a14cce4c357858 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 2 Mar 2017, 16:48 (10 years ago) parent46135ac
2 files changed+64−8
src/Text/Pandoc/Readers/RST.hs+16−8 test/command/1166.md+48
src/Text/Pandoc/Readers/RST.hs+16−8
@@ -1029,22 +1029,29 @@ simpleTableFooter = try $ simpleTableSep '=' >> blanklines
10291029
10301030-- Parse a raw line and split it into chunks by indices.
10311031simpleTableRawLine :: Monad m => [Int] -> RSTParser m [String]
1032−simpleTableRawLine indices = do
1033− line <- many1Till anyChar newline
1034− return (simpleTableSplitLine indices line)
1032+simpleTableRawLine indices = simpleTableSplitLine indices <$> anyLine
1033+
1034+simpleTableRawLineWithEmptyCell :: Monad m => [Int] -> RSTParser m [String]
1035+simpleTableRawLineWithEmptyCell indices = try $ do
1036+ cs <- simpleTableRawLine indices
1037+ let isEmptyCell = all (\c -> c == ' ' || c == '\t')
1038+ guard $ any isEmptyCell cs
1039+ return cs
10351040
10361041-- Parse a table row and return a list of blocks (columns).
10371042simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [Blocks]
10381043simpleTableRow indices = do
10391044 notFollowedBy' simpleTableFooter
10401045 firstLine <- simpleTableRawLine indices
1041− colLines <- return [] -- TODO
1042− let cols = map unlines . transpose $ firstLine : colLines
1043− mapM (parseFromString (mconcat <$> many plain)) cols
1046+ conLines <- many $ simpleTableRawLineWithEmptyCell indices
1047+ let cols = map unlines . transpose $ firstLine : conLines ++
1048+ [replicate (length indices) ""
1049+ | not (null conLines)]
1050+ mapM (parseFromString parseBlocks) cols
10441051
10451052simpleTableSplitLine :: [Int] -> String -> [String]
10461053simpleTableSplitLine indices line =
1047− map trim
1054+ map trimr
10481055 $ tail $ splitByIndices (init indices) line
10491056
10501057simpleTableHeader :: PandocMonad m
@@ -1125,7 +1132,8 @@ hyphens = do
11251132
11261133escapedChar :: Monad m => ParserT [Char] st m Inlines
11271134escapedChar = do c <- escaped anyChar
1128− return $ if c == ' ' -- '\ ' is null in RST
1135+ return $ if c == ' ' || c == '\n' || c == '\r'
1136+ -- '\ ' is null in RST
11291137 then mempty
11301138 else B.str [c]
11311139
test/command/1166.mdnew file+48
@@ -0,0 +1,48 @@
1+See #1166 and <http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#simple-tables>.
2+
3+```
4+% pandoc -f rst -t html5
5+===== =====
6+col 1 col 2
7+===== =====
8+1 Second column of row 1.
9+2 Second column of row 2.
10+ Second line of paragraph.
11+3 - Second column of row 3.
12+
13+ - Second item in bullet
14+ list (row 3, column 2).
15+\ Row 4; column 1 will be empty.
16+===== =====
17+^D
18+<table>
19+<thead>
20+<tr class="header">
21+<th>col 1</th>
22+<th>col 2</th>
23+</tr>
24+</thead>
25+<tbody>
26+<tr class="odd">
27+<td>1</td>
28+<td>Second column of row 1.</td>
29+</tr>
30+<tr class="even">
31+<td><p>2</p></td>
32+<td><p>Second column of row 2. Second line of paragraph.</p></td>
33+</tr>
34+<tr class="odd">
35+<td><p>3</p></td>
36+<td><ul>
37+<li>Second column of row 3.</li>
38+<li>Second item in bullet list (row 3, column 2).</li>
39+</ul></td>
40+</tr>
41+<tr class="even">
42+<td></td>
43+<td>Row 4; column 1 will be empty.</td>
44+</tr>
45+</tbody>
46+</table>
47+```
48+