From 5f7eaaf89372be5d2d853546affe3a995e3f18e6 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Wed, 24 Oct 2018 11:21:10 +0300 Subject: Muse reader: simplify museToPandocTable to get rid of partial functions (head, tail, maximum) --- src/Text/Pandoc/Readers/Muse.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 88c78d450..818f66e20 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -45,7 +45,7 @@ import Control.Monad.Reader import Control.Monad.Except (throwError) import Data.Bifunctor import Data.Default -import Data.List (intercalate, transpose) +import Data.List (intercalate, transpose, uncons) import Data.List.Split (splitOn) import qualified Data.Map as M import qualified Data.Set as Set @@ -640,11 +640,9 @@ data MuseTableElement = MuseHeaderRow [Blocks] museToPandocTable :: MuseTable -> Blocks museToPandocTable (MuseTable caption headers body footers) = - B.table caption attrs headRow rows - where ncol = maximum (0 : map length (headers ++ body ++ footers)) - attrs = replicate ncol (AlignDefault, 0.0) - headRow = if null headers then [] else head headers - rows = (if null headers then [] else tail headers) ++ body ++ footers + B.table caption attrs headRow (rows ++ body ++ footers) + where attrs = const (AlignDefault, 0.0) <$> transpose (headers ++ body ++ footers) + (headRow, rows) = fromMaybe ([], []) $ uncons headers museAppendElement :: MuseTableElement -> MuseTable -- cgit v1.2.3