{-# LANGUAGE Haskell2010, LambdaCase #-} module Main where import Control.Applicative import System.Environment import Text.Nicify main = getArgs >>= \case [] -> lhs2html <$> getContents >>= putStrLn args -> flip mapM_ args $ \f -> lhs2html <$> readFile f >>= writeFile (f ++ ".html") preamble = "\n\ \\n\ \
\n\ \ \n\ \\n\ \\n\ \\n\ \ \n" : map' htmlize ls) Code ls -> foldr (++) ("\n" ++ xs) ("
" : map' (spanify . escape) ls) H1 ls -> "" ++ htmlize ls ++ "
\n" ++ xs H2 ls -> "" ++ htmlize ls ++ "
\n" ++ xs H3 ls -> "" ++ htmlize ls ++ "
\n" ++ xs _ -> xs spanify xs = "" ++ xs ++ "" map' :: (String -> String) -> [String] -> [String] map' f = foldr (\a b -> (f a ++ "\n") : b) [] htmlize :: String -> String htmlize = codify False . escape escape :: String -> String escape = concatMap $ \case '<' -> "<" '>' -> ">" '&' -> "&" x -> [x] codify :: Bool -> String -> String codify False ('`' : xs) = "" ++ codify True xs codify True ('`' : xs) = "
" ++ codify False xs codify flag (x : xs) = x : codify flag xs codify _ _ = []