diff options
Diffstat (limited to 'build')
| -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 | ||
