aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-10-25 18:35:02 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-10-25 18:35:02 +0300
commit07fc8501726563d32b57fa5740e90dec17f8f4a8 (patch)
treec1a92e3f8631987595a5a0d111633b7ccfd565ad /src
parent02e515cada735d83a870404c6c51ef15a9beef37 (diff)
downloadpandoc-07fc8501726563d32b57fa5740e90dec17f8f4a8.tar.gz
Muse writer: add support for grid tables
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Muse.hs58
1 files changed, 35 insertions, 23 deletions
diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs
index ceae14c16..408215602 100644
--- a/src/Text/Pandoc/Writers/Muse.hs
+++ b/src/Text/Pandoc/Writers/Muse.hs
@@ -163,6 +163,32 @@ flatBlockListToMuse bs@(DefinitionList _ : DefinitionList _ : _) = catWithBlankL
flatBlockListToMuse bs@(_ : _) = catWithBlankLines bs 0
flatBlockListToMuse [] = return mempty
+simpleTable :: PandocMonad m
+ => [Inline]
+ -> [TableCell]
+ -> [[TableCell]]
+ -> Muse m Doc
+simpleTable caption headers rows = do
+ caption' <- inlineListToMuse caption
+ headers' <- mapM blockListToMuse headers
+ rows' <- mapM (mapM blockListToMuse) rows
+ let noHeaders = all null headers
+ let numChars = maximum . map offset
+ let widthsInChars =
+ map numChars $ transpose (headers' : rows')
+ let hpipeBlocks sep blocks = hcat $ intersperse sep' blocks
+ where h = maximum (1 : map height blocks)
+ sep' = lblock (length sep) $ vcat (replicate h (text sep))
+ let makeRow sep = (" " <>) . hpipeBlocks sep . zipWith lblock widthsInChars
+ let head' = makeRow " || " headers'
+ let rowSeparator = if noHeaders then " | " else " | "
+ rows'' <- mapM (\row -> makeRow rowSeparator <$> mapM blockListToMuse row) rows
+ let body = vcat rows''
+ return $ (if noHeaders then empty else head')
+ $$ body
+ $$ (if null caption then empty else " |+ " <> caption' <> " +|")
+ $$ blankline
+
-- | Convert list of Pandoc block elements to Muse.
blockListToMuse :: PandocMonad m
=> [Block] -- ^ List of block elements
@@ -252,29 +278,15 @@ blockToMuse (Header level (ident,_,_) inlines) = do
return $ blankline <> attr' $$ nowrap (header' <> contents) <> blankline
-- https://www.gnu.org/software/emacs-muse/manual/muse.html#Horizontal-Rules-and-Anchors
blockToMuse HorizontalRule = return $ blankline $$ "----" $$ blankline
-blockToMuse (Table caption _ _ headers rows) = do
- caption' <- inlineListToMuse caption
- headers' <- mapM blockListToMuse headers
- rows' <- mapM (mapM blockListToMuse) rows
- let noHeaders = all null headers
-
- let numChars = maximum . map offset
- -- FIXME: width is not being used.
- let widthsInChars =
- map numChars $ transpose (headers' : rows')
- -- FIXME: Muse doesn't allow blocks with height more than 1.
- let hpipeBlocks sep blocks = hcat $ intersperse sep' blocks
- where h = maximum (1 : map height blocks)
- sep' = lblock (length sep) $ vcat (replicate h (text sep))
- let makeRow sep = (" " <>) . hpipeBlocks sep . zipWith lblock widthsInChars
- let head' = makeRow " || " headers'
- let rowSeparator = if noHeaders then " | " else " | "
- rows'' <- mapM (\row -> makeRow rowSeparator <$> mapM blockListToMuse row) rows
- let body = vcat rows''
- return $ (if noHeaders then empty else head')
- $$ body
- $$ (if null caption then empty else " |+ " <> caption' <> " +|")
- $$ blankline
+blockToMuse (Table caption aligns widths headers rows) =
+ if all (== 0.0) widths
+ then simpleTable caption headers rows
+ else do
+ opts <- asks envOptions
+ gridTable opts blocksToDoc True (map (const AlignDefault) aligns) widths headers rows
+ where
+ blocksToDoc opts blocks =
+ local (\env -> env { envOptions = opts }) $ blockListToMuse blocks
blockToMuse (Div _ bs) = flatBlockListToMuse bs
blockToMuse Null = return empty