2014-07-31 21:51:01 +02:00
|
|
|
{-# LANGUAGE CPP, TupleSections #-}
|
2006-12-20 21:54:23 +01:00
|
|
|
{-
|
2015-04-26 19:18:29 +02:00
|
|
|
Copyright (C) 2006-2015 John MacFarlane <jgm@berkeley.edu>
|
2006-12-20 21:54:23 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
|
|
|
|
2006-12-20 07:50:14 +01:00
|
|
|
{- |
|
|
|
|
Module : Main
|
2015-04-26 19:18:29 +02:00
|
|
|
Copyright : Copyright (C) 2006-2015 John MacFarlane
|
2008-08-10 19:33:20 +02:00
|
|
|
License : GNU GPL, version 2 or above
|
2006-12-20 07:50:14 +01:00
|
|
|
|
2007-07-08 00:51:55 +02:00
|
|
|
Maintainer : John MacFarlane <jgm@berkeley@edu>
|
2008-08-10 19:33:20 +02:00
|
|
|
Stability : alpha
|
2006-12-20 07:50:14 +01:00
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Parses command-line options and calls the appropriate readers and
|
|
|
|
writers.
|
|
|
|
-}
|
2006-10-17 16:22:29 +02:00
|
|
|
module Main where
|
2007-07-12 10:31:05 +02:00
|
|
|
import Text.Pandoc
|
2013-09-02 00:37:02 +02:00
|
|
|
import Text.Pandoc.Builder (setMeta)
|
2013-07-20 21:14:43 +02:00
|
|
|
import Text.Pandoc.PDF (makePDF)
|
2014-07-30 20:44:25 +02:00
|
|
|
import Text.Pandoc.Walk (walk)
|
2012-01-30 08:54:00 +01:00
|
|
|
import Text.Pandoc.Readers.LaTeX (handleIncludes)
|
2013-08-14 03:25:20 +02:00
|
|
|
import Text.Pandoc.Shared ( tabFilter, readDataFileUTF8, readDataFile,
|
2013-12-05 20:28:22 +01:00
|
|
|
safeRead, headerShift, normalize, err, warn,
|
2014-07-31 21:00:21 +02:00
|
|
|
openURL )
|
2014-08-01 01:26:48 +02:00
|
|
|
import Text.Pandoc.MediaBag ( mediaDirectory, extractMediaBag, MediaBag )
|
2013-08-25 07:27:08 +02:00
|
|
|
import Text.Pandoc.XML ( toEntities )
|
2011-11-22 00:24:28 +01:00
|
|
|
import Text.Pandoc.SelfContained ( makeSelfContained )
|
2013-08-09 00:15:58 +02:00
|
|
|
import Text.Pandoc.Process (pipeProcess)
|
2013-03-06 07:09:42 +01:00
|
|
|
import Text.Highlighting.Kate ( languages, Style, tango, pygments,
|
2012-05-18 03:54:41 +02:00
|
|
|
espresso, zenburn, kate, haddock, monochrome )
|
2014-08-17 19:33:18 +02:00
|
|
|
import System.Environment ( getArgs, getProgName )
|
2007-01-08 17:29:29 +01:00
|
|
|
import System.Exit ( exitWith, ExitCode (..) )
|
2009-01-24 20:58:06 +01:00
|
|
|
import System.FilePath
|
2006-10-17 16:22:29 +02:00
|
|
|
import System.Console.GetOpt
|
2010-12-13 05:09:14 +01:00
|
|
|
import Data.Char ( toLower )
|
2015-02-27 18:29:33 +01:00
|
|
|
import Data.List ( delete, intercalate, isPrefixOf, isSuffixOf, sort )
|
2014-04-06 00:51:04 +02:00
|
|
|
import System.Directory ( getAppUserDataDirectory, findExecutable,
|
2014-07-31 20:04:40 +02:00
|
|
|
doesFileExist, Permissions(..), getPermissions )
|
2013-08-14 22:02:54 +02:00
|
|
|
import System.IO ( stdout, stderr )
|
2011-07-23 07:15:25 +02:00
|
|
|
import System.IO.Error ( isDoesNotExistError )
|
2012-07-25 04:28:51 +02:00
|
|
|
import qualified Control.Exception as E
|
2011-07-23 07:15:25 +02:00
|
|
|
import Control.Exception.Extensible ( throwIO )
|
2010-05-07 05:29:44 +02:00
|
|
|
import qualified Text.Pandoc.UTF8 as UTF8
|
2014-08-04 16:08:12 +02:00
|
|
|
import Control.Monad (when, unless, (>=>))
|
2014-09-25 19:23:28 +02:00
|
|
|
import Data.Maybe (isJust, fromMaybe)
|
2013-08-08 20:09:00 +02:00
|
|
|
import Data.Foldable (foldrM)
|
2010-11-13 03:30:50 +01:00
|
|
|
import Network.URI (parseURI, isURI, URI(..))
|
2010-07-03 05:12:14 +02:00
|
|
|
import qualified Data.ByteString.Lazy as B
|
2013-08-14 03:25:20 +02:00
|
|
|
import qualified Data.ByteString as BS
|
2013-08-09 00:15:58 +02:00
|
|
|
import Data.Aeson (eitherDecode', encode)
|
2013-09-18 06:04:27 +02:00
|
|
|
import qualified Data.Map as M
|
2013-09-20 05:21:35 +02:00
|
|
|
import Data.Yaml (decode)
|
|
|
|
import qualified Data.Yaml as Yaml
|
|
|
|
import qualified Data.Text as T
|
2014-09-25 19:23:28 +02:00
|
|
|
import Control.Applicative ((<$>), (<|>))
|
2014-07-20 18:00:38 +02:00
|
|
|
import Text.Pandoc.Readers.Txt2Tags (getT2TMeta)
|
2014-07-31 21:00:21 +02:00
|
|
|
import Data.Monoid
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2015-02-18 20:57:30 +01:00
|
|
|
import Text.Pandoc.Error
|
|
|
|
|
2014-08-01 01:26:48 +02:00
|
|
|
type Transform = Pandoc -> Pandoc
|
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
copyrightMessage :: String
|
2014-08-30 17:16:00 +02:00
|
|
|
copyrightMessage = intercalate "\n" [
|
2014-08-04 16:08:12 +02:00
|
|
|
"",
|
2015-04-26 19:18:29 +02:00
|
|
|
"Copyright (C) 2006-2015 John MacFarlane",
|
2014-08-04 16:08:12 +02:00
|
|
|
"Web: http://johnmacfarlane.net/pandoc",
|
|
|
|
"This is free software; see the source for copying conditions.",
|
|
|
|
"There is no warranty, not even for merchantability or fitness",
|
|
|
|
"for a particular purpose." ]
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2008-08-04 01:33:40 +02:00
|
|
|
compileInfo :: String
|
2008-08-04 05:15:34 +02:00
|
|
|
compileInfo =
|
2013-08-25 07:27:08 +02:00
|
|
|
"\nCompiled with texmath " ++
|
2012-02-12 01:21:37 +01:00
|
|
|
VERSION_texmath ++ ", highlighting-kate " ++ VERSION_highlighting_kate ++
|
2011-12-29 23:17:10 +01:00
|
|
|
".\nSyntax highlighting is supported for the following languages:\n " ++
|
2013-02-08 04:58:28 +01:00
|
|
|
wrapWords 4 78
|
|
|
|
[map toLower l | l <- languages, l /= "Alert" && l /= "Alert_indent"]
|
2008-02-09 04:22:01 +01:00
|
|
|
|
2008-09-30 22:16:03 +02:00
|
|
|
-- | Converts a list of strings into a single string with the items printed as
|
|
|
|
-- comma separated words in lines with a maximum line length.
|
2011-12-29 22:53:25 +01:00
|
|
|
wrapWords :: Int -> Int -> [String] -> String
|
|
|
|
wrapWords indent c = wrap' (c - indent) (c - indent)
|
2014-08-04 16:08:12 +02:00
|
|
|
where
|
|
|
|
wrap' _ _ [] = ""
|
|
|
|
wrap' cols remaining (x:xs)
|
|
|
|
| remaining == cols =
|
|
|
|
x ++ wrap' cols (remaining - length x) xs
|
|
|
|
| (length x + 1) > remaining =
|
|
|
|
",\n" ++ replicate indent ' ' ++ x ++
|
|
|
|
wrap' cols (cols - length x) xs
|
|
|
|
| otherwise =
|
|
|
|
", " ++ x ++
|
|
|
|
wrap' cols (remaining - length x - 2) xs
|
2008-02-09 04:21:19 +01:00
|
|
|
|
2012-08-10 05:19:06 +02:00
|
|
|
isTextFormat :: String -> Bool
|
2014-08-04 16:08:12 +02:00
|
|
|
isTextFormat s = takeWhile (`notElem` "+-") s `notElem` binaries
|
|
|
|
where binaries = ["odt","docx","epub","epub3"]
|
2008-08-01 01:16:02 +02:00
|
|
|
|
2013-08-09 00:15:58 +02:00
|
|
|
externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
|
2013-08-24 21:54:39 +02:00
|
|
|
externalFilter f args' d = do
|
2014-08-17 19:33:18 +02:00
|
|
|
mbexe <- if '/' `elem` f
|
|
|
|
-- don't check PATH if filter name has a path
|
2014-06-28 03:30:57 +02:00
|
|
|
then return Nothing
|
2014-08-17 19:33:18 +02:00
|
|
|
-- we catch isDoesNotExistError because this will
|
|
|
|
-- be triggered if PATH not set:
|
|
|
|
else E.catch (findExecutable f)
|
|
|
|
(\e -> if isDoesNotExistError e
|
|
|
|
then return Nothing
|
|
|
|
else throwIO e)
|
2014-04-06 00:51:04 +02:00
|
|
|
(f', args'') <- case mbexe of
|
|
|
|
Just x -> return (x, args')
|
|
|
|
Nothing -> do
|
|
|
|
exists <- doesFileExist f
|
|
|
|
if exists
|
2014-06-30 23:03:47 +02:00
|
|
|
then do
|
|
|
|
isExecutable <- executable `fmap`
|
|
|
|
getPermissions f
|
|
|
|
return $
|
2014-04-06 00:51:04 +02:00
|
|
|
case map toLower $ takeExtension f of
|
2014-06-30 23:03:47 +02:00
|
|
|
_ | isExecutable -> (f, args')
|
2014-04-06 00:51:04 +02:00
|
|
|
".py" -> ("python", f:args')
|
|
|
|
".hs" -> ("runhaskell", f:args')
|
|
|
|
".pl" -> ("perl", f:args')
|
|
|
|
".rb" -> ("ruby", f:args')
|
|
|
|
".php" -> ("php", f:args')
|
|
|
|
_ -> (f, args')
|
|
|
|
else err 85 $ "Filter " ++ f ++ " not found"
|
2013-08-24 21:54:39 +02:00
|
|
|
(exitcode, outbs, errbs) <- E.handle filterException $
|
2014-04-06 00:51:04 +02:00
|
|
|
pipeProcess Nothing f' args'' $ encode d
|
2013-08-14 22:02:54 +02:00
|
|
|
when (not $ B.null errbs) $ B.hPutStr stderr errbs
|
2013-08-09 00:15:58 +02:00
|
|
|
case exitcode of
|
|
|
|
ExitSuccess -> return $ either error id $ eitherDecode' outbs
|
2013-08-24 21:54:39 +02:00
|
|
|
ExitFailure _ -> err 83 $ "Error running filter " ++ f
|
|
|
|
where filterException :: E.SomeException -> IO a
|
2013-09-18 06:38:34 +02:00
|
|
|
filterException e = err 83 $ "Error running filter " ++ f ++ "\n" ++
|
2014-06-21 08:08:00 +02:00
|
|
|
show e
|
2013-08-08 20:09:00 +02:00
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
-- | Data structure for command line options.
|
|
|
|
data Opt = Opt
|
2009-01-31 18:13:41 +01:00
|
|
|
{ optTabStop :: Int -- ^ Number of spaces per tab
|
2009-04-08 22:19:50 +02:00
|
|
|
, optPreserveTabs :: Bool -- ^ Preserve tabs instead of converting to spaces
|
2006-12-30 23:51:49 +01:00
|
|
|
, optStandalone :: Bool -- ^ Include header, footer
|
2006-12-28 03:20:09 +01:00
|
|
|
, optReader :: String -- ^ Reader format
|
|
|
|
, optWriter :: String -- ^ Writer format
|
2006-12-30 23:51:49 +01:00
|
|
|
, optParseRaw :: Bool -- ^ Parse unconvertable HTML and TeX
|
2007-07-07 07:43:23 +02:00
|
|
|
, optTableOfContents :: Bool -- ^ Include table of contents
|
2014-08-01 01:26:48 +02:00
|
|
|
, optTransforms :: [Transform] -- ^ Doc transforms to apply
|
2011-07-23 07:15:25 +02:00
|
|
|
, optTemplate :: Maybe FilePath -- ^ Custom template
|
2009-12-31 02:09:56 +01:00
|
|
|
, optVariables :: [(String,String)] -- ^ Template variables to set
|
2013-09-18 06:04:27 +02:00
|
|
|
, optMetadata :: M.Map String MetaValue -- ^ Metadata fields to set
|
2006-12-22 21:16:03 +01:00
|
|
|
, optOutputFile :: String -- ^ Name of output file
|
2006-12-30 23:51:49 +01:00
|
|
|
, optNumberSections :: Bool -- ^ Number sections in LaTeX
|
2013-03-16 22:48:37 +01:00
|
|
|
, optNumberOffset :: [Int] -- ^ Starting number for sections
|
2010-07-16 04:01:00 +02:00
|
|
|
, optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
|
2012-05-24 10:31:18 +02:00
|
|
|
, optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
|
2011-11-22 00:24:28 +01:00
|
|
|
, optSelfContained :: Bool -- ^ Make HTML accessible offline
|
2006-12-30 23:51:49 +01:00
|
|
|
, optSmart :: Bool -- ^ Use smart typography
|
2012-01-01 22:48:28 +01:00
|
|
|
, optOldDashes :: Bool -- ^ Parse dashes like pandoc <=1.8.2.1
|
2011-01-12 05:37:06 +01:00
|
|
|
, optHtml5 :: Bool -- ^ Produce HTML5 in HTML
|
2013-01-16 03:50:36 +01:00
|
|
|
, optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
|
2011-12-28 08:46:23 +01:00
|
|
|
, optHighlight :: Bool -- ^ Highlight source code
|
|
|
|
, optHighlightStyle :: Style -- ^ Style to use for highlighted code
|
2011-01-16 17:57:32 +01:00
|
|
|
, optChapters :: Bool -- ^ Use chapter for top-level sects
|
2007-12-01 04:11:52 +01:00
|
|
|
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
|
2009-12-31 23:40:59 +01:00
|
|
|
, optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
|
2012-01-03 21:10:10 +01:00
|
|
|
, optReferenceDocx :: Maybe FilePath -- ^ Path of reference.docx
|
2013-01-05 07:44:18 +01:00
|
|
|
, optEpubStylesheet :: Maybe String -- ^ EPUB stylesheet
|
|
|
|
, optEpubMetadata :: String -- ^ EPUB metadata
|
|
|
|
, optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
|
|
|
|
, optEpubChapterLevel :: Int -- ^ Header level at which to split chapters
|
2013-01-05 21:03:05 +01:00
|
|
|
, optTOCDepth :: Int -- ^ Number of levels to include in TOC
|
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-01-08 09:11:08 +01:00
|
|
|
, optDumpArgs :: Bool -- ^ Output command-line arguments
|
|
|
|
, optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
|
2014-12-26 19:19:55 +01:00
|
|
|
, optVerbose :: Bool -- ^ Verbose diagnostic output
|
Extensive changes stemming from a rethinking of the Pandoc data
structure. Key and Note blocks have been removed. Link and image URLs
are now stored directly in Link and Image inlines, and note blocks
are stored in Note inlines. This requires changes in both parsers
and writers. Markdown and RST parsers need to extract data from key
and note blocks and insert them into the relevant inline elements.
Other parsers can be simplified, since there is no longer any need to
construct separate key and note blocks. Markdown, RST, and HTML writers
need to construct lists of notes; Markdown and RST writers need to
construct lists of link references (when the --reference-links option
is specified); and the RST writer needs to construct a list of image
substitution references. All writers have been rewritten to use the
State monad when state is required. This rewrite yields a small speed
boost and considerably cleaner code.
* Text/Pandoc/Definition.hs:
+ blocks: removed Key and Note
+ inlines: removed NoteRef, added Note
+ modified Target: there is no longer a 'Ref' target; all targets
are explicit URL, title pairs
* Text/Pandoc/Shared.hs:
+ Added 'Reference', 'isNoteBlock', 'isKeyBlock', 'isLineClump',
used in some of the readers.
+ Removed 'generateReference', 'keyTable', 'replaceReferenceLinks',
'replaceRefLinksBlockList', along with some auxiliary functions
used only by them. These are no longer needed, since
reference links are resolved in the Markdown and RST readers.
+ Moved 'inTags', 'selfClosingTag', 'inTagsSimple', and 'inTagsIndented'
to the Docbook writer, since that is now the only module that uses
them.
+ Changed name of 'escapeSGMLString' to 'escapeStringForXML'
+ Added KeyTable and NoteTable types
+ Removed fields from ParserState; 'stateKeyBlocks', 'stateKeysUsed',
'stateNoteBlocks', 'stateNoteIdentifiers', 'stateInlineLinks'.
Added 'stateKeys' and 'stateNotes'.
+ Added clause for Note to 'prettyBlock'.
+ Added 'writerNotes', 'writerReferenceLinks' fields to WriterOptions.
* Text/Pandoc/Entities.hs: Renamed 'escapeSGMLChar' and
'escapeSGMLString' to 'escapeCharForXML' and 'escapeStringForXML'
* Text/ParserCombinators/Pandoc.hs: Added lineClump parser: parses a raw
line block up to and including following blank lines.
* Main.hs: Replaced --inline-links with --reference-links.
* README:
+ Documented --reference-links and removed description of --inline-links.
+ Added note that footnotes may occur anywhere in the document, but must
be at the outer level, not embedded in block elements.
* man/man1/pandoc.1, man/man1/html2markdown.1: Removed --inline-links
option, added --reference-links option
* Markdown and RST readers:
+ Rewrote to fit new Pandoc definition. Since there are no longer
Note or Key blocks, all note and key blocks are parsed on a first pass
through the document. Once tables of notes and keys have been constructed,
the remaining parts of the document are reassembled and parsed.
+ Refactored link parsers.
* LaTeX and HTML readers: Rewrote to fit new Pandoc definition. Since
there are no longer Note or Key blocks, notes and references can be
parsed in a single pass through the document.
* RST, Markdown, and HTML writers: Rewrote using state monad new Pandoc
and definition. State is used to hold lists of references footnotes to
and be printed at the end of the document.
* RTF and LaTeX writers: Rewrote using new Pandoc definition. (Because
of the different treatment of footnotes, the "notes" parameter is no
longer needed in the block and inline conversion functions.)
* Docbook writer:
+ Moved the functions 'attributeList', 'inTags', 'selfClosingTag',
'inTagsSimple', 'inTagsIndented' from Text/Pandoc/Shared, since
they are now used only by the Docbook writer.
+ Rewrote using new Pandoc definition. (Because of the different
treatment of footnotes, the "notes" parameter is no longer needed
in the block and inline conversion functions.)
* Updated test suite
* Throughout: old haskell98 module names replaced by hierarchical module
names, e.g. List by Data.List.
* debian/control: Include libghc6-xhtml-dev instead of libghc6-html-dev
in "Build-Depends."
* cabalize:
+ Remove haskell98 from BASE_DEPENDS (since now the new hierarchical
module names are being used throughout)
+ Added mtl to BASE_DEPENDS (needed for state monad)
+ Removed html from GHC66_DEPENDS (not needed since xhtml is now used)
git-svn-id: https://pandoc.googlecode.com/svn/trunk@580 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-04-10 03:56:50 +02:00
|
|
|
, optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
|
2007-09-27 03:23:44 +02:00
|
|
|
, optWrapText :: Bool -- ^ Wrap text
|
2010-12-13 05:09:14 +01:00
|
|
|
, optColumns :: Int -- ^ Line length in characters
|
2013-09-11 05:23:03 +02:00
|
|
|
, optFilters :: [FilePath] -- ^ Filters to apply
|
2009-01-24 20:58:48 +01:00
|
|
|
, optEmailObfuscation :: ObfuscationMethod
|
2009-12-05 18:56:02 +01:00
|
|
|
, optIdentifierPrefix :: String
|
2009-12-05 05:46:57 +01:00
|
|
|
, optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
|
2010-01-14 06:54:38 +01:00
|
|
|
, optDataDir :: Maybe FilePath
|
2010-12-13 21:18:01 +01:00
|
|
|
, optCiteMethod :: CiteMethod -- ^ Method to output cites
|
2011-01-17 23:54:51 +01:00
|
|
|
, optListings :: Bool -- ^ Use listings package for code blocks
|
2012-01-21 23:46:27 +01:00
|
|
|
, optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
|
2015-03-04 10:55:56 +01:00
|
|
|
, optLaTeXEngineArgs :: [String] -- ^ Flags to pass to the latex-engine
|
2012-01-26 02:50:03 +01:00
|
|
|
, optSlideLevel :: Maybe Int -- ^ Header level that creates slides
|
2012-01-27 08:55:37 +01:00
|
|
|
, optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
|
2012-02-05 23:58:55 +01:00
|
|
|
, optAscii :: Bool -- ^ Use ascii characters only in html
|
2012-05-12 07:58:49 +02:00
|
|
|
, optTeXLigatures :: Bool -- ^ Use TeX ligatures for quotes/dashes
|
2013-02-06 05:08:00 +01:00
|
|
|
, optDefaultImageExtension :: String -- ^ Default image extension
|
2014-07-30 20:44:25 +02:00
|
|
|
, optExtractMedia :: Maybe FilePath -- ^ Path to extract embedded media
|
2014-02-26 07:43:58 +01:00
|
|
|
, optTrace :: Bool -- ^ Print debug information
|
2014-07-20 18:00:38 +02:00
|
|
|
, optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
|
2014-09-25 19:23:28 +02:00
|
|
|
, optKaTeXStylesheet :: Maybe String -- ^ Path to stylesheet for KaTeX
|
|
|
|
, optKaTeXJS :: Maybe String -- ^ Path to js file for KaTeX
|
2006-10-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
-- | Defaults for command-line options.
|
2006-12-28 03:20:09 +01:00
|
|
|
defaultOpts :: Opt
|
|
|
|
defaultOpts = Opt
|
2013-02-06 05:08:00 +01:00
|
|
|
{ optTabStop = 4
|
|
|
|
, optPreserveTabs = False
|
|
|
|
, optStandalone = False
|
|
|
|
, optReader = "" -- null for default reader
|
|
|
|
, optWriter = "" -- null for default writer
|
|
|
|
, optParseRaw = False
|
|
|
|
, optTableOfContents = False
|
|
|
|
, optTransforms = []
|
|
|
|
, optTemplate = Nothing
|
|
|
|
, optVariables = []
|
2013-09-18 06:04:27 +02:00
|
|
|
, optMetadata = M.empty
|
2013-02-06 05:08:00 +01:00
|
|
|
, optOutputFile = "-" -- "-" means stdout
|
|
|
|
, optNumberSections = False
|
2013-03-16 22:48:37 +01:00
|
|
|
, optNumberOffset = [0,0,0,0,0,0]
|
2013-02-06 05:08:00 +01:00
|
|
|
, optSectionDivs = False
|
|
|
|
, optIncremental = False
|
|
|
|
, optSelfContained = False
|
|
|
|
, optSmart = False
|
|
|
|
, optOldDashes = False
|
|
|
|
, optHtml5 = False
|
|
|
|
, optHtmlQTags = False
|
|
|
|
, optHighlight = True
|
|
|
|
, optHighlightStyle = pygments
|
|
|
|
, optChapters = False
|
|
|
|
, optHTMLMathMethod = PlainMath
|
|
|
|
, optReferenceODT = Nothing
|
|
|
|
, optReferenceDocx = Nothing
|
|
|
|
, optEpubStylesheet = Nothing
|
|
|
|
, optEpubMetadata = ""
|
|
|
|
, optEpubFonts = []
|
|
|
|
, optEpubChapterLevel = 1
|
|
|
|
, optTOCDepth = 3
|
|
|
|
, optDumpArgs = False
|
|
|
|
, optIgnoreArgs = False
|
2014-12-26 19:19:55 +01:00
|
|
|
, optVerbose = False
|
2013-02-06 05:08:00 +01:00
|
|
|
, optReferenceLinks = False
|
|
|
|
, optWrapText = True
|
|
|
|
, optColumns = 72
|
2013-09-11 05:23:03 +02:00
|
|
|
, optFilters = []
|
2013-02-06 05:08:00 +01:00
|
|
|
, optEmailObfuscation = JavascriptObfuscation
|
|
|
|
, optIdentifierPrefix = ""
|
|
|
|
, optIndentedCodeClasses = []
|
|
|
|
, optDataDir = Nothing
|
|
|
|
, optCiteMethod = Citeproc
|
|
|
|
, optListings = False
|
|
|
|
, optLaTeXEngine = "pdflatex"
|
2015-03-04 10:55:56 +01:00
|
|
|
, optLaTeXEngineArgs = []
|
2013-02-06 05:08:00 +01:00
|
|
|
, optSlideLevel = Nothing
|
|
|
|
, optSetextHeaders = True
|
|
|
|
, optAscii = False
|
|
|
|
, optTeXLigatures = True
|
|
|
|
, optDefaultImageExtension = ""
|
2014-07-30 20:44:25 +02:00
|
|
|
, optExtractMedia = Nothing
|
2014-02-26 07:43:58 +01:00
|
|
|
, optTrace = False
|
2014-06-25 20:09:01 +02:00
|
|
|
, optTrackChanges = AcceptChanges
|
2014-09-25 19:23:28 +02:00
|
|
|
, optKaTeXStylesheet = Nothing
|
|
|
|
, optKaTeXJS = Nothing
|
2006-10-17 16:22:29 +02:00
|
|
|
}
|
|
|
|
|
2006-12-28 03:20:09 +01:00
|
|
|
-- | A list of functions, each transforming the options data structure
|
|
|
|
-- in response to a command-line option.
|
|
|
|
options :: [OptDescr (Opt -> IO Opt)]
|
|
|
|
options =
|
2006-12-22 21:16:03 +01:00
|
|
|
[ Option "fr" ["from","read"]
|
2006-10-17 16:22:29 +02:00
|
|
|
(ReqArg
|
2014-04-28 05:38:15 +02:00
|
|
|
(\arg opt -> return opt { optReader = arg })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FORMAT")
|
2010-12-11 02:30:32 +01:00
|
|
|
""
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
, Option "tw" ["to","write"]
|
|
|
|
(ReqArg
|
2014-04-28 05:38:15 +02:00
|
|
|
(\arg opt -> return opt { optWriter = arg })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FORMAT")
|
2010-12-11 02:30:32 +01:00
|
|
|
""
|
2008-08-10 19:33:20 +02:00
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
, Option "o" ["output"]
|
|
|
|
(ReqArg
|
2006-12-28 03:20:09 +01:00
|
|
|
(\arg opt -> return opt { optOutputFile = arg })
|
2006-12-22 21:16:03 +01:00
|
|
|
"FILENAME")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Name of output file"
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "" ["data-dir"]
|
2006-10-17 16:22:29 +02:00
|
|
|
(ReqArg
|
2012-01-26 07:45:49 +01:00
|
|
|
(\arg opt -> return opt { optDataDir = Just arg })
|
|
|
|
"DIRECTORY") -- "Directory containing pandoc data files."
|
|
|
|
""
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-12-30 23:51:49 +01:00
|
|
|
, Option "" ["strict"]
|
|
|
|
(NoArg
|
2012-08-10 05:19:06 +02:00
|
|
|
(\opt -> do
|
|
|
|
err 59 $ "The --strict option has been removed.\n" ++
|
2012-08-10 07:30:44 +02:00
|
|
|
"Use `markdown_strict' input or output format instead."
|
2012-08-10 05:19:06 +02:00
|
|
|
return opt ))
|
2007-07-22 21:20:21 +02:00
|
|
|
"" -- "Disable markdown syntax extensions"
|
2006-12-30 23:51:49 +01:00
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
, Option "R" ["parse-raw"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optParseRaw = True }))
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Parse untranslatable HTML codes and LaTeX environments as raw"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-12-18 23:02:39 +01:00
|
|
|
, Option "S" ["smart"]
|
2006-10-17 16:22:29 +02:00
|
|
|
(NoArg
|
2006-12-18 23:02:39 +01:00
|
|
|
(\opt -> return opt { optSmart = True }))
|
2007-01-06 10:54:58 +01:00
|
|
|
"" -- "Use smart quotes, dashes, and ellipses"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2012-01-01 22:48:28 +01:00
|
|
|
, Option "" ["old-dashes"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optSmart = True
|
|
|
|
, optOldDashes = True }))
|
|
|
|
"" -- "Use smart quotes, dashes, and ellipses"
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "" ["base-header-level"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt ->
|
2012-08-09 17:11:28 +02:00
|
|
|
case safeRead arg of
|
|
|
|
Just t | t > 0 -> do
|
2012-01-26 07:45:49 +01:00
|
|
|
let oldTransforms = optTransforms opt
|
|
|
|
let shift = t - 1
|
|
|
|
return opt{ optTransforms =
|
|
|
|
headerShift shift : oldTransforms }
|
2012-08-09 17:11:28 +02:00
|
|
|
_ -> err 19
|
2012-01-26 07:45:49 +01:00
|
|
|
"base-header-level must be a number > 0")
|
|
|
|
"NUMBER")
|
|
|
|
"" -- "Headers base level"
|
|
|
|
|
|
|
|
, Option "" ["indented-code-classes"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> return opt { optIndentedCodeClasses = words $
|
|
|
|
map (\c -> if c == ',' then ' ' else c) arg })
|
|
|
|
"STRING")
|
|
|
|
"" -- "Classes (whitespace- or comma-separated) to use for indented code-blocks"
|
|
|
|
|
2013-08-25 16:47:22 +02:00
|
|
|
, Option "F" ["filter"]
|
2013-08-08 20:09:00 +02:00
|
|
|
(ReqArg
|
2013-09-11 05:23:03 +02:00
|
|
|
(\arg opt -> return opt { optFilters = arg : optFilters opt })
|
2013-08-08 20:09:00 +02:00
|
|
|
"PROGRAM")
|
|
|
|
"" -- "External JSON filter"
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "" ["normalize"]
|
2011-01-12 05:37:06 +01:00
|
|
|
(NoArg
|
2012-01-26 07:45:49 +01:00
|
|
|
(\opt -> return opt { optTransforms =
|
|
|
|
normalize : optTransforms opt } ))
|
|
|
|
"" -- "Normalize the Pandoc AST"
|
|
|
|
|
|
|
|
, Option "p" ["preserve-tabs"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optPreserveTabs = True }))
|
|
|
|
"" -- "Preserve tabs instead of converting to spaces"
|
|
|
|
|
|
|
|
, Option "" ["tab-stop"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt ->
|
2012-08-09 17:11:28 +02:00
|
|
|
case safeRead arg of
|
|
|
|
Just t | t > 0 -> return opt { optTabStop = t }
|
|
|
|
_ -> err 31
|
2012-01-26 07:45:49 +01:00
|
|
|
"tab-stop must be a number greater than 0")
|
|
|
|
"NUMBER")
|
|
|
|
"" -- "Tab stop (default 4)"
|
|
|
|
|
2014-07-30 20:44:25 +02:00
|
|
|
, Option "" ["track-changes"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
action <- case arg of
|
|
|
|
"accept" -> return AcceptChanges
|
|
|
|
"reject" -> return RejectChanges
|
|
|
|
"all" -> return AllChanges
|
|
|
|
_ -> err 6
|
|
|
|
("Unknown option for track-changes: " ++ arg)
|
|
|
|
return opt { optTrackChanges = action })
|
|
|
|
"accept|reject|all")
|
|
|
|
"" -- "Accepting or reject MS Word track-changes.""
|
|
|
|
|
|
|
|
, Option "" ["extract-media"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
return opt { optExtractMedia = Just arg })
|
|
|
|
"PATH")
|
|
|
|
"" -- "Directory to which to extract embedded media"
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "s" ["standalone"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optStandalone = True }))
|
|
|
|
"" -- "Include needed header and footer on output"
|
|
|
|
|
|
|
|
, Option "" ["template"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
return opt{ optTemplate = Just arg,
|
|
|
|
optStandalone = True })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "Use custom template"
|
|
|
|
|
2013-09-02 00:37:02 +02:00
|
|
|
, Option "M" ["metadata"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
let (key,val) = case break (`elem` ":=") arg of
|
2013-09-20 05:21:35 +02:00
|
|
|
(k,_:v) -> (k, readMetaValue v)
|
2013-09-02 01:22:40 +02:00
|
|
|
(k,_) -> (k, MetaBool True)
|
2013-09-18 06:04:27 +02:00
|
|
|
return opt{ optMetadata = addMetadata key val
|
|
|
|
$ optMetadata opt })
|
2013-09-02 00:37:02 +02:00
|
|
|
"KEY[:VALUE]")
|
|
|
|
""
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "V" ["variable"]
|
|
|
|
(ReqArg
|
2012-03-09 19:45:01 +01:00
|
|
|
(\arg opt -> do
|
|
|
|
let (key,val) = case break (`elem` ":=") arg of
|
|
|
|
(k,_:v) -> (k,v)
|
|
|
|
(k,_) -> (k,"true")
|
2012-07-04 06:57:35 +02:00
|
|
|
return opt{ optVariables = (key,val) : optVariables opt })
|
2012-03-09 19:45:01 +01:00
|
|
|
"KEY[:VALUE]")
|
2013-09-02 00:37:02 +02:00
|
|
|
""
|
2012-01-26 07:45:49 +01:00
|
|
|
|
|
|
|
, Option "D" ["print-default-template"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg _ -> do
|
|
|
|
templ <- getDefaultTemplate Nothing arg
|
|
|
|
case templ of
|
2012-09-24 07:53:34 +02:00
|
|
|
Right t -> UTF8.hPutStr stdout t
|
2012-01-26 07:45:49 +01:00
|
|
|
Left e -> error $ show e
|
|
|
|
exitWith ExitSuccess)
|
|
|
|
"FORMAT")
|
|
|
|
"" -- "Print default template for FORMAT"
|
|
|
|
|
2013-08-14 03:25:20 +02:00
|
|
|
, Option "" ["print-default-data-file"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg _ -> do
|
|
|
|
readDataFile Nothing arg >>= BS.hPutStr stdout
|
|
|
|
exitWith ExitSuccess)
|
|
|
|
"FILE")
|
|
|
|
"" -- "Print default data file"
|
2013-04-03 06:08:38 +02:00
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "" ["no-wrap"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optWrapText = False }))
|
|
|
|
"" -- "Do not wrap text in output"
|
|
|
|
|
|
|
|
, Option "" ["columns"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt ->
|
2012-08-09 17:11:28 +02:00
|
|
|
case safeRead arg of
|
|
|
|
Just t | t > 0 -> return opt { optColumns = t }
|
|
|
|
_ -> err 33 $
|
2012-01-26 07:45:49 +01:00
|
|
|
"columns must be a number greater than 0")
|
|
|
|
"NUMBER")
|
|
|
|
"" -- "Length of line in characters"
|
|
|
|
|
|
|
|
, Option "" ["toc", "table-of-contents"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optTableOfContents = True }))
|
|
|
|
"" -- "Include table of contents"
|
2011-01-12 05:37:06 +01:00
|
|
|
|
2013-01-05 21:03:05 +01:00
|
|
|
, Option "" ["toc-depth"]
|
2013-01-05 20:34:23 +01:00
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
case safeRead arg of
|
|
|
|
Just t | t >= 1 && t <= 6 ->
|
2013-07-03 21:47:35 +02:00
|
|
|
return opt { optTOCDepth = t }
|
2013-01-05 20:34:23 +01:00
|
|
|
_ -> err 57 $
|
|
|
|
"TOC level must be a number between 1 and 6")
|
|
|
|
"NUMBER")
|
|
|
|
"" -- "Number of levels to include in TOC"
|
|
|
|
|
2011-12-28 08:46:23 +01:00
|
|
|
, Option "" ["no-highlight"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optHighlight = False }))
|
|
|
|
"" -- "Don't highlight source code"
|
|
|
|
|
|
|
|
, Option "" ["highlight-style"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
newStyle <- case map toLower arg of
|
|
|
|
"pygments" -> return pygments
|
|
|
|
"tango" -> return tango
|
|
|
|
"espresso" -> return espresso
|
2012-05-18 03:54:41 +02:00
|
|
|
"zenburn" -> return zenburn
|
2011-12-28 08:46:23 +01:00
|
|
|
"kate" -> return kate
|
|
|
|
"monochrome" -> return monochrome
|
|
|
|
"haddock" -> return haddock
|
2012-01-21 07:12:03 +01:00
|
|
|
_ -> err 39 $
|
|
|
|
"Unknown style :" ++ arg
|
2011-12-28 08:46:23 +01:00
|
|
|
return opt{ optHighlightStyle = newStyle })
|
|
|
|
"STYLE")
|
|
|
|
"" -- "Style for highlighted code"
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "H" ["include-in-header"]
|
|
|
|
(ReqArg
|
2010-07-16 04:01:00 +02:00
|
|
|
(\arg opt -> do
|
2012-09-23 21:33:17 +02:00
|
|
|
text <- UTF8.readFile arg
|
2012-01-26 07:45:49 +01:00
|
|
|
-- add new ones to end, so they're included in order specified
|
|
|
|
let newvars = optVariables opt ++ [("header-includes",text)]
|
|
|
|
return opt { optVariables = newvars,
|
|
|
|
optStandalone = True })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "File to include at end of header (implies -s)"
|
2007-12-01 04:11:52 +01:00
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "B" ["include-before-body"]
|
|
|
|
(ReqArg
|
2010-07-16 04:01:00 +02:00
|
|
|
(\arg opt -> do
|
2012-09-23 21:33:17 +02:00
|
|
|
text <- UTF8.readFile arg
|
2012-01-26 07:45:49 +01:00
|
|
|
-- add new ones to end, so they're included in order specified
|
|
|
|
let newvars = optVariables opt ++ [("include-before",text)]
|
|
|
|
return opt { optVariables = newvars,
|
|
|
|
optStandalone = True })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "File to include before document body"
|
2008-10-28 22:54:50 +01:00
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "A" ["include-after-body"]
|
|
|
|
(ReqArg
|
2011-07-23 22:30:59 +02:00
|
|
|
(\arg opt -> do
|
2012-09-23 21:33:17 +02:00
|
|
|
text <- UTF8.readFile arg
|
2012-01-26 07:45:49 +01:00
|
|
|
-- add new ones to end, so they're included in order specified
|
|
|
|
let newvars = optVariables opt ++ [("include-after",text)]
|
|
|
|
return opt { optVariables = newvars,
|
|
|
|
optStandalone = True })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "File to include after document body"
|
2007-12-01 04:11:52 +01:00
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "" ["self-contained"]
|
2006-10-17 16:22:29 +02:00
|
|
|
(NoArg
|
2012-01-26 07:45:49 +01:00
|
|
|
(\opt -> return opt { optSelfContained = True,
|
|
|
|
optStandalone = True }))
|
|
|
|
"" -- "Make slide shows include all the needed js and css"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2010-07-23 06:50:17 +02:00
|
|
|
, Option "" ["offline"]
|
|
|
|
(NoArg
|
2012-01-21 18:55:37 +01:00
|
|
|
(\opt -> do warn $ "--offline is deprecated. Use --self-contained instead."
|
|
|
|
return opt { optSelfContained = True,
|
|
|
|
optStandalone = True }))
|
2011-11-22 00:24:28 +01:00
|
|
|
"" -- "Make slide shows include all the needed js and css"
|
|
|
|
-- deprecated synonym for --self-contained
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "5" ["html5"]
|
2011-11-22 00:24:28 +01:00
|
|
|
(NoArg
|
2012-01-26 07:45:49 +01:00
|
|
|
(\opt -> do
|
|
|
|
warn $ "--html5 is deprecated. "
|
|
|
|
++ "Use the html5 output format instead."
|
|
|
|
return opt { optHtml5 = True }))
|
|
|
|
"" -- "Produce HTML5 in HTML output"
|
|
|
|
|
2013-01-16 03:50:36 +01:00
|
|
|
, Option "" ["html-q-tags"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> do
|
|
|
|
return opt { optHtmlQTags = True }))
|
|
|
|
"" -- "Use <q> tags for quotes in HTML"
|
|
|
|
|
2012-02-05 23:58:55 +01:00
|
|
|
, Option "" ["ascii"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optAscii = True }))
|
|
|
|
"" -- "Use ascii characters only in HTML output"
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "" ["reference-links"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optReferenceLinks = True } ))
|
|
|
|
"" -- "Use reference links in parsing HTML"
|
2010-07-23 06:50:17 +02:00
|
|
|
|
2012-01-27 08:55:37 +01:00
|
|
|
, Option "" ["atx-headers"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optSetextHeaders = False } ))
|
|
|
|
"" -- "Use atx-style headers for markdown"
|
|
|
|
|
2011-01-16 18:34:26 +01:00
|
|
|
, Option "" ["chapters"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optChapters = True }))
|
|
|
|
"" -- "Use chapter for top-level sections in LaTeX, DocBook"
|
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
, Option "N" ["number-sections"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optNumberSections = True }))
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Number sections in LaTeX"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2013-02-24 03:11:05 +01:00
|
|
|
, Option "" ["number-offset"]
|
2013-02-22 06:40:06 +01:00
|
|
|
(ReqArg
|
|
|
|
(\arg opt ->
|
2013-02-24 03:11:05 +01:00
|
|
|
case safeRead ('[':arg ++ "]") of
|
|
|
|
Just ns -> return opt { optNumberOffset = ns,
|
|
|
|
optNumberSections = True }
|
|
|
|
_ -> err 57 "could not parse number-offset")
|
|
|
|
"NUMBERS")
|
|
|
|
"" -- "Starting number for sections, subsections, etc."
|
2013-02-22 06:40:06 +01:00
|
|
|
|
2012-05-12 07:58:49 +02:00
|
|
|
, Option "" ["no-tex-ligatures"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optTeXLigatures = False }))
|
|
|
|
"" -- "Don't use tex ligatures for quotes, dashes"
|
|
|
|
|
2011-01-17 23:54:51 +01:00
|
|
|
, Option "" ["listings"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optListings = True }))
|
|
|
|
"" -- "Use listings package for LaTeX code blocks"
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "i" ["incremental"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optIncremental = True }))
|
2012-05-24 10:31:18 +02:00
|
|
|
"" -- "Make list items display incrementally in Slidy/Slideous/S5"
|
2012-01-26 07:45:49 +01:00
|
|
|
|
2012-01-26 02:50:03 +01:00
|
|
|
, Option "" ["slide-level"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2012-08-09 17:11:28 +02:00
|
|
|
case safeRead arg of
|
|
|
|
Just t | t >= 1 && t <= 6 ->
|
2012-01-26 02:50:03 +01:00
|
|
|
return opt { optSlideLevel = Just t }
|
2012-08-09 17:11:28 +02:00
|
|
|
_ -> err 39 $
|
2012-01-26 02:50:03 +01:00
|
|
|
"slide level must be a number between 1 and 6")
|
|
|
|
"NUMBER")
|
|
|
|
"" -- "Force header level for slides"
|
|
|
|
|
2010-07-16 04:01:00 +02:00
|
|
|
, Option "" ["section-divs"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optSectionDivs = True }))
|
|
|
|
"" -- "Put sections in div tags in HTML"
|
|
|
|
|
2013-02-06 05:08:00 +01:00
|
|
|
, Option "" ["default-image-extension"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> return opt { optDefaultImageExtension = arg })
|
|
|
|
"extension")
|
|
|
|
"" -- "Default extension for extensionless images"
|
|
|
|
|
2009-01-24 20:58:48 +01:00
|
|
|
, Option "" ["email-obfuscation"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
method <- case arg of
|
|
|
|
"references" -> return ReferenceObfuscation
|
|
|
|
"javascript" -> return JavascriptObfuscation
|
|
|
|
"none" -> return NoObfuscation
|
2012-01-21 07:12:03 +01:00
|
|
|
_ -> err 6
|
2012-01-22 00:13:12 +01:00
|
|
|
("Unknown obfuscation method: " ++ arg)
|
2009-01-24 20:58:48 +01:00
|
|
|
return opt { optEmailObfuscation = method })
|
|
|
|
"none|javascript|references")
|
|
|
|
"" -- "Method for obfuscating email in HTML"
|
|
|
|
|
2009-12-05 18:56:02 +01:00
|
|
|
, Option "" ["id-prefix"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> return opt { optIdentifierPrefix = arg })
|
|
|
|
"STRING")
|
|
|
|
"" -- "Prefix to add to automatically generated HTML identifiers"
|
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "T" ["title-prefix"]
|
2009-12-31 02:10:04 +01:00
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2012-01-26 07:45:49 +01:00
|
|
|
let newvars = ("title-prefix", arg) : optVariables opt
|
|
|
|
return opt { optVariables = newvars,
|
2009-12-31 02:10:04 +01:00
|
|
|
optStandalone = True })
|
2012-01-26 07:45:49 +01:00
|
|
|
"STRING")
|
|
|
|
"" -- "String to prefix to HTML window title"
|
2009-12-31 02:10:26 +01:00
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
, Option "c" ["css"]
|
|
|
|
(ReqArg
|
2008-08-10 19:33:20 +02:00
|
|
|
(\arg opt -> do
|
2009-12-31 02:15:50 +01:00
|
|
|
-- add new link to end, so it is included in proper order
|
|
|
|
let newvars = optVariables opt ++ [("css",arg)]
|
2009-12-31 02:10:32 +01:00
|
|
|
return opt { optVariables = newvars,
|
2008-01-08 21:21:28 +01:00
|
|
|
optStandalone = True })
|
2009-12-31 02:10:04 +01:00
|
|
|
"URL")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Link to CSS style sheet"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2009-12-31 23:40:59 +01:00
|
|
|
, Option "" ["reference-odt"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
return opt { optReferenceODT = Just arg })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "Path of custom reference.odt"
|
|
|
|
|
2012-01-03 21:10:10 +01:00
|
|
|
, Option "" ["reference-docx"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
return opt { optReferenceDocx = Just arg })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "Path of custom reference.docx"
|
|
|
|
|
2010-07-03 07:07:00 +02:00
|
|
|
, Option "" ["epub-stylesheet"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2015-05-09 08:46:02 +02:00
|
|
|
warn "--epub-stylesheet is deprecated. Use --css or stylesheet in metadata."
|
|
|
|
let newvars = optVariables opt ++ [("css",arg)]
|
|
|
|
return opt { optVariables = newvars,
|
|
|
|
optStandalone = True })
|
2010-07-03 07:07:00 +02:00
|
|
|
"FILENAME")
|
|
|
|
"" -- "Path of epub.css"
|
|
|
|
|
2011-03-09 08:25:01 +01:00
|
|
|
, Option "" ["epub-cover-image"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt ->
|
2011-04-16 18:53:11 +02:00
|
|
|
return opt { optVariables =
|
|
|
|
("epub-cover-image", arg) : optVariables opt })
|
2011-03-09 08:25:01 +01:00
|
|
|
"FILENAME")
|
|
|
|
"" -- "Path of epub cover image"
|
|
|
|
|
2010-07-05 01:56:17 +02:00
|
|
|
, Option "" ["epub-metadata"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2012-09-23 21:33:17 +02:00
|
|
|
text <- UTF8.readFile arg
|
2013-01-05 07:44:18 +01:00
|
|
|
return opt { optEpubMetadata = text })
|
2010-07-05 01:56:17 +02:00
|
|
|
"FILENAME")
|
|
|
|
"" -- "Path of epub metadata file"
|
|
|
|
|
2012-01-30 20:45:55 +01:00
|
|
|
, Option "" ["epub-embed-font"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2013-01-05 07:44:18 +01:00
|
|
|
return opt{ optEpubFonts = arg : optEpubFonts opt })
|
2012-01-30 20:45:55 +01:00
|
|
|
"FILE")
|
|
|
|
"" -- "Directory of fonts to embed"
|
|
|
|
|
2013-01-05 07:29:41 +01:00
|
|
|
, Option "" ["epub-chapter-level"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
case safeRead arg of
|
|
|
|
Just t | t >= 1 && t <= 6 ->
|
2013-01-05 07:44:18 +01:00
|
|
|
return opt { optEpubChapterLevel = t }
|
2013-01-05 07:29:41 +01:00
|
|
|
_ -> err 59 $
|
|
|
|
"chapter level must be a number between 1 and 6")
|
|
|
|
"NUMBER")
|
|
|
|
"" -- "Header level at which to split chapters in EPUB"
|
|
|
|
|
2012-01-21 23:46:27 +01:00
|
|
|
, Option "" ["latex-engine"]
|
2012-01-21 23:18:36 +01:00
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
let b = takeBaseName arg
|
2013-12-20 02:19:24 +01:00
|
|
|
if b `elem` ["pdflatex", "lualatex", "xelatex"]
|
2012-01-21 23:46:27 +01:00
|
|
|
then return opt { optLaTeXEngine = arg }
|
|
|
|
else err 45 "latex-engine must be pdflatex, lualatex, or xelatex.")
|
2012-01-21 23:18:36 +01:00
|
|
|
"PROGRAM")
|
|
|
|
"" -- "Name of latex program to use in generating PDF"
|
|
|
|
|
2015-03-04 10:55:56 +01:00
|
|
|
, Option "" ["latex-engine-opt"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
let oldArgs = optLaTeXEngineArgs opt
|
|
|
|
return opt { optLaTeXEngineArgs = arg : oldArgs })
|
|
|
|
"STRING")
|
|
|
|
"" -- "Flags to pass to the LaTeX engine, all instances of this option are accumulated and used"
|
|
|
|
|
2010-11-13 17:42:09 +01:00
|
|
|
, Option "" ["bibliography"]
|
2008-08-04 05:15:34 +02:00
|
|
|
(ReqArg
|
2013-09-18 06:04:27 +02:00
|
|
|
(\arg opt -> return opt{ optMetadata = addMetadata
|
2013-09-20 05:21:35 +02:00
|
|
|
"bibliography" (readMetaValue arg)
|
2013-09-18 06:04:27 +02:00
|
|
|
$ optMetadata opt
|
2014-01-03 19:11:21 +01:00
|
|
|
, optVariables =
|
|
|
|
("biblio-files", dropExtension arg) :
|
|
|
|
optVariables opt
|
2013-09-18 06:04:27 +02:00
|
|
|
})
|
2013-09-02 00:54:48 +02:00
|
|
|
"FILE")
|
2008-08-04 05:15:34 +02:00
|
|
|
""
|
2011-01-16 20:08:20 +01:00
|
|
|
|
2013-09-02 00:54:48 +02:00
|
|
|
, Option "" ["csl"]
|
2008-08-04 05:15:34 +02:00
|
|
|
(ReqArg
|
2013-09-02 00:54:48 +02:00
|
|
|
(\arg opt ->
|
2013-09-18 06:04:27 +02:00
|
|
|
return opt{ optMetadata = addMetadata "csl"
|
2013-09-20 05:21:35 +02:00
|
|
|
(readMetaValue arg)
|
2013-09-18 06:04:27 +02:00
|
|
|
$ optMetadata opt })
|
2013-09-02 00:54:48 +02:00
|
|
|
"FILE")
|
2008-08-04 05:15:34 +02:00
|
|
|
""
|
2011-01-16 20:08:20 +01:00
|
|
|
|
2013-09-02 00:54:48 +02:00
|
|
|
, Option "" ["citation-abbreviations"]
|
2011-11-12 02:36:57 +01:00
|
|
|
(ReqArg
|
2013-09-02 00:54:48 +02:00
|
|
|
(\arg opt ->
|
2013-09-18 06:04:27 +02:00
|
|
|
return opt{ optMetadata = addMetadata
|
|
|
|
"citation-abbreviations"
|
2013-09-20 05:21:35 +02:00
|
|
|
(readMetaValue arg)
|
2013-09-18 06:04:27 +02:00
|
|
|
$ optMetadata opt })
|
2013-09-02 00:54:48 +02:00
|
|
|
"FILE")
|
2011-11-12 02:36:57 +01:00
|
|
|
""
|
|
|
|
|
2011-01-16 20:08:37 +01:00
|
|
|
, Option "" ["natbib"]
|
2010-12-13 21:18:01 +01:00
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optCiteMethod = Natbib }))
|
|
|
|
"" -- "Use natbib cite commands in LaTeX output"
|
2011-01-16 20:08:20 +01:00
|
|
|
|
2010-12-13 21:18:01 +01:00
|
|
|
, Option "" ["biblatex"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optCiteMethod = Biblatex }))
|
|
|
|
"" -- "Use biblatex cite commands in LaTeX output"
|
2011-01-16 20:08:20 +01:00
|
|
|
|
2012-01-26 07:45:49 +01:00
|
|
|
, Option "m" ["latexmathml", "asciimathml"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt ->
|
|
|
|
return opt { optHTMLMathMethod = LaTeXMathML arg })
|
|
|
|
"URL")
|
|
|
|
"" -- "Use LaTeXMathML script in html output"
|
|
|
|
|
|
|
|
, Option "" ["mathml"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt ->
|
|
|
|
return opt { optHTMLMathMethod = MathML arg })
|
|
|
|
"URL")
|
|
|
|
"" -- "Use mathml for HTML math"
|
|
|
|
|
|
|
|
, Option "" ["mimetex"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt -> do
|
|
|
|
let url' = case arg of
|
|
|
|
Just u -> u ++ "?"
|
|
|
|
Nothing -> "/cgi-bin/mimetex.cgi?"
|
|
|
|
return opt { optHTMLMathMethod = WebTeX url' })
|
|
|
|
"URL")
|
|
|
|
"" -- "Use mimetex for HTML math"
|
|
|
|
|
|
|
|
, Option "" ["webtex"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt -> do
|
|
|
|
let url' = case arg of
|
|
|
|
Just u -> u
|
|
|
|
Nothing -> "http://chart.apis.google.com/chart?cht=tx&chl="
|
|
|
|
return opt { optHTMLMathMethod = WebTeX url' })
|
|
|
|
"URL")
|
|
|
|
"" -- "Use web service for HTML math"
|
|
|
|
|
|
|
|
, Option "" ["jsmath"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
|
|
|
|
"URL")
|
|
|
|
"" -- "Use jsMath for HTML math"
|
|
|
|
|
|
|
|
, Option "" ["mathjax"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt -> do
|
|
|
|
let url' = case arg of
|
|
|
|
Just u -> u
|
2014-08-31 20:18:43 +02:00
|
|
|
Nothing -> "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
|
2012-01-26 07:45:49 +01:00
|
|
|
return opt { optHTMLMathMethod = MathJax url'})
|
|
|
|
"URL")
|
|
|
|
"" -- "Use MathJax for HTML math"
|
2014-09-25 19:23:28 +02:00
|
|
|
, Option "" ["katex"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt ->
|
|
|
|
return opt
|
|
|
|
{ optKaTeXJS =
|
|
|
|
arg <|> Just "http://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.0/katex.min.js"})
|
|
|
|
"URL")
|
|
|
|
"" -- Use KaTeX for HTML Math
|
|
|
|
|
|
|
|
, Option "" ["katex-stylesheet"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt ->
|
|
|
|
return opt { optKaTeXStylesheet = Just arg })
|
|
|
|
"URL")
|
|
|
|
"" -- Set the KaTeX Stylesheet location
|
2012-01-26 07:45:49 +01:00
|
|
|
|
|
|
|
, Option "" ["gladtex"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optHTMLMathMethod = GladTeX }))
|
|
|
|
"" -- "Use gladtex for HTML math"
|
2010-01-14 06:54:38 +01:00
|
|
|
|
2014-02-26 07:43:58 +01:00
|
|
|
, Option "" ["trace"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optTrace = True }))
|
|
|
|
"" -- "Turn on diagnostic tracing in readers."
|
|
|
|
|
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-01-08 09:11:08 +01:00
|
|
|
, Option "" ["dump-args"]
|
2006-12-22 21:16:03 +01:00
|
|
|
(NoArg
|
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-01-08 09:11:08 +01:00
|
|
|
(\opt -> return opt { optDumpArgs = True }))
|
|
|
|
"" -- "Print output filename and arguments to stdout."
|
|
|
|
|
2008-08-04 05:15:34 +02:00
|
|
|
, Option "" ["ignore-args"]
|
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-01-08 09:11:08 +01:00
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optIgnoreArgs = True }))
|
|
|
|
"" -- "Ignore command-line arguments."
|
2008-08-10 19:33:20 +02:00
|
|
|
|
2014-12-26 19:19:55 +01:00
|
|
|
, Option "" ["verbose"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optVerbose = True }))
|
|
|
|
"" -- "Verbose diagnostic output."
|
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
, Option "v" ["version"]
|
|
|
|
(NoArg
|
|
|
|
(\_ -> do
|
|
|
|
prg <- getProgName
|
2013-02-08 04:58:28 +01:00
|
|
|
defaultDatadir <- getAppUserDataDirectory "pandoc"
|
|
|
|
UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++
|
2013-02-08 04:58:28 +01:00
|
|
|
compileInfo ++ "\nDefault user data directory: " ++
|
2013-02-08 04:58:28 +01:00
|
|
|
defaultDatadir ++ copyrightMessage)
|
2009-02-26 17:47:36 +01:00
|
|
|
exitWith ExitSuccess ))
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Print version"
|
2006-12-22 21:16:03 +01:00
|
|
|
|
|
|
|
, Option "h" ["help"]
|
|
|
|
(NoArg
|
2006-12-28 03:20:09 +01:00
|
|
|
(\_ -> do
|
|
|
|
prg <- getProgName
|
2012-09-24 07:53:34 +02:00
|
|
|
UTF8.hPutStr stdout (usageMessage prg options)
|
2009-02-26 17:47:36 +01:00
|
|
|
exitWith ExitSuccess ))
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Show help"
|
2012-01-26 07:45:49 +01:00
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
]
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2014-09-25 19:23:28 +02:00
|
|
|
|
2013-09-18 06:04:27 +02:00
|
|
|
addMetadata :: String -> MetaValue -> M.Map String MetaValue
|
|
|
|
-> M.Map String MetaValue
|
|
|
|
addMetadata k v m = case M.lookup k m of
|
|
|
|
Nothing -> M.insert k v m
|
|
|
|
Just (MetaList xs) -> M.insert k
|
|
|
|
(MetaList (xs ++ [v])) m
|
|
|
|
Just x -> M.insert k (MetaList [v, x]) m
|
|
|
|
|
2013-09-20 05:21:35 +02:00
|
|
|
readMetaValue :: String -> MetaValue
|
|
|
|
readMetaValue s = case decode (UTF8.fromString s) of
|
|
|
|
Just (Yaml.String t) -> MetaString $ T.unpack t
|
|
|
|
Just (Yaml.Bool b) -> MetaBool b
|
|
|
|
_ -> MetaString s
|
|
|
|
|
2006-12-31 02:12:01 +01:00
|
|
|
-- Returns usage message
|
|
|
|
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
|
2009-01-24 20:59:07 +01:00
|
|
|
usageMessage programName = usageInfo
|
2008-08-10 19:33:20 +02:00
|
|
|
(programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
|
2015-02-27 18:29:33 +01:00
|
|
|
(wrapWords 16 78 $ readers'names) ++
|
|
|
|
'\n' : replicate 16 ' ' ++
|
|
|
|
"[ *only Pandoc's JSON version of native AST]" ++ "\nOutput formats: " ++
|
2013-04-27 06:13:07 +02:00
|
|
|
(wrapWords 16 78 $ writers'names) ++
|
|
|
|
'\n' : replicate 16 ' ' ++
|
2015-02-27 18:29:33 +01:00
|
|
|
"[**for pdf output, use latex or beamer and -o FILENAME.pdf]\nOptions:")
|
2011-02-15 19:40:50 +01:00
|
|
|
where
|
2015-02-27 18:29:33 +01:00
|
|
|
writers'names = sort $ "json*" : "pdf**" : delete "json" (map fst writers)
|
|
|
|
readers'names = sort $ "json*" : delete "json" (map fst readers)
|
2008-08-10 19:33:20 +02:00
|
|
|
|
2006-12-28 03:20:09 +01:00
|
|
|
-- Determine default reader based on source file extensions
|
2010-03-18 07:45:50 +01:00
|
|
|
defaultReaderName :: String -> [FilePath] -> String
|
|
|
|
defaultReaderName fallback [] = fallback
|
|
|
|
defaultReaderName fallback (x:xs) =
|
2008-02-09 04:21:04 +01:00
|
|
|
case takeExtension (map toLower x) of
|
|
|
|
".xhtml" -> "html"
|
|
|
|
".html" -> "html"
|
|
|
|
".htm" -> "html"
|
|
|
|
".tex" -> "latex"
|
|
|
|
".latex" -> "latex"
|
|
|
|
".ltx" -> "latex"
|
|
|
|
".rst" -> "rst"
|
2014-03-04 00:33:25 +01:00
|
|
|
".org" -> "org"
|
2008-12-02 23:43:17 +01:00
|
|
|
".lhs" -> "markdown+lhs"
|
2012-04-15 06:56:16 +02:00
|
|
|
".db" -> "docbook"
|
2013-03-18 01:43:51 +01:00
|
|
|
".opml" -> "opml"
|
2012-09-10 19:02:12 +02:00
|
|
|
".wiki" -> "mediawiki"
|
2013-07-14 14:40:27 +02:00
|
|
|
".dokuwiki" -> "dokuwiki"
|
2010-12-04 07:15:51 +01:00
|
|
|
".textile" -> "textile"
|
2008-02-09 04:21:04 +01:00
|
|
|
".native" -> "native"
|
2010-12-13 05:30:26 +01:00
|
|
|
".json" -> "json"
|
2014-06-15 14:38:16 +02:00
|
|
|
".docx" -> "docx"
|
2014-07-14 00:38:22 +02:00
|
|
|
".t2t" -> "t2t"
|
2014-07-30 01:57:20 +02:00
|
|
|
".epub" -> "epub"
|
2014-10-20 01:59:31 +02:00
|
|
|
".odt" -> "odt" -- so we get an "unknown reader" error
|
|
|
|
".pdf" -> "pdf" -- so we get an "unknown reader" error
|
|
|
|
".doc" -> "doc" -- so we get an "unknown reader" error
|
2010-03-18 07:45:50 +01:00
|
|
|
_ -> defaultReaderName fallback xs
|
2006-12-28 03:20:09 +01:00
|
|
|
|
2008-12-02 23:41:51 +01:00
|
|
|
-- Returns True if extension of first source is .lhs
|
|
|
|
lhsExtension :: [FilePath] -> Bool
|
|
|
|
lhsExtension (x:_) = takeExtension x == ".lhs"
|
|
|
|
lhsExtension _ = False
|
|
|
|
|
2006-12-28 03:20:09 +01:00
|
|
|
-- Determine default writer based on output file extension
|
2008-02-09 04:21:04 +01:00
|
|
|
defaultWriterName :: FilePath -> String
|
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-01-08 09:11:08 +01:00
|
|
|
defaultWriterName "-" = "html" -- no output file
|
2006-12-28 03:20:09 +01:00
|
|
|
defaultWriterName x =
|
2008-02-09 04:21:04 +01:00
|
|
|
case takeExtension (map toLower x) of
|
2008-02-24 06:48:59 +01:00
|
|
|
"" -> "markdown" -- empty extension
|
|
|
|
".tex" -> "latex"
|
|
|
|
".latex" -> "latex"
|
|
|
|
".ltx" -> "latex"
|
|
|
|
".context" -> "context"
|
|
|
|
".ctx" -> "context"
|
|
|
|
".rtf" -> "rtf"
|
|
|
|
".rst" -> "rst"
|
|
|
|
".s5" -> "s5"
|
|
|
|
".native" -> "native"
|
2010-12-13 05:30:26 +01:00
|
|
|
".json" -> "json"
|
2008-02-24 06:48:59 +01:00
|
|
|
".txt" -> "markdown"
|
|
|
|
".text" -> "markdown"
|
|
|
|
".md" -> "markdown"
|
|
|
|
".markdown" -> "markdown"
|
2011-01-23 09:05:10 +01:00
|
|
|
".textile" -> "textile"
|
2008-12-02 23:43:17 +01:00
|
|
|
".lhs" -> "markdown+lhs"
|
2008-02-24 06:48:59 +01:00
|
|
|
".texi" -> "texinfo"
|
|
|
|
".texinfo" -> "texinfo"
|
|
|
|
".db" -> "docbook"
|
2008-08-01 01:16:02 +02:00
|
|
|
".odt" -> "odt"
|
2012-01-03 21:10:10 +01:00
|
|
|
".docx" -> "docx"
|
2010-07-03 07:07:00 +02:00
|
|
|
".epub" -> "epub"
|
2010-12-04 11:27:39 +01:00
|
|
|
".org" -> "org"
|
2011-11-16 23:52:10 +01:00
|
|
|
".asciidoc" -> "asciidoc"
|
2012-01-28 20:41:26 +01:00
|
|
|
".pdf" -> "latex"
|
2011-02-15 19:40:50 +01:00
|
|
|
".fb2" -> "fb2"
|
2013-03-20 04:35:14 +01:00
|
|
|
".opml" -> "opml"
|
2014-10-21 00:01:13 +02:00
|
|
|
".icml" -> "icml"
|
2008-06-17 20:55:42 +02:00
|
|
|
['.',y] | y `elem` ['1'..'9'] -> "man"
|
2014-08-04 16:08:12 +02:00
|
|
|
_ -> "html"
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2014-08-01 01:26:48 +02:00
|
|
|
-- Transformations of a Pandoc document post-parsing:
|
|
|
|
|
|
|
|
extractMedia :: MediaBag -> FilePath -> Pandoc -> IO Pandoc
|
|
|
|
extractMedia media dir d =
|
|
|
|
case [fp | (fp, _, _) <- mediaDirectory media] of
|
|
|
|
[] -> return d
|
|
|
|
fps -> do
|
|
|
|
extractMediaBag True dir media
|
|
|
|
return $ walk (adjustImagePath dir fps) d
|
|
|
|
|
|
|
|
adjustImagePath :: FilePath -> [FilePath] -> Inline -> Inline
|
|
|
|
adjustImagePath dir paths (Image lab (src, tit))
|
|
|
|
| src `elem` paths = Image lab (dir ++ "/" ++ src, tit)
|
|
|
|
adjustImagePath _ _ x = x
|
|
|
|
|
|
|
|
adjustMetadata :: M.Map String MetaValue -> Pandoc -> IO Pandoc
|
|
|
|
adjustMetadata metadata d = return $ M.foldWithKey setMeta d metadata
|
|
|
|
|
|
|
|
applyTransforms :: [Transform] -> Pandoc -> IO Pandoc
|
|
|
|
applyTransforms transforms d = return $ foldr ($) d transforms
|
|
|
|
|
|
|
|
applyFilters :: [FilePath] -> [String] -> Pandoc -> IO Pandoc
|
|
|
|
applyFilters filters args d =
|
|
|
|
foldrM ($) d $ map (flip externalFilter args) filters
|
|
|
|
|
2008-06-17 20:55:42 +02:00
|
|
|
main :: IO ()
|
2006-12-28 03:20:09 +01:00
|
|
|
main = do
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2014-08-04 16:08:12 +02:00
|
|
|
rawArgs <- map UTF8.decodeArg <$> getArgs
|
2007-01-02 08:37:42 +01:00
|
|
|
prg <- getProgName
|
|
|
|
let compatMode = (prg == "hsmarkdown")
|
|
|
|
|
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-01-08 09:11:08 +01:00
|
|
|
let (actions, args, errors) = if compatMode
|
|
|
|
then ([], rawArgs, [])
|
|
|
|
else getOpt Permute options rawArgs
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2009-01-24 20:59:07 +01:00
|
|
|
unless (null errors) $
|
2012-01-21 07:12:03 +01:00
|
|
|
err 2 $ concat $ errors ++
|
|
|
|
["Try " ++ prg ++ " --help for more information."]
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2008-08-10 19:33:20 +02:00
|
|
|
let defaultOpts' = if compatMode
|
2012-08-10 07:30:44 +02:00
|
|
|
then defaultOpts { optReader = "markdown_strict"
|
2007-01-02 08:37:42 +01:00
|
|
|
, optWriter = "html"
|
2012-08-10 05:19:06 +02:00
|
|
|
, optEmailObfuscation =
|
|
|
|
ReferenceObfuscation }
|
2007-01-02 08:37:42 +01:00
|
|
|
else defaultOpts
|
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
-- thread option data structure through all supplied option actions
|
2007-01-02 08:37:42 +01:00
|
|
|
opts <- foldl (>>=) (return defaultOpts') actions
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2013-02-06 05:08:00 +01:00
|
|
|
let Opt { optTabStop = tabStop
|
|
|
|
, optPreserveTabs = preserveTabs
|
|
|
|
, optStandalone = standalone
|
|
|
|
, optReader = readerName
|
|
|
|
, optWriter = writerName
|
|
|
|
, optParseRaw = parseRaw
|
|
|
|
, optVariables = variables
|
2013-09-02 00:37:02 +02:00
|
|
|
, optMetadata = metadata
|
2013-02-06 05:08:00 +01:00
|
|
|
, optTableOfContents = toc
|
|
|
|
, optTransforms = transforms
|
|
|
|
, optTemplate = templatePath
|
|
|
|
, optOutputFile = outputFile
|
|
|
|
, optNumberSections = numberSections
|
2014-08-04 16:08:12 +02:00
|
|
|
, optNumberOffset = numberFrom
|
2013-02-06 05:08:00 +01:00
|
|
|
, optSectionDivs = sectionDivs
|
|
|
|
, optIncremental = incremental
|
|
|
|
, optSelfContained = selfContained
|
|
|
|
, optSmart = smart
|
|
|
|
, optOldDashes = oldDashes
|
|
|
|
, optHtml5 = html5
|
|
|
|
, optHtmlQTags = htmlQTags
|
|
|
|
, optHighlight = highlight
|
|
|
|
, optHighlightStyle = highlightStyle
|
|
|
|
, optChapters = chapters
|
2014-09-25 19:23:28 +02:00
|
|
|
, optHTMLMathMethod = mathMethod'
|
2013-02-06 05:08:00 +01:00
|
|
|
, optReferenceODT = referenceODT
|
|
|
|
, optReferenceDocx = referenceDocx
|
|
|
|
, optEpubStylesheet = epubStylesheet
|
|
|
|
, optEpubMetadata = epubMetadata
|
|
|
|
, optEpubFonts = epubFonts
|
|
|
|
, optEpubChapterLevel = epubChapterLevel
|
|
|
|
, optTOCDepth = epubTOCDepth
|
|
|
|
, optDumpArgs = dumpArgs
|
|
|
|
, optIgnoreArgs = ignoreArgs
|
2014-12-26 19:19:55 +01:00
|
|
|
, optVerbose = verbose
|
2013-02-06 05:08:00 +01:00
|
|
|
, optReferenceLinks = referenceLinks
|
|
|
|
, optWrapText = wrap
|
|
|
|
, optColumns = columns
|
2013-09-11 05:23:03 +02:00
|
|
|
, optFilters = filters
|
2013-02-06 05:08:00 +01:00
|
|
|
, optEmailObfuscation = obfuscationMethod
|
|
|
|
, optIdentifierPrefix = idPrefix
|
|
|
|
, optIndentedCodeClasses = codeBlockClasses
|
|
|
|
, optDataDir = mbDataDir
|
|
|
|
, optCiteMethod = citeMethod
|
|
|
|
, optListings = listings
|
|
|
|
, optLaTeXEngine = latexEngine
|
2015-03-04 10:55:56 +01:00
|
|
|
, optLaTeXEngineArgs = latexEngineArgs
|
2013-02-06 05:08:00 +01:00
|
|
|
, optSlideLevel = slideLevel
|
|
|
|
, optSetextHeaders = setextHeaders
|
|
|
|
, optAscii = ascii
|
|
|
|
, optTeXLigatures = texLigatures
|
|
|
|
, optDefaultImageExtension = defaultImageExtension
|
2014-07-30 20:44:25 +02:00
|
|
|
, optExtractMedia = mbExtractMedia
|
2014-02-26 07:43:58 +01:00
|
|
|
, optTrace = trace
|
2014-06-25 20:09:01 +02:00
|
|
|
, optTrackChanges = trackChanges
|
2014-09-25 19:23:28 +02:00
|
|
|
, optKaTeXStylesheet = katexStylesheet
|
|
|
|
, optKaTeXJS = katexJS
|
2006-10-17 16:22:29 +02:00
|
|
|
} = opts
|
|
|
|
|
2009-01-24 20:59:07 +01:00
|
|
|
when dumpArgs $
|
2012-09-24 07:53:34 +02:00
|
|
|
do UTF8.hPutStrLn stdout outputFile
|
|
|
|
mapM_ (\arg -> UTF8.hPutStrLn stdout arg) args
|
2009-01-24 20:59:07 +01:00
|
|
|
exitWith ExitSuccess
|
2007-01-09 02:43:23 +01:00
|
|
|
|
2014-09-25 19:23:28 +02:00
|
|
|
let csscdn = "http://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.0/katex.min.css"
|
|
|
|
let mathMethod =
|
|
|
|
case (katexJS, katexStylesheet) of
|
|
|
|
(Nothing, _) -> mathMethod'
|
|
|
|
(Just js, ss) -> KaTeX js (fromMaybe csscdn ss)
|
|
|
|
|
|
|
|
|
2013-09-11 05:23:03 +02:00
|
|
|
-- --bibliography implies -F pandoc-citeproc for backwards compatibility:
|
2014-08-04 16:08:12 +02:00
|
|
|
let needsCiteproc = isJust (M.lookup "bibliography" metadata) &&
|
|
|
|
optCiteMethod opts `notElem` [Natbib, Biblatex] &&
|
|
|
|
"pandoc-citeproc" `notElem` map takeBaseName filters
|
|
|
|
let filters' = if needsCiteproc then "pandoc-citeproc" : filters
|
|
|
|
else filters
|
2013-09-11 05:23:03 +02:00
|
|
|
|
Changes to Pandoc's options to facilitate wrapper scripts:
+ removed -d/--debug option
+ added --dump-args option, which prints the name of the output file
(or '-' for STDOUT) and all the command-line arguments (excluding
Pandoc options and their arguments), one per line, then exits. Note
that special wrapper options will be treated as arguments if they
follow '--' at the end of the command line. Thus,
pandoc --dump-args -o foo.html foo.txt -- -e latin1
will print the following to STDOUT:
foo.html
foo.txt
-e
latin1
+ added --ignore-args option, which causes Pandoc to ignore all
(non-option) arguments, including any special options that occur
after '--' at the end of the command line.
+ '-' now means STDIN as the name of an input file, STDOUT as the
name of an output file. So,
pandoc -o - -
will take input from STDIN and print output to STDOUT. Note that
if multiple '-o' options are specified on the same line, the last
one takes precedence. So, in a script,
pandoc "$@" -o -
will guarantee output to STDOUT, even if the '-o' option was used.
+ documented these changes in man pages, README, and changelog.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@454 788f1e2b-df1e-0410-8736-df70ead52e1b
2007-01-08 09:11:08 +01:00
|
|
|
let sources = if ignoreArgs then [] else args
|
|
|
|
|
2010-01-14 06:54:38 +01:00
|
|
|
datadir <- case mbDataDir of
|
2012-07-25 04:28:51 +02:00
|
|
|
Nothing -> E.catch
|
2014-08-04 16:08:12 +02:00
|
|
|
(Just <$> getAppUserDataDirectory "pandoc")
|
2012-07-25 04:28:51 +02:00
|
|
|
(\e -> let _ = (e :: E.SomeException)
|
|
|
|
in return Nothing)
|
2010-02-21 17:47:24 +01:00
|
|
|
Just _ -> return mbDataDir
|
2010-01-14 06:54:38 +01:00
|
|
|
|
2006-12-28 03:20:09 +01:00
|
|
|
-- assign reader and writer based on options and filenames
|
2014-04-28 06:01:30 +02:00
|
|
|
let readerName' = case map toLower readerName of
|
|
|
|
[] -> defaultReaderName
|
|
|
|
(if any isURI sources
|
|
|
|
then "html"
|
|
|
|
else "markdown") sources
|
|
|
|
"html4" -> "html"
|
|
|
|
x -> x
|
2014-04-28 05:38:15 +02:00
|
|
|
|
|
|
|
let writerName' = case map toLower writerName of
|
|
|
|
[] -> defaultWriterName outputFile
|
|
|
|
"epub2" -> "epub"
|
|
|
|
"html4" -> "html"
|
|
|
|
x -> x
|
2006-12-28 03:20:09 +01:00
|
|
|
|
2012-01-28 20:41:26 +01:00
|
|
|
let pdfOutput = map toLower (takeExtension outputFile) == ".pdf"
|
|
|
|
|
2012-08-10 05:19:06 +02:00
|
|
|
let laTeXOutput = "latex" `isPrefixOf` writerName' ||
|
|
|
|
"beamer" `isPrefixOf` writerName'
|
2012-03-09 19:32:32 +01:00
|
|
|
|
2014-04-28 05:56:50 +02:00
|
|
|
writer <- if ".lua" `isSuffixOf` writerName'
|
|
|
|
-- note: use non-lowercased version writerName
|
|
|
|
then return $ IOStringWriter $ writeCustom writerName
|
|
|
|
else case getWriter writerName' of
|
|
|
|
Left e -> err 9 $
|
|
|
|
if writerName' == "pdf"
|
2014-08-04 16:08:12 +02:00
|
|
|
then e ++
|
|
|
|
"\nTo create a pdf with pandoc, use " ++
|
2014-04-28 05:56:50 +02:00
|
|
|
"the latex or beamer writer and specify\n" ++
|
|
|
|
"an output file with .pdf extension " ++
|
|
|
|
"(pandoc -t latex -o filename.pdf)."
|
|
|
|
else e
|
|
|
|
Right w -> return w
|
2012-01-21 18:34:47 +01:00
|
|
|
|
2014-07-20 18:00:38 +02:00
|
|
|
reader <- if "t2t" == readerName'
|
|
|
|
then (mkStringReader .
|
|
|
|
readTxt2Tags) <$>
|
2014-07-31 02:25:00 +02:00
|
|
|
(getT2TMeta sources outputFile)
|
2014-07-20 18:00:38 +02:00
|
|
|
else case getReader readerName' of
|
|
|
|
Right r -> return r
|
2014-10-20 01:59:31 +02:00
|
|
|
Left e -> err 7 e'
|
|
|
|
where e' = case readerName' of
|
|
|
|
"odt" -> e ++
|
|
|
|
"\nPandoc can convert to ODT, but not from ODT.\nTry using LibreOffice to export as HTML, and convert that with pandoc."
|
|
|
|
"pdf" -> e ++
|
|
|
|
"\nPandoc can convert to PDF, but not from PDF."
|
|
|
|
"doc" -> e ++
|
|
|
|
"\nPandoc can convert from DOCX, but not from DOC.\nTry using Word to save your DOC file as DOCX, and convert that with pandoc."
|
|
|
|
_ -> e
|
2006-12-28 03:20:09 +01:00
|
|
|
|
2012-08-10 05:19:06 +02:00
|
|
|
let standalone' = standalone || not (isTextFormat writerName') || pdfOutput
|
2011-11-22 23:21:19 +01:00
|
|
|
|
2011-07-23 07:15:25 +02:00
|
|
|
templ <- case templatePath of
|
2011-11-22 23:21:19 +01:00
|
|
|
_ | not standalone' -> return ""
|
2011-07-23 07:15:25 +02:00
|
|
|
Nothing -> do
|
|
|
|
deftemp <- getDefaultTemplate datadir writerName'
|
|
|
|
case deftemp of
|
|
|
|
Left e -> throwIO e
|
|
|
|
Right t -> return t
|
2011-07-23 07:49:38 +02:00
|
|
|
Just tp -> do
|
2012-08-10 05:19:06 +02:00
|
|
|
-- strip off extensions
|
|
|
|
let format = takeWhile (`notElem` "+-") writerName'
|
2011-07-23 07:49:38 +02:00
|
|
|
let tp' = case takeExtension tp of
|
|
|
|
"" -> tp <.> format
|
|
|
|
_ -> tp
|
2012-09-23 21:33:17 +02:00
|
|
|
E.catch (UTF8.readFile tp')
|
2011-07-23 07:15:25 +02:00
|
|
|
(\e -> if isDoesNotExistError e
|
2012-07-25 04:28:51 +02:00
|
|
|
then E.catch
|
2012-12-30 02:44:02 +01:00
|
|
|
(readDataFileUTF8 datadir
|
|
|
|
("templates" </> tp'))
|
2012-07-25 04:28:51 +02:00
|
|
|
(\e' -> let _ = (e' :: E.SomeException)
|
|
|
|
in throwIO e')
|
2011-07-23 07:15:25 +02:00
|
|
|
else throwIO e)
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2011-11-22 00:24:28 +01:00
|
|
|
variables' <- case mathMethod of
|
2009-12-31 02:13:26 +01:00
|
|
|
LaTeXMathML Nothing -> do
|
2013-12-20 02:43:25 +01:00
|
|
|
s <- readDataFileUTF8 datadir "LaTeXMathML.js"
|
2011-11-22 00:24:28 +01:00
|
|
|
return $ ("mathml-script", s) : variables
|
2010-03-18 07:45:56 +01:00
|
|
|
MathML Nothing -> do
|
2013-12-20 02:43:25 +01:00
|
|
|
s <- readDataFileUTF8 datadir "MathMLinHTML.js"
|
2011-11-22 00:24:28 +01:00
|
|
|
return $ ("mathml-script", s) : variables
|
|
|
|
_ -> return variables
|
2009-12-31 02:13:16 +01:00
|
|
|
|
2012-08-10 05:19:06 +02:00
|
|
|
variables'' <- if "dzslides" `isPrefixOf` writerName'
|
|
|
|
then do
|
2012-12-30 02:44:02 +01:00
|
|
|
dztempl <- readDataFileUTF8 datadir
|
|
|
|
("dzslides" </> "template.html")
|
2014-08-04 16:08:12 +02:00
|
|
|
let dzline = "<!-- {{{{ dzslides core"
|
|
|
|
let dzcore = unlines
|
|
|
|
$ dropWhile (not . (dzline `isPrefixOf`))
|
|
|
|
$ lines dztempl
|
2011-12-30 02:41:06 +01:00
|
|
|
return $ ("dzslides-core", dzcore) : variables'
|
2012-08-10 05:19:06 +02:00
|
|
|
else return variables'
|
2014-08-03 01:07:19 +02:00
|
|
|
|
Options: Changed `writerSourceDir` to `writerSourceURL` (now a Maybe).
Previously we used to store the directory of the first input file,
even if it was local, and used this as a base directory for
finding images in ODT, EPUB, Docx, and PDF.
This has been confusing to many users. It seems better to look for
images relative to the current working directory, even if the first
file argument is in another directory.
writerSourceURL is set to 'Just url' when the first command-line
argument is an absolute URL. (So, relative links will be resolved
in relation to the first page.) Otherwise, 'Nothing'.
The ODT, EPUB, Docx, and PDF writers have been modified accordingly.
Note that this change may break some existing workflows. If you
have been assuming that relative links will be interpreted relative
to the directory of the first file argument, you'll need to
make that the current directory before running pandoc.
Closes #942.
2013-08-12 00:58:09 +02:00
|
|
|
let sourceURL = case sources of
|
2014-08-04 16:08:12 +02:00
|
|
|
[] -> Nothing
|
|
|
|
(x:_) -> case parseURI x of
|
|
|
|
Just u
|
|
|
|
| uriScheme u `elem` ["http:","https:"] ->
|
2014-08-06 23:36:46 +02:00
|
|
|
Just $ show u{ uriQuery = "",
|
2014-08-04 16:08:12 +02:00
|
|
|
uriFragment = "" }
|
|
|
|
_ -> Nothing
|
2010-07-09 02:14:03 +02:00
|
|
|
|
2012-08-10 05:19:06 +02:00
|
|
|
let readerOpts = def{ readerSmart = smart || (texLigatures &&
|
|
|
|
(laTeXOutput || "context" `isPrefixOf` writerName'))
|
2012-07-26 07:35:41 +02:00
|
|
|
, readerStandalone = standalone'
|
|
|
|
, readerParseRaw = parseRaw
|
|
|
|
, readerColumns = columns
|
|
|
|
, readerTabStop = tabStop
|
|
|
|
, readerOldDashes = oldDashes
|
|
|
|
, readerIndentedCodeClasses = codeBlockClasses
|
|
|
|
, readerApplyMacros = not laTeXOutput
|
2013-02-06 05:08:00 +01:00
|
|
|
, readerDefaultImageExtension = defaultImageExtension
|
2014-02-26 07:43:58 +01:00
|
|
|
, readerTrace = trace
|
2014-06-25 20:09:01 +02:00
|
|
|
, readerTrackChanges = trackChanges
|
2012-07-26 07:35:41 +02:00
|
|
|
}
|
2010-07-09 02:14:03 +02:00
|
|
|
|
2014-08-01 01:26:48 +02:00
|
|
|
when (not (isTextFormat writerName') && outputFile == "-") $
|
|
|
|
err 5 $ "Cannot write " ++ writerName' ++ " output to stdout.\n" ++
|
|
|
|
"Specify an output file using the -o option."
|
|
|
|
|
|
|
|
let readSources [] = mapM readSource ["-"]
|
|
|
|
readSources srcs = mapM readSource srcs
|
|
|
|
readSource "-" = UTF8.getContents
|
|
|
|
readSource src = case parseURI src of
|
|
|
|
Just u | uriScheme u `elem` ["http:","https:"] ->
|
|
|
|
readURI src
|
|
|
|
_ -> UTF8.readFile src
|
|
|
|
readURI src = do
|
|
|
|
res <- openURL src
|
|
|
|
case res of
|
|
|
|
Left e -> throwIO e
|
|
|
|
Right (bs,_) -> return $ UTF8.toString bs
|
|
|
|
|
|
|
|
let readFiles [] = error "Cannot read archive from stdin"
|
2015-01-19 03:44:04 +01:00
|
|
|
readFiles [x] = B.readFile x
|
|
|
|
readFiles (x:xs) = mapM (warn . ("Ignoring: " ++)) xs >> B.readFile x
|
2014-08-01 01:26:48 +02:00
|
|
|
|
2014-08-04 16:08:12 +02:00
|
|
|
let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
|
|
|
|
then 0
|
|
|
|
else tabStop)
|
2014-08-01 01:26:48 +02:00
|
|
|
|
2015-02-18 20:57:30 +01:00
|
|
|
let handleIncludes' :: String -> IO (Either PandocError String)
|
|
|
|
handleIncludes' = if readerName' `elem` ["latex", "latex+lhs"]
|
2014-08-04 16:08:12 +02:00
|
|
|
then handleIncludes
|
2015-02-18 20:57:30 +01:00
|
|
|
else return . Right
|
|
|
|
|
|
|
|
(doc, media) <- fmap handleError $
|
|
|
|
case reader of
|
|
|
|
StringReader r-> do
|
|
|
|
srcs <- convertTabs . intercalate "\n" <$> readSources sources
|
|
|
|
doc <- handleIncludes' srcs
|
|
|
|
either (return . Left) (\s -> fmap (,mempty) <$> r readerOpts s) doc
|
2014-08-01 01:26:48 +02:00
|
|
|
ByteStringReader r -> readFiles sources >>= r readerOpts
|
|
|
|
|
2012-07-24 07:53:35 +02:00
|
|
|
let writerOptions = def { writerStandalone = standalone',
|
|
|
|
writerTemplate = templ,
|
|
|
|
writerVariables = variables'',
|
|
|
|
writerTabStop = tabStop,
|
2012-07-24 07:58:16 +02:00
|
|
|
writerTableOfContents = toc,
|
2012-07-24 07:53:35 +02:00
|
|
|
writerHTMLMathMethod = mathMethod,
|
|
|
|
writerIncremental = incremental,
|
|
|
|
writerCiteMethod = citeMethod,
|
|
|
|
writerIgnoreNotes = False,
|
|
|
|
writerNumberSections = numberSections,
|
2013-03-16 22:48:37 +01:00
|
|
|
writerNumberOffset = numberFrom,
|
2012-07-24 07:53:35 +02:00
|
|
|
writerSectionDivs = sectionDivs,
|
|
|
|
writerReferenceLinks = referenceLinks,
|
|
|
|
writerWrapText = wrap,
|
|
|
|
writerColumns = columns,
|
2012-08-10 05:19:06 +02:00
|
|
|
writerEmailObfuscation = obfuscationMethod,
|
2012-07-24 07:53:35 +02:00
|
|
|
writerIdentifierPrefix = idPrefix,
|
Options: Changed `writerSourceDir` to `writerSourceURL` (now a Maybe).
Previously we used to store the directory of the first input file,
even if it was local, and used this as a base directory for
finding images in ODT, EPUB, Docx, and PDF.
This has been confusing to many users. It seems better to look for
images relative to the current working directory, even if the first
file argument is in another directory.
writerSourceURL is set to 'Just url' when the first command-line
argument is an absolute URL. (So, relative links will be resolved
in relation to the first page.) Otherwise, 'Nothing'.
The ODT, EPUB, Docx, and PDF writers have been modified accordingly.
Note that this change may break some existing workflows. If you
have been assuming that relative links will be interpreted relative
to the directory of the first file argument, you'll need to
make that the current directory before running pandoc.
Closes #942.
2013-08-12 00:58:09 +02:00
|
|
|
writerSourceURL = sourceURL,
|
2012-07-24 07:53:35 +02:00
|
|
|
writerUserDataDir = datadir,
|
|
|
|
writerHtml5 = html5,
|
2013-01-16 03:50:36 +01:00
|
|
|
writerHtmlQTags = htmlQTags,
|
2012-07-24 07:53:35 +02:00
|
|
|
writerChapters = chapters,
|
|
|
|
writerListings = listings,
|
|
|
|
writerBeamer = False,
|
|
|
|
writerSlideLevel = slideLevel,
|
|
|
|
writerHighlight = highlight,
|
|
|
|
writerHighlightStyle = highlightStyle,
|
|
|
|
writerSetextHeaders = setextHeaders,
|
2012-07-24 18:56:00 +02:00
|
|
|
writerTeXLigatures = texLigatures,
|
2013-01-05 07:41:09 +01:00
|
|
|
writerEpubMetadata = epubMetadata,
|
2012-07-24 18:56:00 +02:00
|
|
|
writerEpubStylesheet = epubStylesheet,
|
|
|
|
writerEpubFonts = epubFonts,
|
2013-01-05 07:29:41 +01:00
|
|
|
writerEpubChapterLevel = epubChapterLevel,
|
2013-01-05 21:03:05 +01:00
|
|
|
writerTOCDepth = epubTOCDepth,
|
2012-07-24 18:56:00 +02:00
|
|
|
writerReferenceODT = referenceODT,
|
2014-08-01 01:26:48 +02:00
|
|
|
writerReferenceDocx = referenceDocx,
|
2014-12-26 19:19:55 +01:00
|
|
|
writerMediaBag = media,
|
2015-03-04 10:55:56 +01:00
|
|
|
writerVerbose = verbose,
|
|
|
|
writerLaTeXArgs = latexEngineArgs
|
2012-07-24 07:53:35 +02:00
|
|
|
}
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2014-07-31 21:51:01 +02:00
|
|
|
|
2014-08-01 01:26:48 +02:00
|
|
|
doc' <- (maybe return (extractMedia media) mbExtractMedia >=>
|
|
|
|
adjustMetadata metadata >=>
|
|
|
|
applyTransforms transforms >=>
|
|
|
|
applyFilters filters' [writerName']) doc
|
2010-03-15 00:23:26 +01:00
|
|
|
|
2012-01-28 20:41:26 +01:00
|
|
|
let writeBinary :: B.ByteString -> IO ()
|
2012-09-23 19:43:03 +02:00
|
|
|
writeBinary = B.writeFile (UTF8.encodePath outputFile)
|
2012-01-28 20:41:26 +01:00
|
|
|
|
|
|
|
let writerFn :: FilePath -> String -> IO ()
|
2012-09-24 07:53:34 +02:00
|
|
|
writerFn "-" = UTF8.putStr
|
|
|
|
writerFn f = UTF8.writeFile f
|
2012-01-28 20:41:26 +01:00
|
|
|
|
2014-04-06 08:43:28 +02:00
|
|
|
case writer of
|
2014-08-01 01:26:48 +02:00
|
|
|
IOStringWriter f -> f writerOptions doc' >>= writerFn outputFile
|
|
|
|
IOByteStringWriter f -> f writerOptions doc' >>= writeBinary
|
2014-04-06 08:43:28 +02:00
|
|
|
PureStringWriter f
|
2012-07-25 04:05:38 +02:00
|
|
|
| pdfOutput -> do
|
2014-04-06 08:43:28 +02:00
|
|
|
-- make sure writer is latex or beamer
|
|
|
|
unless laTeXOutput $
|
|
|
|
err 47 $ "cannot produce pdf output with " ++ writerName' ++
|
|
|
|
" writer"
|
|
|
|
|
|
|
|
-- check for latex program
|
|
|
|
mbLatex <- findExecutable latexEngine
|
|
|
|
when (mbLatex == Nothing) $
|
|
|
|
err 41 $ latexEngine ++ " not found. " ++
|
|
|
|
latexEngine ++ " is needed for pdf output."
|
|
|
|
|
2014-08-01 01:26:48 +02:00
|
|
|
res <- makePDF latexEngine f writerOptions doc'
|
2012-01-21 18:34:47 +01:00
|
|
|
case res of
|
|
|
|
Right pdf -> writeBinary pdf
|
2014-03-19 19:09:36 +01:00
|
|
|
Left err' -> do
|
|
|
|
B.hPutStr stderr $ err'
|
|
|
|
B.hPut stderr $ B.pack [10]
|
|
|
|
err 43 "Error producing PDF from TeX source"
|
2014-08-01 01:26:48 +02:00
|
|
|
| otherwise -> selfcontain (f writerOptions doc' ++
|
2012-07-25 04:05:38 +02:00
|
|
|
['\n' | not standalone'])
|
|
|
|
>>= writerFn outputFile . handleEntities
|
|
|
|
where htmlFormat = writerName' `elem`
|
2012-02-05 23:58:55 +01:00
|
|
|
["html","html+lhs","html5","html5+lhs",
|
2013-03-24 02:46:27 +01:00
|
|
|
"s5","slidy","slideous","dzslides","revealjs"]
|
2012-02-05 23:58:55 +01:00
|
|
|
selfcontain = if selfContained && htmlFormat
|
2014-08-03 01:07:19 +02:00
|
|
|
then makeSelfContained writerOptions
|
2012-02-05 23:58:55 +01:00
|
|
|
else return
|
2012-07-25 04:05:38 +02:00
|
|
|
handleEntities = if htmlFormat && ascii
|
|
|
|
then toEntities
|
|
|
|
else id
|