git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1527 from mpickering/juicypixels
e883ef4John MacFarlane
pandoc.cabal+2−1
@@ -252,7 +252,8 @@ Library
252 SHA >= 1.6 && < 1.7,
252 SHA >= 1.6 && < 1.7,
253 haddock-library >= 1.1 && < 1.2,
253 haddock-library >= 1.1 && < 1.2,
254 old-time,
254 old-time,
255− deepseq-generics >= 0.1 && < 0.2
255+ deepseq-generics >= 0.1 && < 0.2,
256+ JuicyPixels >= 3.1.6.1 && < 3.2
256 if flag(https)
257 if flag(https)
257 Build-Depends: http-client >= 0.3.2 && < 0.4,
258 Build-Depends: http-client >= 0.3.2 && < 0.4,
258 http-client-tls >= 0.2 && < 0.3,
259 http-client-tls >= 0.2 && < 0.3,
src/Text/Pandoc/PDF.hs+29−3
@@ -39,7 +39,8 @@ import System.FilePath
39import System.Directory
39import System.Directory
40import Data.Digest.Pure.SHA (showDigest, sha1)
40import Data.Digest.Pure.SHA (showDigest, sha1)
41import System.Environment
41import System.Environment
42−import Control.Monad (unless)
42+import Control.Monad (unless, (<=<))
43+import Control.Applicative ((<$>), (<$))
43import Data.List (isInfixOf)
44import Data.List (isInfixOf)
44import Data.Maybe (fromMaybe)
45import Data.Maybe (fromMaybe)
45import qualified Text.Pandoc.UTF8 as UTF8
46import qualified Text.Pandoc.UTF8 as UTF8
@@ -47,9 +48,10 @@ import Text.Pandoc.Definition
47import Text.Pandoc.Walk (walkM)
48import Text.Pandoc.Walk (walkM)
48import Text.Pandoc.Shared (fetchItem', warn, withTempDir)
49import Text.Pandoc.Shared (fetchItem', warn, withTempDir)
49import Text.Pandoc.Options (WriterOptions(..))
50import Text.Pandoc.Options (WriterOptions(..))
50−import Text.Pandoc.MIME (extensionFromMimeType)
51+import Text.Pandoc.MIME (extensionFromMimeType, getMimeType)
51import Text.Pandoc.Process (pipeProcess)
52import Text.Pandoc.Process (pipeProcess)
52import qualified Data.ByteString.Lazy as BL
53import qualified Data.ByteString.Lazy as BL
54+import qualified Codec.Picture as JP
53#ifdef _WINDOWS
55#ifdef _WINDOWS
54import Data.List (intercalate)
56import Data.List (intercalate)
55#endif
57#endif
@@ -73,7 +75,7 @@ handleImages :: WriterOptions
73 -> FilePath -- ^ temp dir to store images
75 -> FilePath -- ^ temp dir to store images
74 -> Pandoc -- ^ document
76 -> Pandoc -- ^ document
75 -> IO Pandoc
77 -> IO Pandoc
76−handleImages opts tmpdir = walkM (handleImage' opts tmpdir)
78+handleImages opts tmpdir = walkM (convertImages tmpdir) <=< walkM (handleImage' opts tmpdir)
77
79
78handleImage' :: WriterOptions
80handleImage' :: WriterOptions
79 -> FilePath
81 -> FilePath
@@ -98,6 +100,30 @@ handleImage' opts tmpdir (Image ils (src,tit)) = do
98 return $ Image ils (src,tit)
100 return $ Image ils (src,tit)
99handleImage' _ _ x = return x
101handleImage' _ _ x = return x
100
102
103+convertImages :: FilePath -> Inline -> IO Inline
104+convertImages tmpdir (Image ils (src, tit)) = do
105+ img <- convertImage tmpdir src
106+ newPath <-
107+ case img of
108+ Left _ -> src <$ (warn $ "Unable to convert image `" ++ src ++ "'")
109+ Right (fp, action) -> fp <$ action
110+ return (Image ils (newPath, tit))
111+convertImages _ x = return x
112+
113+-- Convert formats which do not work well in pdf to png
114+convertImage :: FilePath -> FilePath -> IO (Either String ((FilePath, IO ())))
115+convertImage tmpdir fname =
116+ case mime of
117+ Just "image/png" -> doNothing
118+ Just "image/jpeg" -> doNothing
119+ Just "application/pdf" -> doNothing
120+ _ -> savePng <$> JP.readImage fname
121+ where
122+ fileOut = replaceDirectory (replaceExtension fname (".png")) tmpdir
123+ savePng = fmap (\x -> (fileOut, JP.savePngImage fileOut x))
124+ mime = getMimeType fname
125+ doNothing = return (Right $ (fname, return ()))
126+
101tex2pdf' :: FilePath -- ^ temp directory for output
127tex2pdf' :: FilePath -- ^ temp directory for output
102 -> String -- ^ tex program
128 -> String -- ^ tex program
103 -> String -- ^ tex source
129 -> String -- ^ tex source
src/Text/Pandoc/Writers/LaTeX.hs+2−2
@@ -308,7 +308,7 @@ blockToLaTeX (Div (identifier,classes,_) bs) = do
308 ref <- toLabel identifier
308 ref <- toLabel identifier
309 let linkAnchor = if null identifier
309 let linkAnchor = if null identifier
310 then empty
310 then empty
311− else "\\hyperdef{}" <> braces (text ref)
311+ else "\\hyperdef{}" <> braces (text ref) <> "{}"
312 contents <- blockListToLaTeX bs
312 contents <- blockListToLaTeX bs
313 if beamer && "notes" `elem` classes -- speaker notes
313 if beamer && "notes" `elem` classes -- speaker notes
314 then return $ "\\note" <> braces contents
314 then return $ "\\note" <> braces contents
@@ -672,7 +672,7 @@ inlineToLaTeX (Span (id',classes,_) ils) = do
672 ref <- toLabel id'
672 ref <- toLabel id'
673 let linkAnchor = if null id'
673 let linkAnchor = if null id'
674 then empty
674 then empty
675− else "\\hyperdef{}" <> braces (text ref)
675+ else "\\hyperdef{}" <> braces (text ref) <> "{}"
676 fmap (linkAnchor <>)
676 fmap (linkAnchor <>)
677 ((if noEmph then inCmd "textup" else id) .
677 ((if noEmph then inCmd "textup" else id) .
678 (if noStrong then inCmd "textnormal" else id) .
678 (if noStrong then inCmd "textnormal" else id) .