From a939cfe769408ec41aee7ebe5ce4d36f5160d7d1 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Thu, 23 Mar 2017 16:54:24 +0100 Subject: [PATCH] Pipe tables: impose minimum cell size. This might help with #3526. At any rate, it fixes another bug (see test/command/3526.md). --- src/Text/Pandoc/Writers/Shared.hs | 12 +++++++----- test/command/3526.md | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/command/3526.md diff --git a/src/Text/Pandoc/Writers/Shared.hs b/src/Text/Pandoc/Writers/Shared.hs index 7e08724d8..615733a78 100644 --- a/src/Text/Pandoc/Writers/Shared.hs +++ b/src/Text/Pandoc/Writers/Shared.hs @@ -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) diff --git a/test/command/3526.md b/test/command/3526.md new file mode 100644 index 000000000..e197bcf32 --- /dev/null +++ b/test/command/3526.md @@ -0,0 +1,14 @@ +``` +% pandoc -t rst ++--+---+ +| | | ++--+---+ +| | | ++--+---+ +^D ++---+---+ +| | | ++---+---+ +| | | ++---+---+ +```