diff options
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/PDF.hs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs index 5f41d6c55..82c2312fe 100644 --- a/src/Text/Pandoc/PDF.hs +++ b/src/Text/Pandoc/PDF.hs @@ -56,6 +56,8 @@ import System.IO.Error (IOError, isDoesNotExistError) #else import System.IO.Error (isDoesNotExistError) #endif +import Text.HTML.TagSoup +import Text.HTML.TagSoup.Match import Text.Pandoc.Definition import Text.Pandoc.Error (PandocError (PandocPDFProgramNotFoundError)) import Text.Pandoc.MIME (getMimeType) @@ -353,7 +355,13 @@ html2pdf :: Verbosity -- ^ Verbosity level -> [String] -- ^ Args to program -> Text -- ^ HTML5 source -> IO (Either ByteString ByteString) -html2pdf verbosity program args source = do +html2pdf verbosity program args htmlSource = do + cwd <- getCurrentDirectory + let tags = parseTags htmlSource + (hd, tl) = break (tagClose (== "head")) tags + baseTag = TagOpen "base" + [("href", T.pack cwd <> T.singleton pathSeparator)] : [TagText "\n"] + source = renderTags $ hd ++ baseTag ++ tl pdfFile <- withTempFile "." "html2pdf.pdf" $ \fp _ -> return fp let pdfFileArgName = ["-o" | program == "prince"] let programArgs = args ++ ["-"] ++ pdfFileArgName ++ [pdfFile] |