git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Make one-column pipe tables work.
007eb96John MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+16−6
@@ -1221,11 +1221,20 @@ removeOneLeadingSpace xs =
1221gridTableFooter :: MarkdownParser [Char]
1221gridTableFooter :: MarkdownParser [Char]
1222gridTableFooter = blanklines
1222gridTableFooter = blanklines
1223
1223
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+
1224pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
1236pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
1225pipeTable = try $ do
1237pipeTable = try $ do
1226− let pipeBreak = nonindentSpaces *> optional (char '|') *>
1227− pipeTableHeaderPart `sepBy1` sepPipe <*
1228− optional (char '|') <* blankline
1229 (heads,aligns) <- try ( pipeBreak >>= \als ->
1238 (heads,aligns) <- try ( pipeBreak >>= \als ->
1230 return (return $ replicate (length als) mempty, als))
1239 return (return $ replicate (length als) mempty, als))
1231 <|> ( pipeTableRow >>= \row -> pipeBreak >>= \als ->
1240 <|> ( pipeTableRow >>= \row -> pipeBreak >>= \als ->
@@ -1244,12 +1253,13 @@ sepPipe = try $ do
1244pipeTableRow :: MarkdownParser (F [Blocks])
1253pipeTableRow :: MarkdownParser (F [Blocks])
1245pipeTableRow = do
1254pipeTableRow = do
1246 nonindentSpaces
1255 nonindentSpaces
1247− optional (char '|')
1256+ openPipe <- (True <$ char '|') <|> return False
1248 let cell = mconcat <$>
1257 let cell = mconcat <$>
1249 many (notFollowedBy (blankline <|> char '|') >> inline)
1258 many (notFollowedBy (blankline <|> char '|') >> inline)
1250 first <- cell
1259 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)
1253 optional (char '|')
1263 optional (char '|')
1254 blankline
1264 blankline
1255 let cells = sequence (first:rest)
1265 let cells = sequence (first:rest)
tests/pipe-tables.native+9−1
@@ -67,4 +67,12 @@
67 ,[[Plain [Str "orange"]]
67 ,[[Plain [Str "orange"]]
68 ,[Plain [Str "17"]]]
68 ,[Plain [Str "17"]]]
69 ,[[Plain [Str "pear"]]
69 ,[[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
40orange| 17
40orange| 17
41pear | 302
41pear | 302
42
42
43+One-column:
44+
45+|hi|
46+|--|
47+|lo|
48+
49+Header-less one-column:
50+
51+|:-:|
52+|hi|