diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-03-29 01:36:42 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-03-29 01:36:42 +0100 |
commit | 29907c6c870933ec1031fa6499ea9994c96f7aa6 (patch) | |
tree | fb4cb96f30e2138b9d6c0e7ec7b01950d6fe803f | |
parent | 316dfb918c586fa1743b9389729177375e883d9a (diff) | |
download | dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar.gz dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar.bz2 dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar.xz dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.zip |
extract-title.hs now only writes title to stdout
-rwxr-xr-x | build/extract-title.hs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/build/extract-title.hs b/build/extract-title.hs index a84442e..4582657 100755 --- a/build/extract-title.hs +++ b/build/extract-title.hs | |||
@@ -1,16 +1,25 @@ | |||
1 | #!/usr/bin/env runhaskell | 1 | #!/usr/bin/env runhaskell |
2 | 2 | ||
3 | -- import Text.Pandoc.Pretty | ||
4 | -- import Text.Pandoc.JSON | ||
3 | import Text.Pandoc.Pretty | 5 | import Text.Pandoc.Pretty |
4 | import Text.Pandoc.JSON | 6 | import Text.Pandoc.JSON |
7 | import qualified Text.Pandoc.Walk as W | ||
5 | import System.IO | 8 | import System.IO |
9 | import qualified Data.Aeson as A | ||
10 | import qualified Data.ByteString.Lazy as BL | ||
6 | 11 | ||
7 | extract_title :: Pandoc -> IO Pandoc | 12 | extract_title :: Pandoc -> String |
8 | extract_title d@(Pandoc m _) = do hPutStrLn stderr $ (++) "title: " $ render Nothing $ cat $ map pretty (docTitle m) | 13 | extract_title d@(Pandoc m _) = do |
9 | return d | 14 | title <- render Nothing $ cat $ map pretty (docTitle m) |
10 | where pretty :: Inline -> Doc | 15 | return title |
11 | pretty (Str s) = text s | 16 | where pretty :: Inline -> Doc |
12 | pretty Space = space | 17 | pretty (Str s) = text s |
13 | pretty _ = empty | 18 | pretty Space = space |
19 | pretty _ = empty | ||
14 | 20 | ||
15 | main :: IO () | 21 | main :: IO () |
16 | main = toJSONFilter extract_title | 22 | main = do |
23 | input <- BL.getContents | ||
24 | let title = (W.query extract_title :: Pandoc -> String) . either error id . A.eitherDecode' $ input | ||
25 | putStrLn title | ||