diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2018-11-15 12:14:08 +0300 |
---|---|---|
committer | Alexander Krotov <ilabdsf@gmail.com> | 2018-11-15 12:14:08 +0300 |
commit | f393f4ba10a274ccffa164b75f03ae3a893fa2cc (patch) | |
tree | a146f09a7645fb3cc5540405790359a8b179588f | |
parent | 367e8cac18924f8cd9898f84f25c56bd2ae3b744 (diff) | |
download | pandoc-f393f4ba10a274ccffa164b75f03ae3a893fa2cc.tar.gz |
Muse writer: output tables as grid tables if they have multi-line cells
-rw-r--r-- | src/Text/Pandoc/Writers/Muse.hs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index 005909ac1..fd72256b2 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -49,6 +49,7 @@ import Control.Monad.State.Strict import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit, isSpace) import Data.Default import Data.List (intersperse, isInfixOf, transpose) +import Data.Monoid (Any (..)) import qualified Data.Set as Set import Data.Text (Text) import System.FilePath (takeExtension) @@ -61,6 +62,7 @@ import Text.Pandoc.Shared import Text.Pandoc.Templates (renderTemplate') import Text.Pandoc.Writers.Math import Text.Pandoc.Writers.Shared +import Text.Pandoc.Walk type Notes = [[Block]] @@ -276,7 +278,7 @@ blockToMuse (Header level (ident,_,_) inlines) = do -- https://www.gnu.org/software/emacs-muse/manual/muse.html#Horizontal-Rules-and-Anchors blockToMuse HorizontalRule = return $ blankline $$ "----" $$ blankline blockToMuse (Table caption aligns widths headers rows) = - if all (== 0.0) widths && length widths > 1 + if isSimple && numcols > 1 then simpleTable caption headers rows else do opts <- asks envOptions @@ -284,6 +286,16 @@ blockToMuse (Table caption aligns widths headers rows) = where blocksToDoc opts blocks = local (\env -> env { envOptions = opts }) $ blockListToMuse blocks + numcols = maximum (length aligns : length widths : map length (headers:rows)) + hasSimpleCells = all isSimpleCell (concat (headers:rows)) + isLineBreak LineBreak = Any True + isLineBreak _ = Any False + hasLineBreak = getAny . query isLineBreak + isSimple = hasSimpleCells && all (== 0) widths + isSimpleCell [Plain ils] = not (hasLineBreak ils) + isSimpleCell [Para ils ] = not (hasLineBreak ils) + isSimpleCell [] = True + isSimpleCell _ = False blockToMuse (Div _ bs) = flatBlockListToMuse bs blockToMuse Null = return empty |