summaryrefslogtreecommitdiff
path: root/build/extract-title.hs
blob: 4582657386639e074e50445f91b5e8d0b568d3cc (plain)
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
#!/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