2006-12-20 21:54:23 +01:00
|
|
|
{-
|
2010-03-23 21:31:09 +01:00
|
|
|
Copyright (C) 2006-2010 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
|
2010-03-23 21:31:09 +01:00
|
|
|
Copyright : Copyright (C) 2006-2010 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
|
2009-12-31 02:11:13 +01:00
|
|
|
import Text.Pandoc.Writers.S5 (s5HeaderIncludes)
|
2010-07-12 05:03:55 +02:00
|
|
|
import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
|
2010-07-14 05:44:56 +02:00
|
|
|
headerShift, HTMLSlideVariant(..) )
|
2009-05-02 04:37:38 +02:00
|
|
|
#ifdef _HIGHLIGHTING
|
2008-02-09 04:21:19 +01:00
|
|
|
import Text.Pandoc.Highlighting ( languages )
|
2009-05-02 04:37:38 +02:00
|
|
|
#endif
|
2007-01-15 20:52:42 +01:00
|
|
|
import System.Environment ( getArgs, getProgName, getEnvironment )
|
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-03-15 00:23:26 +01:00
|
|
|
import Data.Char ( toLower, isDigit )
|
2008-12-02 23:43:17 +01:00
|
|
|
import Data.List ( intercalate, isSuffixOf )
|
2010-01-14 06:54:38 +01:00
|
|
|
import System.Directory ( getAppUserDataDirectory )
|
2009-12-31 17:48:55 +01:00
|
|
|
import System.IO ( stdout, stderr )
|
2010-05-07 05:29:44 +02:00
|
|
|
import qualified Text.Pandoc.UTF8 as UTF8
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
|
|
|
import Text.CSL
|
|
|
|
import Text.Pandoc.Biblio
|
|
|
|
#endif
|
2010-02-21 17:47:24 +01:00
|
|
|
import Control.Monad (when, unless, liftM)
|
2010-03-15 00:23:26 +01:00
|
|
|
import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
|
2010-03-18 07:45:50 +01:00
|
|
|
import Network.URI (parseURI, isURI)
|
2010-07-03 05:12:14 +02:00
|
|
|
import qualified Data.ByteString.Lazy as B
|
|
|
|
import Data.ByteString.Lazy.UTF8 (toString, fromString)
|
2010-05-05 08:36:03 +02:00
|
|
|
import Codec.Binary.UTF8.String (decodeString)
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
copyrightMessage :: String
|
2010-03-19 16:12:15 +01:00
|
|
|
copyrightMessage = "\nCopyright (C) 2006-2010 John MacFarlane\n" ++
|
2008-08-01 01:55:27 +02:00
|
|
|
"Web: http://johnmacfarlane.net/pandoc\n" ++
|
|
|
|
"This is free software; see the source for copying conditions. There is no\n" ++
|
|
|
|
"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 =
|
|
|
|
#ifdef _CITEPROC
|
2009-05-02 04:37:38 +02:00
|
|
|
"\nCompiled with citeproc support." ++
|
2008-08-04 05:15:34 +02:00
|
|
|
#endif
|
|
|
|
#ifdef _HIGHLIGHTING
|
2009-05-02 04:37:38 +02:00
|
|
|
"\nCompiled with syntax highlighting support for:\n" ++
|
|
|
|
wrapWords 78 languages ++
|
2008-08-04 01:33:40 +02:00
|
|
|
#endif
|
2009-05-02 04:37:38 +02:00
|
|
|
""
|
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.
|
|
|
|
wrapWords :: Int -> [String] -> String
|
|
|
|
wrapWords c = wrap' c c where
|
|
|
|
wrap' _ _ [] = ""
|
|
|
|
wrap' cols remaining (x:xs) = if remaining == cols
|
|
|
|
then x ++ wrap' cols (remaining - length x) xs
|
|
|
|
else if (length x + 1) > remaining
|
|
|
|
then ",\n" ++ x ++ wrap' cols (cols - length x) xs
|
|
|
|
else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
|
2008-02-09 04:21:19 +01:00
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
-- | Association list of formats and readers.
|
|
|
|
readers :: [(String, ParserState -> String -> Pandoc)]
|
2008-12-02 23:43:17 +01:00
|
|
|
readers = [("native" , readPandoc)
|
|
|
|
,("markdown" , readMarkdown)
|
|
|
|
,("markdown+lhs" , readMarkdown)
|
|
|
|
,("rst" , readRST)
|
|
|
|
,("rst+lhs" , readRST)
|
|
|
|
,("html" , readHtml)
|
|
|
|
,("latex" , readLaTeX)
|
|
|
|
,("latex+lhs" , readLaTeX)
|
2006-10-17 16:22:29 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
-- | Reader for native Pandoc format.
|
|
|
|
readPandoc :: ParserState -> String -> Pandoc
|
2009-01-24 20:59:07 +01:00
|
|
|
readPandoc _ = read
|
2008-08-10 19:33:20 +02:00
|
|
|
|
2009-12-31 02:10:57 +01:00
|
|
|
-- | Association list of formats and writers.
|
|
|
|
writers :: [ ( String, WriterOptions -> Pandoc -> String ) ]
|
2010-07-04 22:55:48 +02:00
|
|
|
writers = [("native" , writeNative)
|
2009-12-31 02:10:57 +01:00
|
|
|
,("html" , writeHtmlString)
|
|
|
|
,("html+lhs" , writeHtmlString)
|
|
|
|
,("s5" , writeS5String)
|
2010-07-14 05:44:56 +02:00
|
|
|
,("slidy" , writeHtmlString)
|
2009-12-31 02:10:57 +01:00
|
|
|
,("docbook" , writeDocbook)
|
|
|
|
,("opendocument" , writeOpenDocument)
|
2010-07-03 05:12:14 +02:00
|
|
|
,("odt" , \_ _ -> "")
|
2010-07-03 07:07:00 +02:00
|
|
|
,("epub" , \_ _ -> "")
|
2009-12-31 02:10:57 +01:00
|
|
|
,("latex" , writeLaTeX)
|
|
|
|
,("latex+lhs" , writeLaTeX)
|
|
|
|
,("context" , writeConTeXt)
|
|
|
|
,("texinfo" , writeTexinfo)
|
|
|
|
,("man" , writeMan)
|
|
|
|
,("markdown" , writeMarkdown)
|
|
|
|
,("markdown+lhs" , writeMarkdown)
|
2010-03-18 07:45:43 +01:00
|
|
|
,("plain" , writePlain)
|
2009-12-31 02:10:57 +01:00
|
|
|
,("rst" , writeRST)
|
|
|
|
,("rst+lhs" , writeRST)
|
|
|
|
,("mediawiki" , writeMediaWiki)
|
|
|
|
,("rtf" , writeRTF)
|
2006-10-17 16:22:29 +02:00
|
|
|
]
|
|
|
|
|
2008-08-01 01:16:02 +02:00
|
|
|
isNonTextOutput :: String -> Bool
|
2010-07-03 07:07:00 +02:00
|
|
|
isNonTextOutput = (`elem` ["odt","epub"])
|
2008-08-01 01:16:02 +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
|
2010-03-18 07:45:28 +01:00
|
|
|
, optTransforms :: [Pandoc -> Pandoc] -- ^ Doc transforms to apply
|
2009-12-31 02:10:04 +01:00
|
|
|
, optTemplate :: String -- ^ Custom template
|
2009-12-31 02:09:56 +01:00
|
|
|
, optVariables :: [(String,String)] -- ^ Template variables 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
|
2010-07-16 04:01:00 +02:00
|
|
|
, optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
|
2010-07-14 05:44:56 +02:00
|
|
|
, optIncremental :: Bool -- ^ Use incremental lists in Slidy/S5
|
2009-12-31 02:18:06 +01:00
|
|
|
, optXeTeX :: Bool -- ^ Format latex for xetex
|
2006-12-30 23:51:49 +01:00
|
|
|
, optSmart :: Bool -- ^ Use smart typography
|
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
|
2010-07-03 07:07:00 +02:00
|
|
|
, optEPUBStylesheet :: Maybe String -- ^ EPUB stylesheet
|
2010-07-05 01:56:17 +02:00
|
|
|
, optEPUBMetadata :: String -- ^ EPUB metadata
|
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
|
2006-12-30 23:51:49 +01:00
|
|
|
, optStrict :: Bool -- ^ Use strict markdown syntax
|
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
|
2008-01-03 22:32:32 +01:00
|
|
|
, optSanitizeHTML :: Bool -- ^ Sanitize HTML
|
2009-01-24 20:58:06 +01:00
|
|
|
, optPlugins :: [Pandoc -> IO Pandoc] -- ^ Plugins 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
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
2008-12-29 23:45:18 +01:00
|
|
|
, optBiblioFile :: String
|
|
|
|
, optBiblioFormat :: String
|
2008-08-04 05:15:34 +02:00
|
|
|
, optCslFile :: String
|
|
|
|
#endif
|
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
|
2009-01-31 18:13:41 +01:00
|
|
|
{ optTabStop = 4
|
2009-04-08 22:19:50 +02:00
|
|
|
, optPreserveTabs = False
|
2006-10-17 16:22:29 +02:00
|
|
|
, optStandalone = False
|
2006-12-28 03:20:09 +01:00
|
|
|
, optReader = "" -- null for default reader
|
|
|
|
, optWriter = "" -- null for default writer
|
2006-10-17 16:22:29 +02:00
|
|
|
, optParseRaw = False
|
2007-07-07 07:43:23 +02:00
|
|
|
, optTableOfContents = False
|
2010-03-18 07:45:28 +01:00
|
|
|
, optTransforms = []
|
2009-12-31 02:10:04 +01:00
|
|
|
, optTemplate = ""
|
2009-12-31 02:09:56 +01:00
|
|
|
, optVariables = []
|
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
|
|
|
, optOutputFile = "-" -- "-" means stdout
|
2006-10-17 16:22:29 +02:00
|
|
|
, optNumberSections = False
|
2010-07-16 04:01:00 +02:00
|
|
|
, optSectionDivs = False
|
2006-10-17 16:22:29 +02:00
|
|
|
, optIncremental = False
|
2009-12-31 02:18:06 +01:00
|
|
|
, optXeTeX = False
|
2006-12-18 23:02:39 +01:00
|
|
|
, optSmart = False
|
2007-12-01 04:11:52 +01:00
|
|
|
, optHTMLMathMethod = PlainMath
|
2009-12-31 23:40:59 +01:00
|
|
|
, optReferenceODT = Nothing
|
2010-07-03 07:07:00 +02:00
|
|
|
, optEPUBStylesheet = Nothing
|
2010-07-05 01:56:17 +02:00
|
|
|
, optEPUBMetadata = ""
|
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 = False
|
|
|
|
, optIgnoreArgs = False
|
2006-12-30 23:51:49 +01:00
|
|
|
, optStrict = False
|
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 = False
|
2007-09-27 03:23:44 +02:00
|
|
|
, optWrapText = True
|
2008-01-03 22:32:32 +01:00
|
|
|
, optSanitizeHTML = False
|
2009-01-24 20:58:06 +01:00
|
|
|
, optPlugins = []
|
2009-01-24 20:58:48 +01:00
|
|
|
, optEmailObfuscation = JavascriptObfuscation
|
2009-12-05 18:56:02 +01:00
|
|
|
, optIdentifierPrefix = ""
|
2009-12-05 05:46:57 +01:00
|
|
|
, optIndentedCodeClasses = []
|
2010-01-14 06:54:38 +01:00
|
|
|
, optDataDir = Nothing
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
2008-12-29 23:45:18 +01:00
|
|
|
, optBiblioFile = []
|
|
|
|
, optBiblioFormat = []
|
2008-08-04 05:15:34 +02:00
|
|
|
, optCslFile = []
|
|
|
|
#endif
|
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
|
2006-12-28 03:20:09 +01:00
|
|
|
(\arg opt -> return opt { optReader = map toLower arg })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FORMAT")
|
2008-09-08 08:36:28 +02:00
|
|
|
"" -- ("(" ++ (intercalate ", " $ map fst readers) ++ ")")
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
, Option "tw" ["to","write"]
|
|
|
|
(ReqArg
|
2006-12-28 03:20:09 +01:00
|
|
|
(\arg opt -> return opt { optWriter = map toLower arg })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FORMAT")
|
2008-09-08 08:36:28 +02:00
|
|
|
"" -- ("(" ++ (intercalate ", " $ map fst writers) ++ ")")
|
2008-08-10 19:33:20 +02:00
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
, Option "s" ["standalone"]
|
|
|
|
(NoArg
|
2009-12-31 02:15:08 +01:00
|
|
|
(\opt -> return opt { optStandalone = True }))
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Include needed header and footer on output"
|
2006-10-17 16:22:29 +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
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
, Option "p" ["preserve-tabs"]
|
|
|
|
(NoArg
|
2009-04-08 22:19:50 +02:00
|
|
|
(\opt -> return opt { optPreserveTabs = True }))
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Preserve tabs instead of converting to spaces"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
, Option "" ["tab-stop"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> return opt { optTabStop = (read arg) } )
|
|
|
|
"TABSTOP")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "Tab stop (default 4)"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-12-30 23:51:49 +01:00
|
|
|
, Option "" ["strict"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optStrict = True } ))
|
2007-07-22 21:20:21 +02:00
|
|
|
"" -- "Disable markdown syntax extensions"
|
2006-12-30 23:51:49 +01:00
|
|
|
|
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
|
|
|
, Option "" ["reference-links"]
|
2007-03-03 19:19:31 +01:00
|
|
|
(NoArg
|
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
|
|
|
(\opt -> return opt { optReferenceLinks = True } ))
|
|
|
|
"" -- "Use reference links in parsing HTML"
|
2007-03-03 19:19:31 +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
|
|
|
|
2008-08-13 05:02:42 +02:00
|
|
|
, Option "m" ["latexmathml", "asciimathml"]
|
2007-07-26 04:19:20 +02:00
|
|
|
(OptArg
|
2009-12-31 02:13:16 +01:00
|
|
|
(\arg opt ->
|
|
|
|
return opt { optHTMLMathMethod = LaTeXMathML arg })
|
2007-07-26 04:19:20 +02:00
|
|
|
"URL")
|
2008-08-13 05:02:42 +02:00
|
|
|
"" -- "Use LaTeXMathML script in html output"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2010-03-18 07:45:56 +01:00
|
|
|
, Option "" ["mathml"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt ->
|
|
|
|
return opt { optHTMLMathMethod = MathML arg })
|
|
|
|
"URL")
|
|
|
|
"" -- "Use mathml for HTML math"
|
|
|
|
|
2007-12-01 04:11:52 +01:00
|
|
|
, Option "" ["mimetex"]
|
|
|
|
(OptArg
|
2010-07-16 04:01:00 +02:00
|
|
|
(\arg opt -> do
|
2010-07-21 20:24:37 +02:00
|
|
|
let url' = case arg of
|
2010-07-16 04:01:00 +02:00
|
|
|
Just u -> u ++ "?"
|
|
|
|
Nothing -> "/cgi-bin/mimetex.cgi?"
|
2010-07-21 20:24:37 +02:00
|
|
|
return opt { optHTMLMathMethod = WebTeX url' })
|
2007-12-01 04:11:52 +01:00
|
|
|
"URL")
|
|
|
|
"" -- "Use mimetex for HTML math"
|
|
|
|
|
2010-07-16 04:01:00 +02:00
|
|
|
, Option "" ["webtex"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt -> do
|
2010-07-21 20:24:37 +02:00
|
|
|
let url' = case arg of
|
2010-07-16 04:01:00 +02:00
|
|
|
Just u -> u
|
|
|
|
Nothing -> "http://chart.apis.google.com/chart?cht=tx&chl="
|
2010-07-21 20:24:37 +02:00
|
|
|
return opt { optHTMLMathMethod = WebTeX url' })
|
2010-07-16 04:01:00 +02:00
|
|
|
"URL")
|
|
|
|
"" -- "Use web service for HTML math"
|
|
|
|
|
2008-10-28 22:54:50 +01:00
|
|
|
, Option "" ["jsmath"]
|
|
|
|
(OptArg
|
|
|
|
(\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
|
|
|
|
"URL")
|
|
|
|
"" -- "Use jsMath for HTML math"
|
|
|
|
|
2007-12-01 04:11:52 +01:00
|
|
|
, Option "" ["gladtex"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optHTMLMathMethod = GladTeX }))
|
|
|
|
"" -- "Use gladtex for HTML math"
|
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
, Option "i" ["incremental"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optIncremental = True }))
|
2010-07-14 05:44:56 +02:00
|
|
|
"" -- "Make list items display incrementally in Slidy/S5"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2009-12-31 02:18:06 +01:00
|
|
|
, Option "" ["xetex"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optXeTeX = True }))
|
|
|
|
"" -- "Format latex for processing by XeTeX"
|
|
|
|
|
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
|
|
|
|
2010-07-16 04:01:00 +02:00
|
|
|
, Option "" ["section-divs"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optSectionDivs = True }))
|
|
|
|
"" -- "Put sections in div tags in HTML"
|
|
|
|
|
2007-09-27 03:23:44 +02:00
|
|
|
, Option "" ["no-wrap"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optWrapText = False }))
|
|
|
|
"" -- "Do not wrap text in output"
|
|
|
|
|
2008-01-03 22:32:32 +01:00
|
|
|
, Option "" ["sanitize-html"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optSanitizeHTML = True }))
|
|
|
|
"" -- "Sanitize HTML"
|
|
|
|
|
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
|
2010-05-07 05:29:44 +02:00
|
|
|
_ -> UTF8.hPutStrLn stderr ("Error: Unknown obfuscation method: " ++ arg) >>
|
2009-01-24 20:58:48 +01:00
|
|
|
exitWith (ExitFailure 6)
|
|
|
|
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"
|
|
|
|
|
2009-12-05 05:46:57 +01:00
|
|
|
, Option "" ["indented-code-classes"]
|
2009-12-01 07:56:47 +01:00
|
|
|
(ReqArg
|
2009-12-05 05:46:57 +01:00
|
|
|
(\arg opt -> return opt { optIndentedCodeClasses = words $
|
2009-12-01 07:56:47 +01:00
|
|
|
map (\c -> if c == ',' then ' ' else c) arg })
|
|
|
|
"STRING")
|
|
|
|
"" -- "Classes (whitespace- or comma-separated) to use for indented code-blocks"
|
|
|
|
|
2007-07-12 05:27:24 +02:00
|
|
|
, Option "" ["toc", "table-of-contents"]
|
|
|
|
(NoArg
|
|
|
|
(\opt -> return opt { optTableOfContents = True }))
|
2008-08-10 19:33:20 +02:00
|
|
|
"" -- "Include table of contents"
|
2007-07-12 05:27:24 +02:00
|
|
|
|
2010-03-15 00:23:26 +01:00
|
|
|
, Option "" ["base-header-level"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
if all isDigit arg && (read arg :: Int) >= 1
|
2010-03-18 07:45:28 +01:00
|
|
|
then do
|
|
|
|
let oldTransforms = optTransforms opt
|
|
|
|
let shift = read arg - 1
|
|
|
|
return opt{ optTransforms =
|
|
|
|
headerShift shift : oldTransforms }
|
2010-03-15 00:23:26 +01:00
|
|
|
else do
|
2010-05-07 05:29:44 +02:00
|
|
|
UTF8.hPutStrLn stderr $ "base-header-level must be a number >= 1"
|
2010-03-15 00:23:26 +01:00
|
|
|
exitWith $ ExitFailure 19)
|
|
|
|
"LEVEL")
|
|
|
|
"" -- "Headers base level"
|
|
|
|
|
2009-12-31 02:10:04 +01:00
|
|
|
, Option "" ["template"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2010-05-07 05:29:44 +02:00
|
|
|
text <- UTF8.readFile arg
|
2009-12-31 02:10:04 +01:00
|
|
|
return opt{ optTemplate = text,
|
|
|
|
optStandalone = True })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "Use custom template"
|
|
|
|
|
2009-12-31 02:10:26 +01:00
|
|
|
, Option "V" ["variable"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt ->
|
|
|
|
case break (`elem` ":=") arg of
|
|
|
|
(k,_:v) -> do
|
2009-12-31 02:15:50 +01:00
|
|
|
let newvars = optVariables opt ++ [(k,v)]
|
2009-12-31 02:10:26 +01:00
|
|
|
return opt{ optVariables = newvars }
|
|
|
|
_ -> do
|
2010-05-07 05:29:44 +02:00
|
|
|
UTF8.hPutStrLn stderr $ "Could not parse `" ++ arg ++ "' as a key/value pair (k=v or k:v)"
|
2009-12-31 02:10:26 +01:00
|
|
|
exitWith $ ExitFailure 17)
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "Use custom template"
|
|
|
|
|
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
|
|
|
|
|
|
|
, Option "H" ["include-in-header"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2010-05-07 05:29:44 +02:00
|
|
|
text <- UTF8.readFile arg
|
2009-12-31 02:15:50 +01:00
|
|
|
-- add new ones to end, so they're included in order specified
|
|
|
|
let newvars = optVariables opt ++ [("header-includes",text)]
|
2009-12-31 02:10:32 +01:00
|
|
|
return opt { optVariables = newvars,
|
2006-12-20 07:50:14 +01:00
|
|
|
optStandalone = True })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FILENAME")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "File to include at end of header (implies -s)"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
, Option "B" ["include-before-body"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2010-05-07 05:29:44 +02:00
|
|
|
text <- UTF8.readFile arg
|
2010-03-13 05:11:24 +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 })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FILENAME")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "File to include before document body"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
, Option "A" ["include-after-body"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2010-05-07 05:29:44 +02:00
|
|
|
text <- UTF8.readFile arg
|
2010-03-13 05:11:24 +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 })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FILENAME")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "File to include after document body"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
, Option "C" ["custom-header"]
|
2006-10-17 16:22:29 +02:00
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
2010-05-07 05:29:44 +02:00
|
|
|
text <- UTF8.readFile arg
|
2009-12-31 02:09:56 +01:00
|
|
|
let newVars = ("legacy-header", text) : optVariables opt
|
|
|
|
return opt { optVariables = newVars
|
|
|
|
, optStandalone = True })
|
2006-10-17 16:22:29 +02:00
|
|
|
"FILENAME")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "File to use for custom header (implies -s)"
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
, Option "T" ["title-prefix"]
|
|
|
|
(ReqArg
|
2009-12-31 02:10:17 +01:00
|
|
|
(\arg opt -> do
|
|
|
|
let newvars = ("title-prefix", arg) : optVariables opt
|
|
|
|
return opt { optVariables = newvars,
|
|
|
|
optStandalone = True })
|
2006-10-17 16:22:29 +02:00
|
|
|
"STRING")
|
2006-12-31 02:12:01 +01:00
|
|
|
"" -- "String to prefix to HTML window title"
|
2008-08-10 19:33:20 +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"
|
|
|
|
|
2010-07-03 07:07:00 +02:00
|
|
|
, Option "" ["epub-stylesheet"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
text <- UTF8.readFile arg
|
|
|
|
return opt { optEPUBStylesheet = Just text })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "Path of epub.css"
|
|
|
|
|
2010-07-05 01:56:17 +02:00
|
|
|
, Option "" ["epub-metadata"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> do
|
|
|
|
text <- UTF8.readFile arg
|
|
|
|
return opt { optEPUBMetadata = text })
|
|
|
|
"FILENAME")
|
|
|
|
"" -- "Path of epub metadata file"
|
|
|
|
|
2009-12-31 02:09:36 +01:00
|
|
|
, Option "D" ["print-default-template"]
|
2006-10-17 16:22:29 +02:00
|
|
|
(ReqArg
|
2008-06-17 20:55:42 +02:00
|
|
|
(\arg _ -> do
|
2010-01-18 06:06:08 +01:00
|
|
|
templ <- getDefaultTemplate Nothing arg
|
2009-12-31 02:10:57 +01:00
|
|
|
case templ of
|
2010-05-07 05:29:44 +02:00
|
|
|
Right t -> UTF8.hPutStr stdout t
|
2009-12-31 02:10:57 +01:00
|
|
|
Left e -> error $ show e
|
2006-10-17 16:22:29 +02:00
|
|
|
exitWith ExitSuccess)
|
|
|
|
"FORMAT")
|
2009-12-31 02:09:36 +01:00
|
|
|
"" -- "Print default template for FORMAT"
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
2008-12-29 23:45:18 +01:00
|
|
|
, Option "" ["biblio"]
|
2008-08-04 05:15:34 +02:00
|
|
|
(ReqArg
|
2008-12-29 23:45:18 +01:00
|
|
|
(\arg opt -> return opt { optBiblioFile = arg} )
|
2008-08-04 05:15:34 +02:00
|
|
|
"FILENAME")
|
|
|
|
""
|
2008-12-29 23:45:18 +01:00
|
|
|
, Option "" ["biblio-format"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> return opt { optBiblioFormat = arg} )
|
|
|
|
"STRING")
|
|
|
|
""
|
2008-08-04 05:15:34 +02:00
|
|
|
, Option "" ["csl"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> return opt { optCslFile = arg} )
|
|
|
|
"FILENAME")
|
|
|
|
""
|
|
|
|
#endif
|
2010-01-14 06:54:38 +01:00
|
|
|
, Option "" ["data-dir"]
|
|
|
|
(ReqArg
|
|
|
|
(\arg opt -> return opt { optDataDir = Just arg })
|
|
|
|
"DIRECTORY") -- "Directory containing pandoc data files."
|
|
|
|
""
|
|
|
|
|
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
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
, Option "v" ["version"]
|
|
|
|
(NoArg
|
|
|
|
(\_ -> do
|
|
|
|
prg <- getProgName
|
2010-05-07 05:29:44 +02:00
|
|
|
UTF8.hPutStrLn stdout (prg ++ " " ++ pandocVersion ++ compileInfo ++
|
2006-12-22 21:16:03 +01:00
|
|
|
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
|
2010-05-07 05:29:44 +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"
|
2006-10-17 16:22:29 +02:00
|
|
|
]
|
2006-12-22 21:16:03 +01:00
|
|
|
|
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: " ++
|
2008-09-08 08:36:28 +02:00
|
|
|
(intercalate ", " $ map fst readers) ++ "\nOutput formats: " ++
|
|
|
|
(intercalate ", " $ map fst writers) ++ "\nOptions:")
|
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"
|
2008-12-02 23:43:17 +01:00
|
|
|
".lhs" -> "markdown+lhs"
|
2008-02-09 04:21:04 +01:00
|
|
|
".native" -> "native"
|
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"
|
|
|
|
".txt" -> "markdown"
|
|
|
|
".text" -> "markdown"
|
|
|
|
".md" -> "markdown"
|
|
|
|
".markdown" -> "markdown"
|
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"
|
2010-07-03 07:07:00 +02:00
|
|
|
".epub" -> "epub"
|
2008-06-17 20:55:42 +02:00
|
|
|
['.',y] | y `elem` ['1'..'9'] -> "man"
|
2008-02-09 04:21:04 +01:00
|
|
|
_ -> "html"
|
2006-12-22 21:16:03 +01:00
|
|
|
|
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
|
|
|
|
2010-05-05 08:36:03 +02:00
|
|
|
rawArgs <- liftM (map decodeString) 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) $
|
|
|
|
do name <- getProgName
|
2010-05-07 05:29:44 +02:00
|
|
|
mapM_ (\e -> UTF8.hPutStr stderr (name ++ ": ") >> UTF8.hPutStr stderr e) errors
|
|
|
|
UTF8.hPutStrLn stderr $ "Try " ++ name ++ " --help for more information."
|
2009-01-24 20:59:07 +01:00
|
|
|
exitWith $ ExitFailure 2
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2008-08-10 19:33:20 +02:00
|
|
|
let defaultOpts' = if compatMode
|
2007-01-02 08:37:42 +01:00
|
|
|
then defaultOpts { optReader = "markdown"
|
|
|
|
, optWriter = "html"
|
|
|
|
, optStrict = True }
|
|
|
|
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
|
|
|
|
2009-04-08 22:19:50 +02:00
|
|
|
let Opt { optTabStop = tabStop
|
|
|
|
, optPreserveTabs = preserveTabs
|
2006-10-17 16:22:29 +02:00
|
|
|
, optStandalone = standalone
|
2006-12-28 03:20:09 +01:00
|
|
|
, optReader = readerName
|
|
|
|
, optWriter = writerName
|
2006-10-17 16:22:29 +02:00
|
|
|
, optParseRaw = parseRaw
|
2009-12-31 02:09:56 +01:00
|
|
|
, optVariables = variables
|
2007-07-07 07:43:23 +02:00
|
|
|
, optTableOfContents = toc
|
2010-03-18 07:45:28 +01:00
|
|
|
, optTransforms = transforms
|
2009-12-31 02:10:04 +01:00
|
|
|
, optTemplate = template
|
2006-12-22 21:16:03 +01:00
|
|
|
, optOutputFile = outputFile
|
2006-10-17 16:22:29 +02:00
|
|
|
, optNumberSections = numberSections
|
2010-07-16 04:01:00 +02:00
|
|
|
, optSectionDivs = sectionDivs
|
2006-10-17 16:22:29 +02:00
|
|
|
, optIncremental = incremental
|
2009-12-31 02:18:06 +01:00
|
|
|
, optXeTeX = xetex
|
2006-12-18 23:02:39 +01:00
|
|
|
, optSmart = smart
|
2007-12-01 04:11:52 +01:00
|
|
|
, optHTMLMathMethod = mathMethod
|
2009-12-31 23:40:59 +01:00
|
|
|
, optReferenceODT = referenceODT
|
2010-07-03 07:07:00 +02:00
|
|
|
, optEPUBStylesheet = epubStylesheet
|
2010-07-05 01:56:17 +02:00
|
|
|
, optEPUBMetadata = epubMetadata
|
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 = dumpArgs
|
|
|
|
, optIgnoreArgs = ignoreArgs
|
2006-12-30 23:51:49 +01:00
|
|
|
, optStrict = strict
|
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 = referenceLinks
|
2007-09-27 03:23:44 +02:00
|
|
|
, optWrapText = wrap
|
2008-01-03 22:32:32 +01:00
|
|
|
, optSanitizeHTML = sanitize
|
2009-01-24 20:58:48 +01:00
|
|
|
, optEmailObfuscation = obfuscationMethod
|
2009-12-05 18:56:02 +01:00
|
|
|
, optIdentifierPrefix = idPrefix
|
2009-12-05 05:46:57 +01:00
|
|
|
, optIndentedCodeClasses = codeBlockClasses
|
2010-01-14 06:54:38 +01:00
|
|
|
, optDataDir = mbDataDir
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
2009-01-24 20:58:48 +01:00
|
|
|
, optBiblioFile = biblioFile
|
|
|
|
, optBiblioFormat = biblioFormat
|
|
|
|
, optCslFile = cslFile
|
2008-08-04 05:15:34 +02:00
|
|
|
#endif
|
2006-10-17 16:22:29 +02:00
|
|
|
} = opts
|
|
|
|
|
2009-01-24 20:59:07 +01:00
|
|
|
when dumpArgs $
|
2010-05-07 05:29:44 +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
|
|
|
|
2010-01-02 19:19:19 +01:00
|
|
|
-- warn about deprecated options
|
|
|
|
case lookup "legacy-header" variables of
|
2010-05-07 05:29:44 +02:00
|
|
|
Just _ -> UTF8.hPutStrLn stderr $
|
2010-01-02 19:19:19 +01:00
|
|
|
"Warning: The -C/--custom-header is deprecated.\n" ++
|
|
|
|
"Please transition to using --template instead."
|
|
|
|
Nothing -> return ()
|
|
|
|
|
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
|
2010-02-21 17:47:24 +01:00
|
|
|
Nothing -> catch
|
|
|
|
(liftM Just $ getAppUserDataDirectory "pandoc")
|
|
|
|
(const $ return Nothing)
|
|
|
|
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
|
2008-08-10 19:33:20 +02:00
|
|
|
let readerName' = if null readerName
|
2010-03-18 07:45:50 +01:00
|
|
|
then let fallback = if any isURI sources
|
|
|
|
then "html"
|
|
|
|
else "markdown"
|
|
|
|
in defaultReaderName fallback sources
|
2008-12-02 23:43:17 +01:00
|
|
|
else readerName
|
2006-12-28 03:20:09 +01:00
|
|
|
|
2008-08-10 19:33:20 +02:00
|
|
|
let writerName' = if null writerName
|
2006-12-28 03:20:09 +01:00
|
|
|
then defaultWriterName outputFile
|
|
|
|
else writerName
|
|
|
|
|
|
|
|
reader <- case (lookup readerName' readers) of
|
|
|
|
Just r -> return r
|
|
|
|
Nothing -> error ("Unknown reader: " ++ readerName')
|
|
|
|
|
2010-07-09 02:51:13 +02:00
|
|
|
let writer = case lookup writerName' writers of
|
|
|
|
Just _ | writerName' == "epub" -> writeEPUB epubStylesheet
|
|
|
|
Just _ | writerName' == "odt" -> writeODT referenceODT
|
|
|
|
Just r -> \o ->
|
|
|
|
return . fromString . r o
|
|
|
|
Nothing -> error $ "Unknown writer: " ++
|
|
|
|
writerName'
|
2009-12-31 02:10:57 +01:00
|
|
|
|
2010-02-21 17:47:24 +01:00
|
|
|
templ <- getDefaultTemplate datadir writerName'
|
2009-12-31 02:10:57 +01:00
|
|
|
let defaultTemplate = case templ of
|
|
|
|
Right t -> t
|
|
|
|
Left e -> error (show e)
|
2006-12-22 21:16:03 +01:00
|
|
|
|
2007-01-15 20:52:42 +01:00
|
|
|
environment <- getEnvironment
|
|
|
|
let columns = case lookup "COLUMNS" environment of
|
|
|
|
Just cols -> read cols
|
|
|
|
Nothing -> stateColumns defaultParserState
|
|
|
|
|
2009-05-01 06:18:07 +02:00
|
|
|
let standalone' = standalone || isNonTextOutput writerName'
|
2008-08-01 01:16:02 +02:00
|
|
|
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
2008-12-29 23:45:18 +01:00
|
|
|
refs <- if null biblioFile then return [] else readBiblioFile biblioFile biblioFormat
|
2008-08-04 05:15:34 +02:00
|
|
|
#endif
|
|
|
|
|
2009-12-31 02:11:13 +01:00
|
|
|
variables' <- if writerName' == "s5" && standalone'
|
|
|
|
then do
|
2010-02-21 17:47:24 +01:00
|
|
|
inc <- s5HeaderIncludes datadir
|
2009-12-31 02:15:50 +01:00
|
|
|
return $ ("header-includes", inc) : variables
|
2009-12-31 02:11:13 +01:00
|
|
|
else return variables
|
|
|
|
|
2009-12-31 02:13:16 +01:00
|
|
|
variables'' <- case mathMethod of
|
2009-12-31 02:13:26 +01:00
|
|
|
LaTeXMathML Nothing -> do
|
2010-03-18 07:45:56 +01:00
|
|
|
s <- readDataFile datadir $ "data" </> "LaTeXMathML.js"
|
|
|
|
return $ ("mathml-script", s) : variables'
|
|
|
|
MathML Nothing -> do
|
|
|
|
s <- readDataFile datadir $ "data"</>"MathMLinHTML.js"
|
|
|
|
return $ ("mathml-script", s) : variables'
|
2009-12-31 02:13:16 +01:00
|
|
|
_ -> return variables'
|
|
|
|
|
2010-07-09 02:14:03 +02:00
|
|
|
let sourceDir = if null sources
|
|
|
|
then "."
|
|
|
|
else takeDirectory (head sources)
|
|
|
|
|
2010-07-14 05:44:56 +02:00
|
|
|
let slideVariant = case writerName' of
|
|
|
|
"s5" -> S5Slides
|
|
|
|
"slidy" -> SlidySlides
|
|
|
|
_ -> NoSlides
|
|
|
|
|
2008-08-10 19:33:20 +02:00
|
|
|
let startParserState =
|
2008-12-02 23:41:51 +01:00
|
|
|
defaultParserState { stateParseRaw = parseRaw,
|
|
|
|
stateTabStop = tabStop,
|
|
|
|
stateSanitizeHTML = sanitize,
|
2008-12-02 23:43:17 +01:00
|
|
|
stateLiterateHaskell = "+lhs" `isSuffixOf` readerName' ||
|
2008-12-02 23:41:51 +01:00
|
|
|
lhsExtension sources,
|
|
|
|
stateStandalone = standalone',
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
2008-12-02 23:41:51 +01:00
|
|
|
stateCitations = map citeKey refs,
|
2008-08-04 05:15:34 +02:00
|
|
|
#endif
|
2008-12-02 23:41:51 +01:00
|
|
|
stateSmart = smart || writerName' `elem`
|
2009-06-06 23:27:40 +02:00
|
|
|
["latex", "context", "man"],
|
2008-12-02 23:41:51 +01:00
|
|
|
stateColumns = columns,
|
2009-12-01 07:56:47 +01:00
|
|
|
stateStrict = strict,
|
2009-12-05 05:46:57 +01:00
|
|
|
stateIndentedCodeClasses = codeBlockClasses }
|
2010-07-09 02:14:03 +02:00
|
|
|
|
2009-01-24 20:58:48 +01:00
|
|
|
let writerOptions = WriterOptions { writerStandalone = standalone',
|
2009-12-31 02:10:17 +01:00
|
|
|
writerTemplate = if null template
|
2009-12-31 02:10:04 +01:00
|
|
|
then defaultTemplate
|
|
|
|
else template,
|
2009-12-31 02:13:16 +01:00
|
|
|
writerVariables = variables'',
|
2010-07-05 01:56:17 +02:00
|
|
|
writerEPUBMetadata = epubMetadata,
|
2009-01-24 20:58:48 +01:00
|
|
|
writerTabStop = tabStop,
|
|
|
|
writerTableOfContents = toc &&
|
|
|
|
writerName' /= "s5",
|
|
|
|
writerHTMLMathMethod = mathMethod,
|
2010-07-14 05:44:56 +02:00
|
|
|
writerSlideVariant = slideVariant,
|
|
|
|
writerIncremental = incremental,
|
2009-12-31 02:18:06 +01:00
|
|
|
writerXeTeX = xetex,
|
2009-01-24 20:58:48 +01:00
|
|
|
writerIgnoreNotes = False,
|
|
|
|
writerNumberSections = numberSections,
|
2010-07-16 04:01:00 +02:00
|
|
|
writerSectionDivs = sectionDivs,
|
2009-01-24 20:58:48 +01:00
|
|
|
writerStrictMarkdown = strict,
|
|
|
|
writerReferenceLinks = referenceLinks,
|
|
|
|
writerWrapText = wrap,
|
|
|
|
writerLiterateHaskell = "+lhs" `isSuffixOf` writerName' ||
|
|
|
|
lhsExtension [outputFile],
|
|
|
|
writerEmailObfuscation = if strict
|
|
|
|
then ReferenceObfuscation
|
2009-12-05 18:56:02 +01:00
|
|
|
else obfuscationMethod,
|
2010-07-09 02:14:03 +02:00
|
|
|
writerIdentifierPrefix = idPrefix,
|
2010-07-09 02:31:55 +02:00
|
|
|
writerSourceDirectory = sourceDir,
|
|
|
|
writerUserDataDir = datadir }
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2009-01-24 20:59:07 +01:00
|
|
|
when (isNonTextOutput writerName' && outputFile == "-") $
|
2010-05-07 05:29:44 +02:00
|
|
|
do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
|
2008-08-10 19:33:20 +02:00
|
|
|
"Specify an output file using the -o option.")
|
2009-01-24 20:59:07 +01:00
|
|
|
exitWith $ ExitFailure 5
|
2008-08-10 19:33:20 +02:00
|
|
|
|
2009-01-24 20:58:06 +01:00
|
|
|
let readSources [] = mapM readSource ["-"]
|
|
|
|
readSources srcs = mapM readSource srcs
|
2010-05-07 05:29:44 +02:00
|
|
|
readSource "-" = UTF8.getContents
|
2010-02-02 08:37:01 +01:00
|
|
|
readSource src = case parseURI src of
|
|
|
|
Just u -> readURI u
|
2010-05-07 05:29:44 +02:00
|
|
|
Nothing -> UTF8.readFile src
|
2010-02-02 08:37:01 +01:00
|
|
|
readURI uri = simpleHTTP (mkRequest GET uri) >>= getResponseBody >>=
|
|
|
|
return . toString -- treat all as UTF8
|
2009-01-24 20:58:06 +01:00
|
|
|
|
2009-04-08 22:19:50 +02:00
|
|
|
let convertTabs = tabFilter (if preserveTabs then 0 else tabStop)
|
|
|
|
|
|
|
|
doc <- fmap (reader startParserState . convertTabs . intercalate "\n") (readSources sources)
|
2008-08-01 01:16:02 +02:00
|
|
|
|
2010-03-18 07:45:28 +01:00
|
|
|
let doc' = foldr ($) doc transforms
|
2010-03-15 00:23:26 +01:00
|
|
|
|
|
|
|
doc'' <- do
|
2008-08-04 05:15:34 +02:00
|
|
|
#ifdef _CITEPROC
|
2010-03-15 00:23:26 +01:00
|
|
|
processBiblio cslFile refs doc'
|
2009-01-24 20:58:06 +01:00
|
|
|
#else
|
2010-03-15 00:23:26 +01:00
|
|
|
return doc'
|
2008-08-04 05:15:34 +02:00
|
|
|
#endif
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2010-07-03 05:12:14 +02:00
|
|
|
writerOutput <- writer writerOptions doc''
|
2010-01-14 06:54:38 +01:00
|
|
|
|
2010-07-03 05:12:14 +02:00
|
|
|
if outputFile == "-"
|
2010-07-20 21:42:12 +02:00
|
|
|
then B.putStr writerOutput
|
2010-07-03 05:12:14 +02:00
|
|
|
else B.writeFile outputFile writerOutput
|