on 7af73d6 help sign in
servant/doc/tutorial/convert.hs
30 lines 648 B history raw
2import Control.Arrow
3import Data.Foldable
4import Data.List
5import System.Environment
7main = do
8 files <- getArgs
9 forM_ files $ \ file -> do
10 convertM file
12convertM :: FilePath -> IO ()
13convertM file = do
14 contents <- readFile file
15 seq (length contents) (return ())
16 writeFile file (convert contents)
18convert :: String -> String
19convert =
20 lines >>>
21 groupBy (\ a b -> take 1 a == take 1 b) >>>
22 map go >>>
23 concat >>>
24 unlines
25 where
26 go :: [String] -> [String]
27 go (a : r)
28 | ">" `isPrefixOf` a
29 = "``` haskell ignore" : map (drop 2) (a : r) ++ "```" : []
30 go x = x