[doc] Improve hint set documentation.
[ttfautohint.git] / doc / handle-images.hs
blob8be199e42c64e09f37494e7ded56fc5f02304a80
1 -- handle-images.hs
2 --
3 -- Copyright (C) 2012 by Werner Lemberg.
4 --
5 -- This file is part of the ttfautohint library, and may only be used,
6 -- modified, and distributed under the terms given in `COPYING'. By
7 -- continuing to use, modify, or distribute this file you indicate
8 -- that you have read `COPYING' and understand and accept it fully.
9 --
10 -- The file `COPYING' mentioned in the previous paragraph is
11 -- distributed with the ttfautohint library.
14 -- This is a simple pandoc filter to support different image formats
15 -- for different backends. It simply appends the suffix given as a
16 -- command line option to all pandoc images and checks whether the
17 -- image files actually exist. For non-existent files the file name
18 -- doesn't get altered.
20 -- Command line examples:
22 -- % pandoc -t json foo \
23 -- | ./handle-images ".svg" \
24 -- | pandoc -f json -t html \
25 -- > foo.html
27 -- % pandoc -t json foo \
28 -- | ./handle-images ".pdf" \
29 -- | pandoc --latex-engine=pdflatex -f json -t latex \
30 -- > foo.tex
33 import Text.Pandoc
34 import System.Environment(getArgs)
35 import System.Directory(doesFileExist)
38 handleImage :: String
39 -> Inline
40 -> IO Inline
41 handleImage format
42 (Image description (basename, title)) = do
43 let
44 filename = basename ++ format
46 fileExists <- doesFileExist filename
47 if fileExists
48 then
49 return $ Image description (filename, title)
50 else
51 return $ Image description (basename, title)
52 handleImage _ x = return x
55 main :: IO ()
56 main = do
57 args <- getArgs
58 toJsonFilter
59 $ handleImage
60 $ case args of
61 [f] -> f
62 _ -> "" -- default
65 -- end of handle-images.hs