Muse writer: output tables as grid tables if they have multi-line cells
This commit is contained in:
parent
367e8cac18
commit
f393f4ba10
1 changed files with 13 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue