From 29907c6c870933ec1031fa6499ea9994c96f7aa6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 29 Mar 2015 01:36:42 +0100 Subject: extract-title.hs now only writes title to stdout --- build/extract-title.hs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'build/extract-title.hs') 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 @@ #!/usr/bin/env runhaskell +-- import Text.Pandoc.Pretty +-- import Text.Pandoc.JSON import Text.Pandoc.Pretty import Text.Pandoc.JSON +import qualified Text.Pandoc.Walk as W import System.IO +import qualified Data.Aeson as A +import qualified Data.ByteString.Lazy as BL -extract_title :: Pandoc -> IO Pandoc -extract_title d@(Pandoc m _) = do hPutStrLn stderr $ (++) "title: " $ render Nothing $ cat $ map pretty (docTitle m) - return d - where pretty :: Inline -> Doc - pretty (Str s) = text s - pretty Space = space - pretty _ = empty +extract_title :: Pandoc -> String +extract_title d@(Pandoc m _) = do + title <- render Nothing $ cat $ map pretty (docTitle m) + return title + where pretty :: Inline -> Doc + pretty (Str s) = text s + pretty Space = space + pretty _ = empty main :: IO () -main = toJSONFilter extract_title +main = do + input <- BL.getContents + let title = (W.query extract_title :: Pandoc -> String) . either error id . A.eitherDecode' $ input + putStrLn title -- cgit v1.2.3