git.iko.soy/typeable/pandoc
on master help sign in
RST reader: Handle multiline cells in simple tables.
4d25bbaJohn MacFarlane
src/Text/Pandoc/Readers/RST.hs+16−8
@@ -1029,22 +1029,29 @@ simpleTableFooter = try $ simpleTableSep '=' >> blanklines
1029
1029
1030-- Parse a raw line and split it into chunks by indices.
1030-- Parse a raw line and split it into chunks by indices.
1031simpleTableRawLine :: Monad m => [Int] -> RSTParser m [String]
1031simpleTableRawLine :: Monad m => [Int] -> RSTParser m [String]
1032−simpleTableRawLine indices = do
1032+simpleTableRawLine indices = simpleTableSplitLine indices <$> anyLine
1033− line <- many1Till anyChar newline
1033+
1034− return (simpleTableSplitLine indices line)
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
1035
1040
1036-- Parse a table row and return a list of blocks (columns).
1041-- Parse a table row and return a list of blocks (columns).
1037simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [Blocks]
1042simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [Blocks]
1038simpleTableRow indices = do
1043simpleTableRow indices = do
1039 notFollowedBy' simpleTableFooter
1044 notFollowedBy' simpleTableFooter
1040 firstLine <- simpleTableRawLine indices
1045 firstLine <- simpleTableRawLine indices
1041− colLines <- return [] -- TODO
1046+ conLines <- many $ simpleTableRawLineWithEmptyCell indices
1042− let cols = map unlines . transpose $ firstLine : colLines
1047+ let cols = map unlines . transpose $ firstLine : conLines ++
1048+ [replicate (length indices) ""
1049+ | not (null conLines)]
1043− mapM (parseFromString (mconcat <$> many plain)) cols
1050+ mapM (parseFromString parseBlocks) cols
1044
1051
1045simpleTableSplitLine :: [Int] -> String -> [String]
1052simpleTableSplitLine :: [Int] -> String -> [String]
1046simpleTableSplitLine indices line =
1053simpleTableSplitLine indices line =
1047− map trim
1054+ map trimr
1048 $ tail $ splitByIndices (init indices) line
1055 $ tail $ splitByIndices (init indices) line
1049
1056
1050simpleTableHeader :: PandocMonad m
1057simpleTableHeader :: PandocMonad m
@@ -1125,7 +1132,8 @@ hyphens = do
1125
1132
1126escapedChar :: Monad m => ParserT [Char] st m Inlines
1133escapedChar :: Monad m => ParserT [Char] st m Inlines
1127escapedChar = do c <- escaped anyChar
1134escapedChar = do c <- escaped anyChar
1135+ return $ if c == ' ' || c == '\n' || c == '\r'
1128− return $ if c == ' ' -- '\ ' is null in RST
1136+ -- '\ ' is null in RST
1129 then mempty
1137 then mempty
1130 else B.str [c]
1138 else B.str [c]
1131
1139
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+