git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Make one-column pipe tables work.

Closes #1218.

commit007eb96e06bc1fff12119addf2e03552ac992b2e authorJohn MacFarlane <jgm@berkeley.edu> dateThu 1 May 2014, 09:23 (13 years ago) parentb306405
3 files changed+35−7
src/Text/Pandoc/Readers/Markdown.hs+16−6 tests/pipe-tables.native+9−1 tests/pipe-tables.txt+10
src/Text/Pandoc/Readers/Markdown.hs+16−6
@@ -1221,11 +1221,20 @@ removeOneLeadingSpace xs =
12211221gridTableFooter :: MarkdownParser [Char]
12221222gridTableFooter = blanklines
12231223
1224+pipeBreak :: MarkdownParser [Alignment]
1225+pipeBreak = try $ do
1226+ nonindentSpaces
1227+ openPipe <- (True <$ char '|') <|> return False
1228+ first <- pipeTableHeaderPart
1229+ rest <- many $ sepPipe *> pipeTableHeaderPart
1230+ -- surrounding pipes needed for a one-column table:
1231+ guard $ not (null rest && not openPipe)
1232+ optional (char '|')
1233+ blankline
1234+ return (first:rest)
1235+
12241236pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
12251237pipeTable = try $ do
1226− let pipeBreak = nonindentSpaces *> optional (char '|') *>
1227− pipeTableHeaderPart `sepBy1` sepPipe <*
1228− optional (char '|') <* blankline
12291238 (heads,aligns) <- try ( pipeBreak >>= \als ->
12301239 return (return $ replicate (length als) mempty, als))
12311240 <|> ( pipeTableRow >>= \row -> pipeBreak >>= \als ->
@@ -1244,12 +1253,13 @@ sepPipe = try $ do
12441253pipeTableRow :: MarkdownParser (F [Blocks])
12451254pipeTableRow = do
12461255 nonindentSpaces
1247− optional (char '|')
1256+ openPipe <- (True <$ char '|') <|> return False
12481257 let cell = mconcat <$>
12491258 many (notFollowedBy (blankline <|> char '|') >> inline)
12501259 first <- cell
1251− sepPipe
1252− rest <- cell `sepBy1` sepPipe
1260+ rest <- many $ sepPipe *> cell
1261+ -- surrounding pipes needed for a one-column table:
1262+ guard $ not (null rest && not openPipe)
12531263 optional (char '|')
12541264 blankline
12551265 let cells = sequence (first:rest)
tests/pipe-tables.native+9−1
@@ -67,4 +67,12 @@
6767 ,[[Plain [Str "orange"]]
6868 ,[Plain [Str "17"]]]
6969 ,[[Plain [Str "pear"]]
70− ,[Plain [Str "302"]]]]]
70+ ,[Plain [Str "302"]]]]
71+,Para [Str "One-column:"]
72+,Table [] [AlignDefault] [0.0]
73+ [[Plain [Str "hi"]]]
74+ [[[Plain [Str "lo"]]]]
75+,Para [Str "Header-less",Space,Str "one-column:"]
76+,Table [] [AlignCenter] [0.0]
77+ [[]]
78+ [[[Plain [Str "hi"]]]]]
tests/pipe-tables.txt+10
@@ -40,3 +40,13 @@ apple | 5
4040orange| 17
4141pear | 302
4242
43+One-column:
44+
45+|hi|
46+|--|
47+|lo|
48+
49+Header-less one-column:
50+
51+|:-:|
52+|hi|