diff options
author | Mauro Bieg <mb21@users.noreply.github.com> | 2018-03-12 02:21:15 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-03-11 18:21:15 -0700 |
commit | 15f700d8edc7c3a860766de7c6fef572b533dab2 (patch) | |
tree | 62539b056f8a01547294ff14d946e26e7cb3a662 /src | |
parent | a0da1e2723a08b4afc12a6e358d3abfdffeb6944 (diff) | |
download | pandoc-15f700d8edc7c3a860766de7c6fef572b533dab2.tar.gz |
html2pdf: inject base tag wih current working directory (#4443)
fixes #4413
Diffstat (limited to 'src')
-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] |