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.
This commit is contained in:
John MacFarlane 2015-03-07 10:40:13 -08:00
parent 62e802ae1e
commit 48eaadc57f
4 changed files with 14 additions and 9 deletions

4
README
View file

@ -1827,8 +1827,8 @@ Pipe tables look like this:
The syntax is [the same as in PHP markdown extra]. The beginning and
ending pipe characters are optional, but pipes are required between all
columns. The colons indicate column alignment as shown. The header
can be omitted, but the horizontal line must still be included, as
it defines column alignments.
cannot be omitted. To simulate a headerless table, include a header
with blank cells.
Since the pipes indicate column boundaries, columns need not be vertically
aligned, as they are in the above example. So, this is a perfectly

View file

@ -1287,11 +1287,9 @@ pipeBreak = try $ do
pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
pipeTable = try $ do
(heads,aligns) <- try ( pipeBreak >>= \als ->
return (return $ replicate (length als) mempty, als))
<|> ( pipeTableRow >>= \row -> pipeBreak >>= \als ->
return (row, als) )
(heads,aligns) <- pipeTableRow >>= \row ->
pipeBreak >>= \als ->
return (row, als)
lines' <- sequence <$> many1 pipeTableRow
let widths = replicate (length aligns) 0.0
return $ (aligns, widths, heads, lines')

View file

@ -508,7 +508,12 @@ pipeTable headless aligns rawHeaders rawRows = do
AlignCenter -> ':':replicate w '-' ++ ":"
AlignRight -> replicate (w + 1) '-' ++ ":"
AlignDefault -> replicate (w + 2) '-'
let header = if headless then empty else torow rawHeaders
-- note: pipe tables can't completely lack a
-- header; for a headerless table, we need a header of empty cells.
-- see jgm/pandoc#1996.
let header = if headless
then torow (replicate (length aligns) empty)
else torow rawHeaders
let border = nowrap $ text "|" <> hcat (intersperse (text "|") $
map toborder $ zip aligns widths) <> text "|"
let body = vcat $ map torow rawRows

View file

@ -1,7 +1,7 @@
Simplest table without caption:
| Default1 | Default2 | Default3 |
|----------|----------|----------|
|----------|----------|----------|
|12|12|12|
|123|123|123|
|1|1|1|
@ -27,6 +27,7 @@ Simple table without caption:
Headerless table without caption:
| | | |
|------:|:-----|:------:|
|12|12|12|
|123|123|123|
@ -48,5 +49,6 @@ One-column:
Header-less one-column:
| |
|:-:|
|hi|