#!/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 -> 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 = do input <- BL.getContents let title = (W.query extract_title :: Pandoc -> String) . either error id . A.eitherDecode' $ input putStrLn title