Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

All export formats now working, including PDF.

  • Loading branch information...
commit 9fa57f5cedaace2d6cbadd77bce68a93a7507d37 1 parent 139cbed
@jgm authored
View
37 Network/Gitit2.hs
@@ -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)
@@ -1152,7 +1153,8 @@ 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 ->
@@ -1160,15 +1162,18 @@ getExportFormats = do
, ("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))
@@ -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
@@ -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 <> "\""
View
1  config/settings.yaml
@@ -12,3 +12,4 @@ cache_dir: cache
front_page: Front Page
help_page: Help
max_upload_size: 1M
+latex_engine: xelatex
View
1  gitit2.cabal
@@ -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
View
6 src/gitit2.hs
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.