2016-01-26 00:27:07 +01:00
|
|
|
|
|
|
|
import Control.Arrow
|
|
|
|
import Data.Foldable
|
|
|
|
import Data.List
|
|
|
|
import System.Environment
|
|
|
|
|
|
|
|
main = do
|
|
|
|
files <- getArgs
|
|
|
|
forM_ files $ \ file -> do
|
|
|
|
convertM file
|
|
|
|
|
|
|
|
convertM :: FilePath -> IO ()
|
|
|
|
convertM file = do
|
|
|
|
contents <- readFile file
|
|
|
|
seq (length contents) (return ())
|
|
|
|
writeFile file (convert contents)
|
|
|
|
|
|
|
|
convert :: String -> String
|
|
|
|
convert =
|
|
|
|
lines >>>
|
|
|
|
groupBy (\ a b -> take 1 a == take 1 b) >>>
|
|
|
|
map go >>>
|
|
|
|
concat >>>
|
|
|
|
unlines
|
|
|
|
where
|
|
|
|
go :: [String] -> [String]
|
|
|
|
go (a : r)
|
|
|
|
| ">" `isPrefixOf` a
|
2016-01-27 22:26:59 +01:00
|
|
|
= "``` haskell ignore" : map (drop 2) (a : r) ++ "```" : []
|
2016-01-26 00:27:07 +01:00
|
|
|
go x = x
|