git.iko.soy/typeable/pandoc
on master help sign in
Fixed pipe tables -- headerless tables are not allowed.
48eaadcJohn MacFarlane
README+2−2
@@ -1827,8 +1827,8 @@ Pipe tables look like this:
1827The syntax is [the same as in PHP markdown extra]. The beginning and
1827The syntax is [the same as in PHP markdown extra]. The beginning and
1828ending pipe characters are optional, but pipes are required between all
1828ending pipe characters are optional, but pipes are required between all
1829columns. The colons indicate column alignment as shown. The header
1829columns. The colons indicate column alignment as shown. The header
1830−can be omitted, but the horizontal line must still be included, as
1830+cannot be omitted. To simulate a headerless table, include a header
1831−it defines column alignments.
1831+with blank cells.
1832
1832
1833Since the pipes indicate column boundaries, columns need not be vertically
1833Since the pipes indicate column boundaries, columns need not be vertically
1834aligned, as they are in the above example. So, this is a perfectly
1834aligned, 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
1287
1287
1288pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
1288pipeTable :: MarkdownParser ([Alignment], [Double], F [Blocks], F [[Blocks]])
1289pipeTable = try $ do
1289pipeTable = try $ do
1290− (heads,aligns) <- try ( pipeBreak >>= \als ->
1290+ (heads,aligns) <- pipeTableRow >>= \row ->
1291− return (return $ replicate (length als) mempty, als))
1292− <|> ( pipeTableRow >>= \row -> pipeBreak >>= \als ->
1291+ pipeBreak >>= \als ->
1293−
1294− return (row, als) )
1292+ return (row, als)
1295 lines' <- sequence <$> many1 pipeTableRow
1293 lines' <- sequence <$> many1 pipeTableRow
1296 let widths = replicate (length aligns) 0.0
1294 let widths = replicate (length aligns) 0.0
1297 return $ (aligns, widths, heads, lines')
1295 return $ (aligns, widths, heads, lines')
src/Text/Pandoc/Writers/Markdown.hs+6−1
@@ -508,7 +508,12 @@ pipeTable headless aligns rawHeaders rawRows = do
508 AlignCenter -> ':':replicate w '-' ++ ":"
508 AlignCenter -> ':':replicate w '-' ++ ":"
509 AlignRight -> replicate (w + 1) '-' ++ ":"
509 AlignRight -> replicate (w + 1) '-' ++ ":"
510 AlignDefault -> replicate (w + 2) '-'
510 AlignDefault -> replicate (w + 2) '-'
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.
511− let header = if headless then empty else torow rawHeaders
514+ let header = if headless
515+ then torow (replicate (length aligns) empty)
516+ else torow rawHeaders
512 let border = nowrap $ text "|" <> hcat (intersperse (text "|") $
517 let border = nowrap $ text "|" <> hcat (intersperse (text "|") $
513 map toborder $ zip aligns widths) <> text "|"
518 map toborder $ zip aligns widths) <> text "|"
514 let body = vcat $ map torow rawRows
519 let body = vcat $ map torow rawRows
tests/pipe-tables.txt+3−1
@@ -1,7 +1,7 @@
1Simplest table without caption:
1Simplest table without caption:
2
2
3| Default1 | Default2 | Default3 |
3| Default1 | Default2 | Default3 |
4−|----------|----------|----------|
4+ |----------|----------|----------|
5|12|12|12|
5|12|12|12|
6|123|123|123|
6|123|123|123|
7|1|1|1|
7|1|1|1|
@@ -27,6 +27,7 @@ Simple table without caption:
27
27
28Headerless table without caption:
28Headerless table without caption:
29
29
30+| | | |
30|------:|:-----|:------:|
31|------:|:-----|:------:|
31|12|12|12|
32|12|12|12|
32|123|123|123|
33|123|123|123|
@@ -48,5 +49,6 @@ One-column:
48
49
49Header-less one-column:
50Header-less one-column:
50
51
52+| |
51|:-:|
53|:-:|
52|hi|
54|hi|