Skip to content

Commit

Permalink
All export formats now working, including PDF.
Browse files Browse the repository at this point in the history
  • Loading branch information
John MacFarlane committed Jul 14, 2012
1 parent 139cbed commit 9fa57f5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
37 changes: 16 additions & 21 deletions Network/Gitit2.hs
Expand Up @@ -29,6 +29,7 @@ import Data.FileStore as FS
import Data.Char (toLower)
import System.FilePath
import Text.Pandoc
import Text.Pandoc.PDF (tex2pdf)
import Text.Pandoc.Shared (stringify, inDirectory, readDataFile)
import Text.Pandoc.SelfContained (makeSelfContained)
import Text.Pandoc.Builder (toList, text)
Expand Down Expand Up @@ -1152,23 +1153,27 @@ getExportFormats = do
, ("DZSlides", (".html", basicExport "dzslides" typeHtml $ \opts -> selfcontained .
writeHtmlString opts{ writerSlideVariant = DZSlides
, writerHtml5 = True }))
, ("EPUB", (".epub", basicExport "epub" "application/xhtml+xml" $ writeEPUB Nothing []))
, ("EPUB", (".epub", basicExport "epub" "application/xhtml+xml" $ \opts ->
inDirectory repopath . writeEPUB Nothing [] opts))
, ("Groff man", (".1", basicExport "man" typePlain $ pureWriter writeMan))
, ("HTML", (".html", basicExport "html" typeHtml $ \opts -> selfcontained . writeHtmlString opts))
, ("HTML5", (".html", basicExport "html5" typeHtml $ \opts ->
selfcontained . writeHtmlString opts{ writerHtml5 = True }))
, ("LaTeX", (".tex", basicExport "latex" "application/x-latex" $ pureWriter writeLaTeX))
, ("Markdown", (".txt", basicExport "markdown" typePlain $ pureWriter writeMarkdown))
, ("Mediawiki", (".wiki", basicExport "mediawiki" typePlain $ pureWriter writeMediaWiki))
-- , ("ODT", (".odt", odtExport))
, ("ODT", (".odt", basicExport "opendocument" "application/vnd.oasis.opendocument.text"
$ \opts -> inDirectory repopath . writeODT Nothing opts))
, ("OpenDocument", (".xml", basicExport "opendocument" "application/vnd.oasis.opendocument.text"
$ pureWriter writeOpenDocument))
, ("Org-mode", (".org", basicExport "org" typePlain $ pureWriter writeOrg))
-- ] ++
-- [ ("PDF", (".pdf", pdfExport)) | isJust (latex_engine conf) ]
-- ++
-- [
, ("Plain text", (".txt", basicExport "plain" typePlain $ pureWriter writePlain))
, ("Org-mode", (".org", basicExport "org" typePlain $ pureWriter writeOrg)) ] ++
[ ("PDF", (".pdf", basicExport "latex" "application/pdf" $ \opts d ->
inDirectory repopath $ tex2pdf (maybe "pdflatex" id $
latex_engine conf) (writeLaTeX opts d) >>= \res ->
case res of
Left e -> error $ "Could not produce PDF: " ++ toString e
Right pdf -> return pdf)) | isJust (latex_engine conf) ] ++
[ ("Plain text", (".txt", basicExport "plain" typePlain $ pureWriter writePlain))
, ("reStructuredText", (".txt", basicExport "rst" typePlain $ pureWriter writeRST))
, ("RTF", (".rtf", basicExport "rtf" "application/rtf" $ \opts d ->
writeRTF opts <$> bottomUpM rtfEmbedImage d))
Expand All @@ -1178,7 +1183,9 @@ getExportFormats = do
, ("Slidy", (".html", basicExport "slidy" typeHtml $ \opts ->
selfcontained . writeHtmlString opts{ writerSlideVariant = SlidySlides }))
, ("Texinfo", (".texi", basicExport "texinfo" "application/x-texinfo" $ pureWriter writeTexinfo))
-- , ("Word docx", (".docx", docxExport))
, ("Word docx", (".docx", basicExport "docx"
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
$ \opts -> inDirectory repopath . writeDocx Nothing opts))
]

basicExport :: ToContent a
Expand Down Expand Up @@ -1216,18 +1223,6 @@ basicExport templ contentType writer = \wikiPage -> do
$ Pandoc (Meta (wpTitle wikiPage) [] []) $ wpContent wikiPage
return (contentType, toContent rendered)

-- TODO
pdfExport :: WikiPage -> GHandler Gitit master (ContentType, Content)
pdfExport page = fail "not implemented"

-- TODO
odtExport :: WikiPage -> GHandler Gitit master (ContentType, Content)
odtExport page = fail "not implemented"

-- TODO
docxExport :: WikiPage -> GHandler Gitit master (ContentType, Content)
docxExport page = fail "not implemented"

setFilename :: Text -> GHandler sub master ()
setFilename fname = setHeader "Content-Disposition"
$ "attachment; filename=\"" <> fname <> "\""
Expand Down
1 change: 1 addition & 0 deletions config/settings.yaml
Expand Up @@ -12,3 +12,4 @@ cache_dir: cache
front_page: Front Page
help_page: Help
max_upload_size: 1M
latex_engine: xelatex
1 change: 1 addition & 0 deletions gitit2.cabal
Expand Up @@ -103,6 +103,7 @@ executable gitit2
, bytestring >= 0.9 && < 1.0
, warp >= 1.2 && < 1.3
, text >= 0.11 && < 0.12
, directory >= 1.1 && < 1.2
, network >= 2.3 && < 2.4
, gitit2
ghc-options: -Wall -threaded -fno-warn-unused-do-bind
Expand Down
6 changes: 6 additions & 0 deletions src/gitit2.hs
Expand Up @@ -8,6 +8,8 @@ import Network.Wai.Handler.Warp
import Data.FileStore
import Data.Yaml
import Control.Applicative
import Control.Monad (when)
import System.Directory (removeDirectoryRecursive)
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import System.IO
Expand Down Expand Up @@ -183,6 +185,10 @@ main = do
Nothing -> err 17 $ "Could not read size: " ++
cfg_max_upload_size conf

-- clear cache
when (cfg_use_cache conf) $
removeDirectoryRecursive $ cfg_cache_dir conf

let settings = defaultSettings{ settingsPort = cfg_port conf }
let runner = runSettingsSocket settings sock
runner =<< toWaiApp
Expand Down

0 comments on commit 9fa57f5

Please sign in to comment.