aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-10-09 23:34:50 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-10-28 03:52:35 +0300
commitf8ca36525d8a8c855dcfa33d6215c47533567d20 (patch)
treea3abe26e2859fa88d1262f1a18960670f6d48ad0 /test
parente34a0703f557ed4ceeadaa6cb29edb6239255d96 (diff)
downloadpandoc-f8ca36525d8a8c855dcfa33d6215c47533567d20.tar.gz
Muse: Make tables round-trip
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Readers/Muse.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs
index bb61e848f..42dec0ffd 100644
--- a/test/Tests/Readers/Muse.hs
+++ b/test/Tests/Readers/Muse.hs
@@ -4,6 +4,7 @@ module Tests.Readers.Muse (tests) where
import Prelude
import Data.List (intersperse)
+import Data.Monoid (Any (..))
import Data.Text (Text)
import qualified Data.Text as T
import Test.Tasty
@@ -14,7 +15,7 @@ import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
import Text.Pandoc.Shared (underlineSpan)
-import Text.Pandoc.Walk (walk)
+import Text.Pandoc.Walk
amuse :: Text -> Pandoc
amuse = purely $ readMuse def { readerExtensions = extensionsFromList [Ext_amuse]}
@@ -33,7 +34,20 @@ spcSep = mconcat . intersperse space
-- Tables don't round-trip yet
--
makeRoundTrip :: Block -> Block
-makeRoundTrip Table{} = Para [Str "table was here"]
+makeRoundTrip t@(Table _caption aligns widths headers rows) =
+ if isSimple && numcols > 1
+ then t
+ else Para [Str "table was here"]
+ where 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
makeRoundTrip (OrderedList (start, LowerAlpha, _) items) = OrderedList (start, Decimal, Period) items
makeRoundTrip (OrderedList (start, UpperAlpha, _) items) = OrderedList (start, Decimal, Period) items
makeRoundTrip x = x