git.iko.soy/typeable/pandoc
on master help sign in
html2pdf: inject base tag wih current working directory (#4443)

fixes #4413

commit15f700d8edc7c3a860766de7c6fef572b533dab2 authorMauro Bieg <mb21@users.noreply.github.com> dateMon 12 Mar 2018, 02:21 (9 years ago) parenta0da1e2
1 file changed+9−1
src/Text/Pandoc/PDF.hs+9−1
src/Text/Pandoc/PDF.hs+9−1
@@ -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]