Pipe tables: impose minimum cell size.

This might help with #3526.
At any rate, it fixes another bug (see test/command/3526.md).
This commit is contained in:
John MacFarlane 2017-03-23 16:54:24 +01:00
parent e92941a9ca
commit a939cfe769
2 changed files with 21 additions and 5 deletions

View file

@ -230,8 +230,11 @@ gridTable opts blocksToDoc headless aligns widths headers rows = do
let numcols = maximum (length aligns : length widths :
map length (headers:rows))
let handleGivenWidths widths' = do
let widthsInChars' = map ((\x -> x - 3) . floor .
(fromIntegral (writerColumns opts) *)) widths'
let widthsInChars' = map (
(\x -> if x < 1 then 1 else x) .
(\x -> x - 3) . floor .
(fromIntegral (writerColumns opts) *)
) widths'
rawHeaders' <- zipWithM blocksToDoc
(map (\w -> opts{writerColumns =
min (w - 2) (writerColumns opts)}) widthsInChars')
@ -268,11 +271,10 @@ gridTable opts blocksToDoc headless aligns widths headers rows = do
let head' = makeRow rawHeaders
let rows' = map (makeRow . map chomp) rawRows
let borderpart ch align widthInChars =
let widthInChars' = if widthInChars < 1 then 1 else widthInChars
in (if (align == AlignLeft || align == AlignCenter)
(if (align == AlignLeft || align == AlignCenter)
then char ':'
else char ch) <>
text (replicate widthInChars' ch) <>
text (replicate widthInChars ch) <>
(if (align == AlignRight || align == AlignCenter)
then char ':'
else char ch)

14
test/command/3526.md Normal file
View file

@ -0,0 +1,14 @@
```
% pandoc -t rst
+--+---+
| | |
+--+---+
| | |
+--+---+
^D
+---+---+
| | |
+---+---+
| | |
+---+---+
```