aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-04-21 13:06:57 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-04-21 13:06:57 -0700
commit7fbe473b2e3b3b2b94be810b6385475c056a304a (patch)
tree324f44cf3d2f281f38d243f89836e33f8d3197eb /src/Text/Pandoc
parent229db80ac23ab0b5dba396d7748fcba0d05c4785 (diff)
downloadpandoc-7fbe473b2e3b3b2b94be810b6385475c056a304a.tar.gz
Markdown reader/writer: spacing adjustments in tables.
* Markdown writer now includes a blank line at the end of the row in a single-row multiline table, to prevent it from being interpreted as a simple table. Closes #4578. * Markdown reader does a better job computing the relative width of the last column in a multiline table, so we can round-trip tables without constantly shrinking the last column.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs11
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs5
2 files changed, 12 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 0d1a83bab..156b2b622 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1341,11 +1341,16 @@ multilineTableHeader headless = try $ do
newline
let (lengths, lines') = unzip dashes
let indices = scanl (+) (length initSp) lines'
+ -- compensate for the fact that intercolumn spaces are
+ -- not included in the last index:
+ let indices' = case reverse indices of
+ [] -> []
+ (x:xs) -> reverse (x+1:xs)
rawHeadsList <- if headless
then fmap (map (:[]) . tail .
- splitStringByIndices (init indices)) $ lookAhead anyLine
+ splitStringByIndices (init indices')) $ lookAhead anyLine
else return $ transpose $ map
- (tail . splitStringByIndices (init indices))
+ (tail . splitStringByIndices (init indices'))
rawContent
let aligns = zipWith alignType rawHeadsList lengths
let rawHeads = if headless
@@ -1353,7 +1358,7 @@ multilineTableHeader headless = try $ do
else map (unlines . map trim) rawHeadsList
heads <- fmap sequence $
mapM ((parseFromString' (mconcat <$> many plain)).trim) rawHeads
- return (heads, aligns, indices)
+ return (heads, aligns, indices')
-- Parse a grid table: starts with row of '-' on top, then header
-- (which may be grid), then the rows,
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 3bfa8a012..075858e5e 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -732,7 +732,10 @@ pandocTable opts multiline headless aligns widths rawHeaders rawRows = do
then empty
else border <> cr <> head'
let body = if multiline
- then vsep rows'
+ then vsep rows' $$
+ if length rows' < 2
+ then blankline -- #4578
+ else empty
else vcat rows'
let bottom = if headless
then underline