git.iko.soy/typeable/pandoc
on master help sign in
Allow simple tables to be printed as grid tables.
38e35aaJohn MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+14−11
@@ -352,23 +352,22 @@ blockToMarkdown opts t@(Table caption aligns widths headers rows) = do
352 let isPlainBlock (Plain _) = True
352 let isPlainBlock (Plain _) = True
353 isPlainBlock _ = False
353 isPlainBlock _ = False
354 let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
354 let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
355− (nst,tbl) <- case isSimple of
355+ (nst,tbl) <- case True of
356+ _ | isSimple &&
356− True | isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
357+ isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
357 pandocTable opts (all null headers) aligns widths
358 pandocTable opts (all null headers) aligns widths
358 rawHeaders rawRows
359 rawHeaders rawRows
360+ | isSimple &&
359− | isEnabled Ext_pipe_tables opts -> fmap (id,) $
361+ isEnabled Ext_pipe_tables opts -> fmap (id,) $
360 pipeTable (all null headers) aligns rawHeaders rawRows
362 pipeTable (all null headers) aligns rawHeaders rawRows
361− | otherwise -> fmap (id,) $
362− return $ text $ writeHtmlString def
363− $ Pandoc (Meta [] [] []) [t]
364− False | not hasBlocks &&
363+ | not hasBlocks &&
365− isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
364+ isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
366 pandocTable opts (all null headers) aligns widths
365 pandocTable opts (all null headers) aligns widths
367 rawHeaders rawRows
366 rawHeaders rawRows
368− | isEnabled Ext_grid_tables opts -> fmap (id,) $
367+ | isEnabled Ext_grid_tables opts -> fmap (id,) $
369 gridTable opts (all null headers) aligns widths
368 gridTable opts (all null headers) aligns widths
370 rawHeaders rawRows
369 rawHeaders rawRows
371− | otherwise -> fmap (id,) $
370+ | otherwise -> fmap (id,) $
372 return $ text $ writeHtmlString def
371 return $ text $ writeHtmlString def
373 $ Pandoc (Meta [] [] []) [t]
372 $ Pandoc (Meta [] [] []) [t]
374 return $ nst $ tbl $$ blankline $$ caption'' $$ blankline
373 return $ nst $ tbl $$ blankline $$ caption'' $$ blankline
@@ -458,7 +457,11 @@ pandocTable opts headless aligns widths rawHeaders rawRows = do
458gridTable :: WriterOptions -> Bool -> [Alignment] -> [Double]
457gridTable :: WriterOptions -> Bool -> [Alignment] -> [Double]
459 -> [Doc] -> [[Doc]] -> State WriterState Doc
458 -> [Doc] -> [[Doc]] -> State WriterState Doc
460gridTable opts headless _aligns widths headers' rawRows = do
459gridTable opts headless _aligns widths headers' rawRows = do
460+ let numcols = length headers'
461+ let widths' = if all (==0) widths
462+ then replicate numcols (1.0 / fromIntegral numcols)
463+ else widths
461− let widthsInChars = map (floor . (fromIntegral (writerColumns opts) *)) widths
464+ let widthsInChars = map (floor . (fromIntegral (writerColumns opts) *)) widths'
462 let hpipeBlocks blocks = hcat [beg, middle, end]
465 let hpipeBlocks blocks = hcat [beg, middle, end]
463 where h = maximum (map height blocks)
466 where h = maximum (map height blocks)
464 sep' = lblock 3 $ vcat (map text $ replicate h " | ")
467 sep' = lblock 3 $ vcat (map text $ replicate h " | ")