git.iko.soy/typeable/pandoc
on master help sign in
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.

commit38e35aaeda093cad8690fc4ef412655d7fbdb418 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 28 Mar 2013, 17:34 (14 years ago) parent186b4f0
1 file changed+14−11
src/Text/Pandoc/Writers/Markdown.hs+14−11
src/Text/Pandoc/Writers/Markdown.hs+14−11
@@ -352,23 +352,22 @@ blockToMarkdown opts t@(Table caption aligns widths headers rows) = do
352352 let isPlainBlock (Plain _) = True
353353 isPlainBlock _ = False
354354 let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
355− (nst,tbl) <- case isSimple of
356− True | isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
355+ (nst,tbl) <- case True of
356+ _ | isSimple &&
357+ isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
357358 pandocTable opts (all null headers) aligns widths
358359 rawHeaders rawRows
359− | isEnabled Ext_pipe_tables opts -> fmap (id,) $
360+ | isSimple &&
361+ isEnabled Ext_pipe_tables opts -> fmap (id,) $
360362 pipeTable (all null headers) aligns rawHeaders rawRows
361− | otherwise -> fmap (id,) $
362− return $ text $ writeHtmlString def
363− $ Pandoc (Meta [] [] []) [t]
364− False | not hasBlocks &&
365− isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
363+ | not hasBlocks &&
364+ isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
366365 pandocTable opts (all null headers) aligns widths
367366 rawHeaders rawRows
368− | isEnabled Ext_grid_tables opts -> fmap (id,) $
367+ | isEnabled Ext_grid_tables opts -> fmap (id,) $
369368 gridTable opts (all null headers) aligns widths
370369 rawHeaders rawRows
371− | otherwise -> fmap (id,) $
370+ | otherwise -> fmap (id,) $
372371 return $ text $ writeHtmlString def
373372 $ Pandoc (Meta [] [] []) [t]
374373 return $ nst $ tbl $$ blankline $$ caption'' $$ blankline
@@ -458,7 +457,11 @@ pandocTable opts headless aligns widths rawHeaders rawRows = do
458457gridTable :: WriterOptions -> Bool -> [Alignment] -> [Double]
459458 -> [Doc] -> [[Doc]] -> State WriterState Doc
460459gridTable opts headless _aligns widths headers' rawRows = do
461− let widthsInChars = map (floor . (fromIntegral (writerColumns opts) *)) widths
460+ let numcols = length headers'
461+ let widths' = if all (==0) widths
462+ then replicate numcols (1.0 / fromIntegral numcols)
463+ else widths
464+ let widthsInChars = map (floor . (fromIntegral (writerColumns opts) *)) widths'
462465 let hpipeBlocks blocks = hcat [beg, middle, end]
463466 where h = maximum (map height blocks)
464467 sep' = lblock 3 $ vcat (map text $ replicate h " | ")