/
Main.hs
31 lines (28 loc) · 981 Bytes
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Main (main) where
import System.Environment (getArgs, getProgName)
import System.IO (hPutStrLn, stderr)
import System.Exit (exitFailure)
import Text.Pandoc (Pandoc(..), Block(..), readMarkdown, defaultParserState)
main :: IO ()
main = getArgs >>= \args -> case args of
-- GHC calls unlit like so:
--
-- > unlit -h label Foo.lhs /tmp/somefile
--
-- The label is meant to be used in line pragmas, like so:
--
-- #line 1 "label"
--
-- But as Pandoc does not provide location information, we have no use for
-- it, yet.
["-h", _, infile, outfile] ->
fmap unlit (readFile infile) >>= writeFile outfile
_ -> do
name <- getProgName
hPutStrLn stderr ("usage: " ++ name ++ " -h label infile outfile")
exitFailure
unlit :: String -> String
unlit input = unlines [x | CodeBlock (_, c, _) x <- nodes, isLiterate c]
where
isLiterate c = "literate" `elem` c && "haskell" `elem` c
Pandoc _ nodes = readMarkdown defaultParserState input