@@ -4,6 +4,7 @@ module Tests.Readers.Muse (tests) where
44
55import Prelude
66import Data.List (intersperse)
7+import Data.Monoid (Any (..))
78import Data.Text (Text)
89import qualified Data.Text as T
910import Test.Tasty
@@ -14,7 +15,7 @@ import Text.Pandoc
1415import Text.Pandoc.Arbitrary ()
1516import Text.Pandoc.Builder
1617import Text.Pandoc.Shared (underlineSpan)
17−import Text.Pandoc.Walk (walk)
18+import Text.Pandoc.Walk
1819
1920amuse :: Text -> Pandoc
2021amuse = purely $ readMuse def { readerExtensions = extensionsFromList [Ext_amuse]}
@@ -33,7 +34,20 @@ spcSep = mconcat . intersperse space
3334-- Tables don't round-trip yet
3435--
3536makeRoundTrip :: Block -> Block
36−makeRoundTrip Table{} = Para [Str "table was here"]
37+makeRoundTrip t@(Table _caption aligns widths headers rows) =
38+ if isSimple && numcols > 1
39+ then t
40+ else Para [Str "table was here"]
41+ where numcols = maximum (length aligns : length widths : map length (headers:rows))
42+ hasSimpleCells = all isSimpleCell (concat (headers:rows))
43+ isLineBreak LineBreak = Any True
44+ isLineBreak _ = Any False
45+ hasLineBreak = getAny . query isLineBreak
46+ isSimple = hasSimpleCells && all (== 0) widths
47+ isSimpleCell [Plain ils] = not (hasLineBreak ils)
48+ isSimpleCell [Para ils ] = not (hasLineBreak ils)
49+ isSimpleCell [] = True
50+ isSimpleCell _ = False
3751makeRoundTrip (OrderedList (start, LowerAlpha, _) items) = OrderedList (start, Decimal, Period) items
3852makeRoundTrip (OrderedList (start, UpperAlpha, _) items) = OrderedList (start, Decimal, Period) items
3953makeRoundTrip x = x