aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-12-12 15:16:16 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2017-12-12 15:16:16 -0800
commite86c337356fc723e366e5f0d6209205bcffe88f3 (patch)
tree69b956db208aa9f687d8d6582ce08b00214f3e08
parent7d23031b904d9371de8ce9ffe943e426bd5056c8 (diff)
downloadpandoc-e86c337356fc723e366e5f0d6209205bcffe88f3.tar.gz
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.
-rw-r--r--MANUAL.txt5
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs4
-rw-r--r--test/pipe-tables.native2
3 files changed, 7 insertions, 4 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 29fc629cd..9fd0e3381 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -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:
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 2d7c12e99..b97a724a4 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -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'')
diff --git a/test/pipe-tables.native b/test/pipe-tables.native
index 63c2c17bc..6e39dc475 100644
--- a/test/pipe-tables.native
+++ b/test/pipe-tables.native
@@ -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"]]]