@@ -45,7 +45,7 @@ import Control.Monad.Reader
4545import Control.Monad.Except (throwError)
4646import Data.Bifunctor
4747import Data.Default
48−import Data.List (intercalate)
48+import Data.List (intercalate, transpose)
4949import Data.List.Split (splitOn)
5050import qualified Data.Map as M
5151import qualified Data.Set as Set
@@ -135,9 +135,6 @@ parseMuse = do
135135
136136-- * Utility functions
137137
138−commonPrefix :: String -> String -> String
139−commonPrefix xs ys = map fst $ takeWhile (uncurry (==)) $ zip xs ys
140−
141138-- | Trim up to one newline from the beginning of the string.
142139lchop :: String -> String
143140lchop ('\n':xs) = xs
@@ -151,10 +148,10 @@ unindent :: String -> String
151148unindent = rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop
152149
153150dropSpacePrefix :: [String] -> [String]
154−dropSpacePrefix lns =
155− map (drop maxIndent) lns
156− where flns = filter (not . all (== ' ')) lns
157− maxIndent = if null flns then maximum (map length lns) else length $ takeWhile (== ' ') $ foldl1 commonPrefix flns
151+dropSpacePrefix lns = drop maxIndent <$> lns
152+ where isSpaceChar c = c == ' ' || c == '\t'
153+ maxIndent = length $ takeWhile (isSpaceChar . head) $ takeWhile same $ transpose lns
154+ same = and . (zipWith (==) <*> drop 1)
158155
159156atStart :: PandocMonad m => MuseParser m ()
160157atStart = do