git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: output tables as grid tables if they have multi-line cells
commitf393f4ba10a274ccffa164b75f03ae3a893fa2cc authorAlexander Krotov <ilabdsf@gmail.com> dateThu 15 Nov 2018, 12:14 (8 years ago) parent367e8ca
1 file changed+13−1
src/Text/Pandoc/Writers/Muse.hs+13−1
src/Text/Pandoc/Writers/Muse.hs+13−1
@@ -49,6 +49,7 @@ import Control.Monad.State.Strict
4949import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit, isSpace)
5050import Data.Default
5151import Data.List (intersperse, isInfixOf, transpose)
52+import Data.Monoid (Any (..))
5253import qualified Data.Set as Set
5354import Data.Text (Text)
5455import System.FilePath (takeExtension)
@@ -61,6 +62,7 @@ import Text.Pandoc.Shared
6162import Text.Pandoc.Templates (renderTemplate')
6263import Text.Pandoc.Writers.Math
6364import Text.Pandoc.Writers.Shared
65+import Text.Pandoc.Walk
6466
6567type Notes = [[Block]]
6668
@@ -276,7 +278,7 @@ blockToMuse (Header level (ident,_,_) inlines) = do
276278-- https://www.gnu.org/software/emacs-muse/manual/muse.html#Horizontal-Rules-and-Anchors
277279blockToMuse HorizontalRule = return $ blankline $$ "----" $$ blankline
278280blockToMuse (Table caption aligns widths headers rows) =
279− if all (== 0.0) widths && length widths > 1
281+ if isSimple && numcols > 1
280282 then simpleTable caption headers rows
281283 else do
282284 opts <- asks envOptions
@@ -284,6 +286,16 @@ blockToMuse (Table caption aligns widths headers rows) =
284286 where
285287 blocksToDoc opts blocks =
286288 local (\env -> env { envOptions = opts }) $ blockListToMuse blocks
289+ numcols = maximum (length aligns : length widths : map length (headers:rows))
290+ hasSimpleCells = all isSimpleCell (concat (headers:rows))
291+ isLineBreak LineBreak = Any True
292+ isLineBreak _ = Any False
293+ hasLineBreak = getAny . query isLineBreak
294+ isSimple = hasSimpleCells && all (== 0) widths
295+ isSimpleCell [Plain ils] = not (hasLineBreak ils)
296+ isSimpleCell [Para ils ] = not (hasLineBreak ils)
297+ isSimpleCell [] = True
298+ isSimpleCell _ = False
287299blockToMuse (Div _ bs) = flatBlockListToMuse bs
288300blockToMuse Null = return empty
289301