aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-01 17:08:14 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-01 17:08:14 +0100
commit8b641f38ca3f0392bd3da5a084d025265ed3e50b (patch)
treeb233960a4facf738b583b5604ac485952afa4967 /src
parent8af838f98f1f104107f1d248053dad5a157d55f5 (diff)
downloadpandoc-8b641f38ca3f0392bd3da5a084d025265ed3e50b.tar.gz
Markdown writer: Refactored gridTable to use widths in chars.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 2cf64537f..d7527e044 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -537,8 +537,16 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
isEnabled Ext_multiline_tables opts -> fmap (nest 2,) $
pandocTable opts (all null headers) aligns widths
rawHeaders rawRows
- | isEnabled Ext_grid_tables opts -> fmap (id,) $
- gridTable opts (all null headers) aligns widths
+ | isEnabled Ext_grid_tables opts -> do
+ let numcols = length headers
+ let widths' = if all (==0) widths
+ then replicate numcols
+ (1.0 / fromIntegral numcols)
+ else widths
+ let widthsInChars = map ((\x -> x - 3) . floor .
+ (fromIntegral (writerColumns opts) *)) widths'
+ fmap (id,) $
+ gridTable (all null headers) aligns widthsInChars
rawHeaders rawRows
| isEnabled Ext_raw_html opts -> fmap (id,) $
text <$>
@@ -657,15 +665,9 @@ pandocTable opts headless aligns widths rawHeaders rawRows = do
else border
return $ head'' $$ underline $$ body $$ bottom
-gridTable :: PandocMonad m => WriterOptions -> Bool -> [Alignment] -> [Double]
+gridTable :: PandocMonad m => Bool -> [Alignment] -> [Int]
-> [Doc] -> [[Doc]] -> MD m Doc
-gridTable opts headless aligns widths headers' rawRows = do
- let numcols = length headers'
- let widths' = if all (==0) widths
- then replicate numcols (1.0 / fromIntegral numcols)
- else widths
- let widthsInChars = map
- ((\x -> x - 3) . floor . (fromIntegral (writerColumns opts) *)) widths'
+gridTable headless aligns widthsInChars headers' rawRows = do
let hpipeBlocks blocks = hcat [beg, middle, end]
where h = maximum (1 : map height blocks)
sep' = lblock 3 $ vcat (map text $ replicate h " | ")