module Common.Unlit (unlit) where
import Data.List
unlit :: String -> String
unlit :: String -> String
unlit s :: String
s = let cs :: [String]
cs = Bool -> [String] -> [String]
getCode Bool
True ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ String -> [String]
lines String
s in
if (String -> Bool) -> [String] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
cs then "" else [String] -> String
unlines [String]
cs
getCode :: Bool -> [String] -> [String]
getCode :: Bool -> [String] -> [String]
getCode d :: Bool
d l :: [String]
l = case [String]
l of
[] -> []
s :: String
s : r :: [String]
r -> if Bool -> Bool
not Bool
d Bool -> Bool -> Bool
&& String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf "\\end{code}" String
s
Bool -> Bool -> Bool
|| Bool
d Bool -> Bool -> Bool
&& String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf "\\begin{code}" String
s
then "" String -> [String] -> [String]
forall a. a -> [a] -> [a]
: Bool -> [String] -> [String]
getCode (Bool -> Bool
not Bool
d) [String]
r
else (case String
s of
'>' : t :: String
t | Bool
d -> ' ' Char -> String -> String
forall a. a -> [a] -> [a]
: String
t
_ -> if Bool
d then "" else String
s) String -> [String] -> [String]
forall a. a -> [a] -> [a]
: Bool -> [String] -> [String]
getCode Bool
d [String]
r