summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-03-28 17:34:54 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2013-03-28 17:34:54 -0700
commit38e35aaeda093cad8690fc4ef412655d7fbdb418 (patch)
tree8de5ca8d146e679baa95c4e3deed193937934350 /src/Text/Pandoc/Writers
parent186b4f01000c58f3f95b268e4775f20f3e8e55e8 (diff)
Allow simple tables to be printed as grid tables.
if other table options are disabled. This means you can do pandoc -t markdown-pipe_tables-simple_tables-multiline_tables and all tables will render as grid tables.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index f09cb3eec..f0d3fc0af 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -352,23 +352,22 @@ blockToMarkdown opts t@(Table caption aligns widths headers rows) = do
let isPlainBlock (Plain _) = True
isPlainBlock _ = False
let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
- (nst,tbl) <- case isSimple of
- True | isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
+ (nst,tbl) <- case True of
+ _ | isSimple &&
+ isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
pandocTable opts (all null headers) aligns widths
rawHeaders rawRows
- | isEnabled Ext_pipe_tables opts -> fmap (id,) $
+ | isSimple &&
+ isEnabled Ext_pipe_tables opts -> fmap (id,) $
pipeTable (all null headers) aligns rawHeaders rawRows
- | otherwise -> fmap (id,) $
- return $ text $ writeHtmlString def
- $ Pandoc (Meta [] [] []) [t]
- False | not hasBlocks &&
- isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
+ | not hasBlocks &&
+ isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
pandocTable opts (all null headers) aligns widths
rawHeaders rawRows
- | isEnabled Ext_grid_tables opts -> fmap (id,) $
+ | isEnabled Ext_grid_tables opts -> fmap (id,) $
gridTable opts (all null headers) aligns widths
rawHeaders rawRows
- | otherwise -> fmap (id,) $
+ | otherwise -> fmap (id,) $
return $ text $ writeHtmlString def
$ Pandoc (Meta [] [] []) [t]
return $ nst $ tbl $$ blankline $$ caption'' $$ blankline
@@ -458,7 +457,11 @@ pandocTable opts headless aligns widths rawHeaders rawRows = do
gridTable :: WriterOptions -> Bool -> [Alignment] -> [Double]
-> [Doc] -> [[Doc]] -> State WriterState Doc
gridTable opts headless _aligns widths headers' rawRows = do
- let widthsInChars = map (floor . (fromIntegral (writerColumns opts) *)) widths
+ let numcols = length headers'
+ let widths' = if all (==0) widths
+ then replicate numcols (1.0 / fromIntegral numcols)
+ else widths
+ let widthsInChars = map (floor . (fromIntegral (writerColumns opts) *)) widths'
let hpipeBlocks blocks = hcat [beg, middle, end]
where h = maximum (map height blocks)
sep' = lblock 3 $ vcat (map text $ replicate h " | ")