summaryrefslogtreecommitdiff
path: root/build/extract-title.hs
diff options
context:
space:
mode:
Diffstat (limited to 'build/extract-title.hs')
-rwxr-xr-xbuild/extract-title.hs25
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
3import Text.Pandoc.Pretty 5import Text.Pandoc.Pretty
4import Text.Pandoc.JSON 6import Text.Pandoc.JSON
7import qualified Text.Pandoc.Walk as W
5import System.IO 8import System.IO
9import qualified Data.Aeson as A
10import qualified Data.ByteString.Lazy as BL
6 11
7extract_title :: Pandoc -> IO Pandoc 12extract_title :: Pandoc -> String
8extract_title d@(Pandoc m _) = do hPutStrLn stderr $ (++) "title: " $ render Nothing $ cat $ map pretty (docTitle m) 13extract_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
15main :: IO () 21main :: IO ()
16main = toJSONFilter extract_title 22main = do
23 input <- BL.getContents
24 let title = (W.query extract_title :: Pandoc -> String) . either error id . A.eitherDecode' $ input
25 putStrLn title