@@ -349,6 +349,9 @@ blockToMarkdown opts t@(Table caption aligns widths headers rows) = do
349349 rawHeaders <- mapM (blockListToMarkdown opts) headers
350350 rawRows <- mapM (mapM (blockListToMarkdown opts)) rows
351351 let isSimple = all (==0) widths
352+ let isPlainBlock (Plain _) = True
353+ isPlainBlock _ = False
354+ let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
352355 (nst,tbl) <- case isSimple of
353356 True | isEnabled Ext_simple_tables opts -> fmap (nest 2,) $
354357 pandocTable opts (all null headers) aligns widths
@@ -358,9 +361,13 @@ blockToMarkdown opts t@(Table caption aligns widths headers rows) = do
358361 | otherwise -> fmap (id,) $
359362 return $ text $ writeHtmlString def
360363 $ Pandoc (Meta [] [] []) [t]
361− False | isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
364+ False | not hasBlocks &&
365+ isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
362366 pandocTable opts (all null headers) aligns widths
363367 rawHeaders rawRows
368+ | isEnabled Ext_grid_tables opts -> fmap (id,) $
369+ gridTable opts (all null headers) aligns widths
370+ rawHeaders rawRows
364371 | otherwise -> fmap (id,) $
365372 return $ text $ writeHtmlString def
366373 $ Pandoc (Meta [] [] []) [t]
@@ -448,6 +455,29 @@ pandocTable opts headless aligns widths rawHeaders rawRows = do
448455 else border
449456 return $ head'' $$ underline $$ body $$ bottom
450457
458+gridTable :: WriterOptions -> Bool -> [Alignment] -> [Double]
459+ -> [Doc] -> [[Doc]] -> State WriterState Doc
460+gridTable opts headless _aligns widths headers' rawRows = do
461+ let widthsInChars = map (floor . (fromIntegral (writerColumns opts) *)) widths
462+ let hpipeBlocks blocks = hcat [beg, middle, end]
463+ where h = maximum (map height blocks)
464+ sep' = lblock 3 $ vcat (map text $ replicate h " | ")
465+ beg = lblock 2 $ vcat (map text $ replicate h "| ")
466+ end = lblock 2 $ vcat (map text $ replicate h " |")
467+ middle = chomp $ hcat $ intersperse sep' blocks
468+ let makeRow = hpipeBlocks . zipWith lblock widthsInChars
469+ let head' = makeRow headers'
470+ let rows' = map (makeRow . map chomp) rawRows
471+ let border ch = char '+' <> char ch <>
472+ (hcat $ intersperse (char ch <> char '+' <> char ch) $
473+ map (\l -> text $ replicate l ch) widthsInChars) <>
474+ char ch <> char '+'
475+ let body = vcat $ intersperse (border '-') rows'
476+ let head'' = if headless
477+ then empty
478+ else head' $$ border '='
479+ return $ border '-' $$ head'' $$ body $$ border '-'
480+
451481-- | Convert bullet list item (list of blocks) to markdown.
452482bulletListItemToMarkdown :: WriterOptions -> [Block] -> State WriterState Doc
453483bulletListItemToMarkdown opts items = do