Pipe tables: use full text width for tables with wrapping cells.

Previously we computed the column sizes based on the ratio
between the header lines and the text width (as set by `--columns`).
This meant that tables with very short header lines would be
very narrow. With this change, pipe tables with wrapping cells will
always take up the whole text width. The relative column widths
will still be determined by the ratio of header lines, but they
will be normalized to add up to 1.0.
This commit is contained in:
John MacFarlane 2017-12-12 15:16:16 -08:00
parent 7d23031b90
commit e86c337356
3 changed files with 7 additions and 4 deletions

View file

@ -2637,7 +2637,10 @@ and lists, and cannot span multiple lines. If a pipe table contains a
row whose printable content is wider than the column width (see
`--columns`), then the cell contents will wrap, with the
relative cell widths determined by the widths of the separator
lines.
lines. (In this case, the table will take up the full text
width.) If no lines are wider than column width, then
cell contents will not be wrapped, and the cells will be sized
to their contents.
Note: pandoc also recognizes pipe tables of the following
form, as can be produced by Emacs' orgtbl-mode:

View file

@ -1353,8 +1353,8 @@ pipeTable = try $ do
numColumns <- getOption readerColumns
let widths = if maxlength > numColumns
then map (\len ->
fromIntegral (len + 1) / fromIntegral numColumns)
seplengths
fromIntegral (len + 1) / fromIntegral (sum seplengths))
seplengths
else replicate (length aligns) 0.0
return (aligns, widths, heads', sequence lines'')

View file

@ -85,7 +85,7 @@
,[[Plain [Str "4"]]
,[Plain [Str "44"]]]]
,Para [Str "Long",Space,Str "pipe",Space,Str "table",Space,Str "with",Space,Str "relative",Space,Str "widths:"]
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.125,0.1375,0.5]
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.1639344262295082,0.18032786885245902,0.6557377049180328]
[[Plain [Str "Default1"]]
,[Plain [Str "Default2"]]
,[Plain [Str "Default3"]]]