aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/PDF.hs
diff options
context:
space:
mode:
authordespresc <christian.j.j.despres@gmail.com>2019-11-04 16:12:37 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2019-11-12 16:03:45 -0800
commit90e436d49604e3fd1ef9432fb23f6d7f6245c7fd (patch)
tree4e7f0692f989643189f1fc6786050d95e239a0ea /src/Text/Pandoc/PDF.hs
parentd3966372f5049eea56213b069fc4d70d8af9144c (diff)
downloadpandoc-90e436d49604e3fd1ef9432fb23f6d7f6245c7fd.tar.gz
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884. + Use pandoc-types 1.20 and texmath 0.12. + Text is now used instead of String, with a few exceptions. + In the MediaBag module, some of the types using Strings were switched to use FilePath instead (not Text). + In the Parsing module, new parsers `manyChar`, `many1Char`, `manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`, `mantyUntilChar` have been added: these are like their unsuffixed counterparts but pack some or all of their output. + `glob` in Text.Pandoc.Class still takes String since it seems to be intended as an interface to Glob, which uses strings. It seems to be used only once in the package, in the EPUB writer, so that is not hard to change.
Diffstat (limited to 'src/Text/Pandoc/PDF.hs')
-rw-r--r--src/Text/Pandoc/PDF.hs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index d7e61109f..1d307cdd4 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
@@ -46,7 +46,7 @@ import Text.Pandoc.MIME (getMimeType)
import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
import Text.Pandoc.Process (pipeProcess)
import System.Process (readProcessWithExitCode)
-import Text.Pandoc.Shared (inDirectory, stringify)
+import Text.Pandoc.Shared (inDirectory, stringify, tshow)
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Walk (walkM)
import Text.Pandoc.Writers.Shared (getField, metaToContext)
@@ -141,7 +141,7 @@ makeWithWkhtmltopdf program pdfargs writer opts doc@(Pandoc meta _) = do
(return . literal . stringify)
(return . literal . stringify)
meta
- let toArgs (f, mbd) = maybe [] (\d -> ['-':'-':f, d]) mbd
+ let toArgs (f, mbd) = maybe [] (\d -> ["--" <> f, T.unpack d]) mbd
let args = pdfargs ++ mathArgs ++ concatMap toArgs
[("page-size", getField "papersize" meta')
,("title", getField "title" meta')
@@ -173,19 +173,19 @@ handleImages opts tmpdir doc =
convertImages :: WriterOptions -> FilePath -> Inline -> PandocIO Inline
convertImages opts tmpdir (Image attr ils (src, tit)) = do
- img <- liftIO $ convertImage opts tmpdir src
+ img <- liftIO $ convertImage opts tmpdir $ T.unpack src
newPath <-
case img of
Left e -> do
report $ CouldNotConvertImage src e
return src
- Right fp -> return fp
+ Right fp -> return $ T.pack fp
return (Image attr ils (newPath, tit))
convertImages _ _ x = return x
-- Convert formats which do not work well in pdf to png
convertImage :: WriterOptions -> FilePath -> FilePath
- -> IO (Either String FilePath)
+ -> IO (Either Text FilePath)
convertImage opts tmpdir fname = do
let dpi = show $ writerDpi opts
case mime of
@@ -202,14 +202,14 @@ convertImage opts tmpdir fname = do
then return $ Right pdfOut
else return $ Left "conversion from SVG failed")
(\(e :: E.SomeException) -> return $ Left $
- "check that rsvg-convert is in path.\n" ++
- show e)
+ "check that rsvg-convert is in path.\n" <>
+ tshow e)
_ -> JP.readImage fname >>= \res ->
case res of
- Left e -> return $ Left e
+ Left e -> return $ Left $ T.pack e
Right img ->
E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
- \(e :: E.SomeException) -> return (Left (show e))
+ \(e :: E.SomeException) -> return (Left (tshow e))
where
pngOut = replaceDirectory (replaceExtension fname ".png") tmpdir
pdfOut = replaceDirectory (replaceExtension fname ".pdf") tmpdir
@@ -262,12 +262,11 @@ missingCharacterWarnings :: Verbosity -> ByteString -> PandocIO ()
missingCharacterWarnings verbosity log' = do
let ls = BC.lines log'
let isMissingCharacterWarning = BC.isPrefixOf "Missing character: "
- let addCodePoint [] = []
- addCodePoint (c:cs)
- | isAscii c = c : addCodePoint cs
- | otherwise = c : " (U+" ++ printf "%04X" (ord c) ++ ")" ++
- addCodePoint cs
- let warnings = [ addCodePoint (utf8ToString (BC.drop 19 l))
+ let toCodePoint c
+ | isAscii c = T.singleton c
+ | otherwise = T.pack $ c : " (U+" ++ printf "%04X" (ord c) ++ ")"
+ let addCodePoint = T.concatMap toCodePoint
+ let warnings = [ addCodePoint (T.pack $ utf8ToString (BC.drop 19 l))
| l <- ls
, isMissingCharacterWarning l
]
@@ -513,7 +512,7 @@ showVerboseInfo mbTmpDir program programArgs env source = do
handlePDFProgramNotFound :: String -> IE.IOError -> IO a
handlePDFProgramNotFound program e
| IE.isDoesNotExistError e =
- E.throwIO $ PandocPDFProgramNotFoundError program
+ E.throwIO $ PandocPDFProgramNotFoundError $ T.pack program
| otherwise = E.throwIO e
utf8ToString :: ByteString -> String