git.iko.soy/typeable/pandoc
on master help sign in
Fixed pipe tables -- headerless tables are not allowed.

GFM and PHP Markdown Extra pipe tables require headers. Previously pandoc allowed pipe tables not to include headers, and produced headerless pipe tables in Markdown output, but this was based on a misconception about pipe table syntax. This commit fixes this. Note: If you have been using headerless pipe tables, this may cause existing tables to break. Closes #1996.

commit48eaadc57ff45bb44efe9c8da85a1c792c03dc77 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 7 Mar 2015, 10:40 (12 years ago) parent62e802a
4 files changed+14−9
README+2−2 src/Text/Pandoc/Readers/Markdown.hs+3−5 src/Text/Pandoc/Writers/Markdown.hs+6−1 tests/pipe-tables.txt+3−1
README+2−2
@@ -1827,8 +1827,8 @@ Pipe tables look like this:
18271827The syntax is [the same as in PHP markdown extra]. The beginning and
18281828ending pipe characters are optional, but pipes are required between all
18291829columns. The colons indicate column alignment as shown. The header
1830−can be omitted, but the horizontal line must still be included, as
1831−it defines column alignments.
1830+cannot be omitted. To simulate a headerless table, include a header
1831+with blank cells.
18321832
18331833Since the pipes indicate column boundaries, columns need not be vertically
18341834aligned, as they are in the above example. So, this is a perfectly
src/Text/Pandoc/Readers/Markdown.hs+3−5
@@ -1287,11 +1287,9 @@ pipeBreak = try $ do
12871287
12881288pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
12891289pipeTable = try $ do
1290− (heads,aligns) <- try ( pipeBreak >>= \als ->
1291− return (return $ replicate (length als) mempty, als))
1292− <|> ( pipeTableRow >>= \row -> pipeBreak >>= \als ->
1293−
1294− return (row, als) )
1290+ (heads,aligns) <- pipeTableRow >>= \row ->
1291+ pipeBreak >>= \als ->
1292+ return (row, als)
12951293 lines' <- sequence <$> many1 pipeTableRow
12961294 let widths = replicate (length aligns) 0.0
12971295 return $ (aligns, widths, heads, lines')
src/Text/Pandoc/Writers/Markdown.hs+6−1
@@ -508,7 +508,12 @@ pipeTable headless aligns rawHeaders rawRows = do
508508 AlignCenter -> ':':replicate w '-' ++ ":"
509509 AlignRight -> replicate (w + 1) '-' ++ ":"
510510 AlignDefault -> replicate (w + 2) '-'
511− let header = if headless then empty else torow rawHeaders
511+ -- note: pipe tables can't completely lack a
512+ -- header; for a headerless table, we need a header of empty cells.
513+ -- see jgm/pandoc#1996.
514+ let header = if headless
515+ then torow (replicate (length aligns) empty)
516+ else torow rawHeaders
512517 let border = nowrap $ text "|" <> hcat (intersperse (text "|") $
513518 map toborder $ zip aligns widths) <> text "|"
514519 let body = vcat $ map torow rawRows
tests/pipe-tables.txt+3−1
@@ -1,7 +1,7 @@
11Simplest table without caption:
22
33| Default1 | Default2 | Default3 |
4−|----------|----------|----------|
4+ |----------|----------|----------|
55|12|12|12|
66|123|123|123|
77|1|1|1|
@@ -27,6 +27,7 @@ Simple table without caption:
2727
2828Headerless table without caption:
2929
30+| | | |
3031|------:|:-----|:------:|
3132|12|12|12|
3233|123|123|123|
@@ -48,5 +49,6 @@ One-column:
4849
4950Header-less one-column:
5051
52+| |
5153|:-:|
5254|hi|