diff options
author | dr@jones.dk <dr@jones.dk> | 2011-04-14 01:32:00 +0200 |
---|---|---|
committer | dr@jones.dk <dr@jones.dk> | 2011-04-14 01:32:00 +0200 |
commit | 6479926bb9955dcbf0d175d053e2b38c44d59507 (patch) | |
tree | 476dcf48e48e4ef2d049b892991f95e0fabed62f /src | |
parent | b880b82b7f4b7c50d79f015eaf635f4b3bd8a1a3 (diff) |
Imported Upstream version 1.8.1.1
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/UTF8.hs | 5 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 3 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 46 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 2 | ||||
-rw-r--r-- | src/markdown2pdf.hs | 12 | ||||
-rw-r--r-- | src/pandoc.hs | 19 |
7 files changed, 57 insertions, 34 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 8326c89ae..c4bc66830 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -490,6 +490,7 @@ data WriterOptions = WriterOptions , writerHtml5 :: Bool -- ^ Produce HTML5 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects , writerListings :: Bool -- ^ Use listings package for code + , writerAscii :: Bool -- ^ Avoid non-ascii characters } deriving Show -- | Default writer options. @@ -507,7 +508,7 @@ defaultWriterOptions = , writerHTMLMathMethod = PlainMath , writerIgnoreNotes = False , writerNumberSections = False - , writerSectionDivs = True + , writerSectionDivs = False , writerStrictMarkdown = False , writerReferenceLinks = False , writerWrapText = True @@ -522,6 +523,7 @@ defaultWriterOptions = , writerHtml5 = False , writerChapters = False , writerListings = False + , writerAscii = False } -- diff --git a/src/Text/Pandoc/UTF8.hs b/src/Text/Pandoc/UTF8.hs index a77f92cdc..4af155882 100644 --- a/src/Text/Pandoc/UTF8.hs +++ b/src/Text/Pandoc/UTF8.hs @@ -44,15 +44,16 @@ where import System.IO hiding (readFile, writeFile, getContents, putStr, putStrLn, hPutStr, hPutStrLn, hGetContents) import Prelude hiding (readFile, writeFile, getContents, putStr, putStrLn ) +import Codec.Binary.UTF8.String (encodeString) import qualified System.IO as IO readFile :: FilePath -> IO String readFile f = do - h <- openFile f ReadMode + h <- openFile (encodeString f) ReadMode hGetContents h writeFile :: FilePath -> String -> IO () -writeFile f s = withFile f WriteMode $ \h -> hPutStr h s +writeFile f s = withFile (encodeString f) WriteMode $ \h -> hPutStr h s getContents :: IO String getContents = hGetContents stdin diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 33b8aa76a..c0cc815d4 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -276,6 +276,9 @@ pageTemplate = unlines , "$endfor$" , "$else$" , "<h1>$title$</h1>" + , "$if(toc)$" + , "$toc$" + , "$endif$" , "$body$" , "$endif$" , "</body>" diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index aba73a417..b3320fa06 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -43,6 +43,7 @@ import Data.List ( isPrefixOf, intersperse ) import Data.Maybe ( catMaybes ) import Control.Monad.State import Text.XHtml.Transitional hiding ( stringToHtml, unordList, ordList ) +import qualified Text.XHtml.Transitional as XHtml import Text.TeXMath import Text.XML.Light.Output @@ -60,8 +61,10 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stHighlighting = -- | Modified version of Text.XHtml's stringToHtml. -- Use unicode characters wherever possible. -stringToHtml :: String -> Html -stringToHtml = primHtml . escapeStringForXML +stringToHtml :: WriterOptions -> String -> Html +stringToHtml opts = if writerAscii opts + then XHtml.stringToHtml + else primHtml . escapeStringForXML -- | Hard linebreak. nl :: WriterOptions -> Html @@ -219,7 +222,7 @@ elementToListItem _ (Blk _) = return Nothing elementToListItem opts (Sec _ num id' headerText subsecs) = do let sectnum = if writerNumberSections opts then (thespan ! [theclass "toc-section-number"] << showSecNum num) +++ - stringToHtml " " + stringToHtml opts" " else noHtml txt <- liftM (sectnum +++) $ inlineListToHtml opts headerText subHeads <- mapM (elementToListItem opts) subsecs >>= return . catMaybes @@ -245,9 +248,11 @@ elementToHtml opts (Sec level num id' title' elements) = do else if writerSectionDivs opts then if writerHtml5 opts then tag "section" ! [prefixedId opts id'] - << intersperse (nl opts) stuff + << (nl opts : (intersperse (nl opts) stuff + ++ [nl opts])) else thediv ! [prefixedId opts id'] << - intersperse (nl opts) stuff + (nl opts : (intersperse (nl opts) stuff + ++ [nl opts])) else toHtmlFromList $ intersperse (nl opts) stuff -- | Convert list of Note blocks to a footnote <div>. @@ -299,7 +304,7 @@ obfuscateLink opts txt s = linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) +++ noscript (primHtml $ obfuscateString altText) _ -> error $ "Unknown obfuscation method: " ++ show meth - _ -> anchor ! [href s] $ stringToHtml txt -- malformed email + _ -> anchor ! [href s] $ stringToHtml opts txt -- malformed email -- | Obfuscate character as entity. obfuscateChar :: Char -> String @@ -351,7 +356,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do else unlines . lines in return $ pre ! attrs $ thecode << (replicate (length leadingBreaks) br +++ - [stringToHtml $ addBird rawCode']) + [stringToHtml opts $ addBird rawCode']) Right h -> modify (\st -> st{ stHighlighting = True }) >> return h blockToHtml opts (BlockQuote blocks) = @@ -377,7 +382,7 @@ blockToHtml opts (Header level lst) = do secnum <- liftM stSecNum get let contents' = if writerNumberSections opts then (thespan ! [theclass "header-section-number"] << showSecNum secnum) +++ - stringToHtml " " +++ contents + stringToHtml opts " " +++ contents else contents let contents'' = if writerTableOfContents opts then anchor ! [href $ "#" ++ writerIdentifierPrefix opts ++ "TOC"] $ contents' @@ -510,19 +515,19 @@ inlineListToHtml opts lst = inlineToHtml :: WriterOptions -> Inline -> State WriterState Html inlineToHtml opts inline = case inline of - (Str str) -> return $ stringToHtml str - (Space) -> return $ stringToHtml " " + (Str str) -> return $ stringToHtml opts str + (Space) -> return $ stringToHtml opts " " (LineBreak) -> return br - (EmDash) -> return $ stringToHtml "—" - (EnDash) -> return $ stringToHtml "–" - (Ellipses) -> return $ stringToHtml "…" - (Apostrophe) -> return $ stringToHtml "’" + (EmDash) -> return $ stringToHtml opts "—" + (EnDash) -> return $ stringToHtml opts "–" + (Ellipses) -> return $ stringToHtml opts "…" + (Apostrophe) -> return $ stringToHtml opts "’" (Emph lst) -> inlineListToHtml opts lst >>= return . emphasize (Strong lst) -> inlineListToHtml opts lst >>= return . strong (Code attr str) -> case highlightHtml True attr str of Left _ -> return $ thecode ! (attrsToHtml opts attr) - $ stringToHtml str + $ stringToHtml opts str Right h -> return h (Strikeout lst) -> inlineListToHtml opts lst >>= return . (thespan ! [thestyle "text-decoration: line-through;"]) @@ -532,10 +537,10 @@ inlineToHtml opts inline = (Subscript lst) -> inlineListToHtml opts lst >>= return . sub (Quoted quoteType lst) -> let (leftQuote, rightQuote) = case quoteType of - SingleQuote -> (stringToHtml "‘", - stringToHtml "’") - DoubleQuote -> (stringToHtml "“", - stringToHtml "”") + SingleQuote -> (stringToHtml opts "‘", + stringToHtml opts "’") + DoubleQuote -> (stringToHtml opts "“", + stringToHtml opts "”") in do contents <- inlineListToHtml opts lst return $ leftQuote +++ contents +++ rightQuote (Math t str) -> modify (\st -> st {stMath = True}) >> @@ -632,7 +637,8 @@ blockListToNote opts ref blocks = -- that block. Otherwise, insert a new Plain block with the backlink. let backlink = [RawInline "html" $ " <a href=\"#" ++ writerIdentifierPrefix opts ++ "fnref" ++ ref ++ "\" class=\"footnoteBackLink\"" ++ - " title=\"Jump back to footnote " ++ ref ++ "\">↩</a>"] + " title=\"Jump back to footnote " ++ ref ++ "\">" ++ + (if writerAscii opts then "↩" else "↩") ++ "</a>"] blocks' = if null blocks then [] else let lastBlock = last blocks diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 28a1e7174..7dd736da4 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -163,7 +163,7 @@ blockToLaTeX (Plain lst) = inlineListToLaTeX lst blockToLaTeX (Para [Image txt (src,tit)]) = do capt <- inlineListToLaTeX txt img <- inlineToLaTeX (Image txt (src,tit)) - return $ "\\begin{figure}[htb]" $$ "\\centering" $$ img $$ + return $ "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$ ("\\caption{" <> capt <> char '}') $$ "\\end{figure}" $$ blankline blockToLaTeX (Para lst) = do result <- inlineListToLaTeX lst diff --git a/src/markdown2pdf.hs b/src/markdown2pdf.hs index c61aaa8cb..005717bf0 100644 --- a/src/markdown2pdf.hs +++ b/src/markdown2pdf.hs @@ -14,11 +14,13 @@ import System.Exit (ExitCode (..), exitWith) import System.FilePath import System.Directory import System.Process (readProcessWithExitCode) - +import Codec.Binary.UTF8.String (decodeString, encodeString) +import Control.Monad (liftM) run :: FilePath -> [String] -> IO (Either String String) run file opts = do - (code, out, err) <- readProcessWithExitCode file opts "" + (code, out, err) <- readProcessWithExitCode (encodeString file) + (map encodeString opts) "" let msg = out ++ err case code of ExitFailure _ -> return $ Left $! msg @@ -122,14 +124,14 @@ saveStdin :: FilePath -> IO (Either String FilePath) saveStdin file = do text <- UTF8.getContents UTF8.writeFile file text - fileExist <- doesFileExist file + fileExist <- doesFileExist (encodeString file) case fileExist of False -> return $ Left $! "Could not create " ++ file True -> return $ Right file saveOutput :: FilePath -> FilePath -> IO () saveOutput input output = do - copyFile input output + copyFile (encodeString input) (encodeString output) UTF8.hPutStrLn stderr $! "Created " ++ output main :: IO () @@ -145,7 +147,7 @@ main = bracket -- run computation $ \tmp -> do - args <- getArgs + args <- liftM (map decodeString) getArgs -- check for invalid arguments and print help message if needed let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"] let goodoptslong = ["--from","--read","--strict", diff --git a/src/pandoc.hs b/src/pandoc.hs index c0f457449..27e4579aa 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -1,5 +1,5 @@ {- -Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu> +Copyright (C) 2006-2011 John MacFarlane <jgm@berkeley.edu> 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 @@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA {- | Module : Main - Copyright : Copyright (C) 2006-2010 John MacFarlane + Copyright : Copyright (C) 2006-2011 John MacFarlane License : GNU GPL, version 2 or above Maintainer : John MacFarlane <jgm@berkeley@edu> @@ -55,7 +55,7 @@ import Data.ByteString.Lazy.UTF8 (toString ) import Codec.Binary.UTF8.String (decodeString, encodeString) copyrightMessage :: String -copyrightMessage = "\nCopyright (C) 2006-2010 John MacFarlane\n" ++ +copyrightMessage = "\nCopyright (C) 2006-2011 John MacFarlane\n" ++ "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." @@ -123,6 +123,7 @@ data Opt = Opt , optBibliography :: [String] , optCslFile :: FilePath , optListings :: Bool -- ^ Use listings package for code blocks + , optAscii :: Bool -- ^ Avoid using nonascii characters } -- | Defaults for command-line options. @@ -166,6 +167,7 @@ defaultOpts = Opt , optBibliography = [] , optCslFile = "" , optListings = False + , optAscii = False } -- | A list of functions, each transforming the options data structure @@ -347,6 +349,11 @@ options = "NUMBER") "" -- "Length of line in characters" + , Option "" ["ascii"] + (NoArg + (\opt -> return opt { optAscii = True })) + "" -- "Avoid using non-ascii characters in output" + , Option "" ["email-obfuscation"] (ReqArg (\arg opt -> do @@ -681,7 +688,8 @@ main = do , optBibliography = reffiles , optCslFile = cslfile , optCiteMethod = citeMethod - , optListings = listings + , optListings = listings + , optAscii = ascii } = opts when dumpArgs $ @@ -803,7 +811,8 @@ main = do writerHtml5 = html5 && "html" `isPrefixOf` writerName', writerChapters = chapters, - writerListings = listings } + writerListings = listings, + writerAscii = ascii } when (isNonTextOutput writerName' && outputFile == "-") $ do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++ |