diff options
Diffstat (limited to 'src/pandoc.hs')
-rw-r--r-- | src/pandoc.hs | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/src/pandoc.hs b/src/pandoc.hs index 27e4579aa..27bc2c25c 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -44,6 +44,8 @@ import Data.Char ( toLower ) import Data.List ( intercalate, isSuffixOf, isPrefixOf ) import System.Directory ( getAppUserDataDirectory, doesFileExist ) import System.IO ( stdout, stderr ) +import System.IO.Error ( isDoesNotExistError ) +import Control.Exception.Extensible ( throwIO ) import qualified Text.Pandoc.UTF8 as UTF8 import Text.CSL import Text.Pandoc.Biblio @@ -93,7 +95,7 @@ data Opt = Opt , optParseRaw :: Bool -- ^ Parse unconvertable HTML and TeX , optTableOfContents :: Bool -- ^ Include table of contents , optTransforms :: [Pandoc -> Pandoc] -- ^ Doc transforms to apply - , optTemplate :: String -- ^ Custom template + , optTemplate :: Maybe FilePath -- ^ Custom template , optVariables :: [(String,String)] -- ^ Template variables to set , optOutputFile :: String -- ^ Name of output file , optNumberSections :: Bool -- ^ Number sections in LaTeX @@ -137,7 +139,7 @@ defaultOpts = Opt , optParseRaw = False , optTableOfContents = False , optTransforms = [] - , optTemplate = "" + , optTemplate = Nothing , optVariables = [] , optOutputFile = "-" -- "-" means stdout , optNumberSections = False @@ -286,8 +288,12 @@ options = "" -- "Use jsMath for HTML math" , Option "" ["mathjax"] - (ReqArg - (\arg opt -> return opt { optHTMLMathMethod = MathJax arg}) + (OptArg + (\arg opt -> do + let url' = case arg of + Just u -> u + Nothing -> "https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" + return opt { optHTMLMathMethod = MathJax url'}) "URL") "" -- "Use MathJax for HTML math" @@ -309,7 +315,10 @@ options = , Option "" ["xetex"] (NoArg - (\opt -> return opt { optXeTeX = True })) + (\opt -> do + UTF8.hPutStrLn stderr $ "pandoc: --xetex is deprecated. " + ++ "It is no longer needed for use with XeTeX." + return opt { optXeTeX = True })) "" -- "Format latex for processing by XeTeX" , Option "" ["chapters"] @@ -404,8 +413,7 @@ options = , Option "" ["template"] (ReqArg (\arg opt -> do - text <- UTF8.readFile arg - return opt{ optTemplate = text, + return opt{ optTemplate = Just arg, optStandalone = True }) "FILENAME") "" -- "Use custom template" @@ -490,6 +498,14 @@ options = "FILENAME") "" -- "Path of epub.css" + , Option "" ["epub-cover-image"] + (ReqArg + (\arg opt -> + return opt { optVariables = + ("epub-cover-image", arg) : optVariables opt }) + "FILENAME") + "" -- "Path of epub cover image" + , Option "" ["epub-metadata"] (ReqArg (\arg opt -> do @@ -661,13 +677,12 @@ main = do , optVariables = variables , optTableOfContents = toc , optTransforms = transforms - , optTemplate = template + , optTemplate = templatePath , optOutputFile = outputFile , optNumberSections = numberSections , optSectionDivs = sectionDivs , optIncremental = incremental , optOffline = offline - , optXeTeX = xetex , optSmart = smart , optHtml5 = html5 , optChapters = chapters @@ -721,10 +736,25 @@ main = do Just r -> return r Nothing -> error ("Unknown reader: " ++ readerName') - templ <- getDefaultTemplate datadir writerName' - let defaultTemplate = case templ of - Right t -> t - Left e -> error (show e) + templ <- case templatePath of + Nothing -> do + deftemp <- getDefaultTemplate datadir writerName' + case deftemp of + Left e -> throwIO e + Right t -> return t + Just tp -> do + -- strip off "+lhs" if present + let format = takeWhile (/='+') writerName' + let tp' = case takeExtension tp of + "" -> tp <.> format + _ -> tp + catch (UTF8.readFile tp') + (\e -> if isDoesNotExistError e + then catch + (readDataFile datadir $ + "templates" </> tp') + (\_ -> throwIO e) + else throwIO e) let standalone' = standalone || isNonTextOutput writerName' @@ -736,7 +766,7 @@ main = do slidyJs <- readDataFile datadir $ "slidy" </> "slidy.min.js" slidyCss <- readDataFile datadir $ - "slidy" </> "slidy.min.css" + "slidy" </> "slidy.css" return $ ("slidy-js", slidyJs) : ("slidy-css", slidyCss) : variables _ -> return variables @@ -778,10 +808,9 @@ main = do stateIndentedCodeClasses = codeBlockClasses, stateApplyMacros = writerName' `notElem` ["latex", "latex+lhs"] } - let writerOptions = WriterOptions { writerStandalone = standalone', - writerTemplate = if null template - then defaultTemplate - else template, + let writerOptions = defaultWriterOptions + { writerStandalone = standalone', + writerTemplate = templ, writerVariables = variables'', writerEPUBMetadata = epubMetadata, writerTabStop = tabStop, @@ -790,7 +819,6 @@ main = do writerHTMLMathMethod = mathMethod, writerSlideVariant = slideVariant, writerIncremental = incremental, - writerXeTeX = xetex, writerCiteMethod = citeMethod, writerBiblioFiles = reffiles, writerIgnoreNotes = False, |