@@ -56,6 +56,8 @@ import System.IO.Error (IOError, isDoesNotExistError)
5656#else
5757import System.IO.Error (isDoesNotExistError)
5858#endif
59+import Text.HTML.TagSoup
60+import Text.HTML.TagSoup.Match
5961import Text.Pandoc.Definition
6062import Text.Pandoc.Error (PandocError (PandocPDFProgramNotFoundError))
6163import Text.Pandoc.MIME (getMimeType)
@@ -353,7 +355,13 @@ html2pdf :: Verbosity -- ^ Verbosity level
353355 -> [String] -- ^ Args to program
354356 -> Text -- ^ HTML5 source
355357 -> IO (Either ByteString ByteString)
356−html2pdf verbosity program args source = do
358+html2pdf verbosity program args htmlSource = do
359+ cwd <- getCurrentDirectory
360+ let tags = parseTags htmlSource
361+ (hd, tl) = break (tagClose (== "head")) tags
362+ baseTag = TagOpen "base"
363+ [("href", T.pack cwd <> T.singleton pathSeparator)] : [TagText "\n"]
364+ source = renderTags $ hd ++ baseTag ++ tl
357365 pdfFile <- withTempFile "." "html2pdf.pdf" $ \fp _ -> return fp
358366 let pdfFileArgName = ["-o" | program == "prince"]
359367 let programArgs = args ++ ["-"] ++ pdfFileArgName ++ [pdfFile]