git.iko.soy/typeable/pandoc
on master help sign in
Added --ascii option.
8f408e4John MacFarlane
@@ -292,6 +292,11 @@ Options
292`--columns`=*NUMBER*
292`--columns`=*NUMBER*
293: Specify length of lines in characters (for text wrapping).
293: Specify length of lines in characters (for text wrapping).
294
294
295+`--ascii`
296+: Use only ascii characters in output. Currently supported only
297+ for HTML output (which uses numerical entities instead of
298+ UTF-8 when this option is selected).
299+
295`--email-obfuscation=`*none|javascript|references*
300`--email-obfuscation=`*none|javascript|references*
296: Specify a method for obfuscating `mailto:` links in HTML documents.
301: Specify a method for obfuscating `mailto:` links in HTML documents.
297 *none* leaves `mailto:` links as they are. *javascript* obfuscates
302 *none* leaves `mailto:` links as they are. *javascript* obfuscates
src/Text/Pandoc/Shared.hs+2
@@ -490,6 +490,7 @@ data WriterOptions = WriterOptions
490 , writerHtml5 :: Bool -- ^ Produce HTML5
490 , writerHtml5 :: Bool -- ^ Produce HTML5
491 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
491 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
492 , writerListings :: Bool -- ^ Use listings package for code
492 , writerListings :: Bool -- ^ Use listings package for code
493+ , writerAscii :: Bool -- ^ Avoid non-ascii characters
493 } deriving Show
494 } deriving Show
494
495
495-- | Default writer options.
496-- | Default writer options.
@@ -522,6 +523,7 @@ defaultWriterOptions =
522 , writerHtml5 = False
523 , writerHtml5 = False
523 , writerChapters = False
524 , writerChapters = False
524 , writerListings = False
525 , writerListings = False
526+ , writerAscii = False
525 }
527 }
526
528
527--
529--
src/Text/Pandoc/Writers/HTML.hs+20−17
@@ -43,6 +43,7 @@ import Data.List ( isPrefixOf, intersperse )
43import Data.Maybe ( catMaybes )
43import Data.Maybe ( catMaybes )
44import Control.Monad.State
44import Control.Monad.State
45import Text.XHtml.Transitional hiding ( stringToHtml, unordList, ordList )
45import Text.XHtml.Transitional hiding ( stringToHtml, unordList, ordList )
46+import qualified Text.XHtml.Transitional as XHtml
46import Text.TeXMath
47import Text.TeXMath
47import Text.XML.Light.Output
48import Text.XML.Light.Output
48
49
@@ -60,8 +61,10 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stHighlighting =
60
61
61-- | Modified version of Text.XHtml's stringToHtml.
62-- | Modified version of Text.XHtml's stringToHtml.
62-- Use unicode characters wherever possible.
63-- Use unicode characters wherever possible.
63−stringToHtml :: String -> Html
64+stringToHtml :: WriterOptions -> String -> Html
65+stringToHtml opts = if writerAscii opts
66+ then XHtml.stringToHtml
64−stringToHtml = primHtml . escapeStringForXML
67+ else primHtml . escapeStringForXML
65
68
66-- | Hard linebreak.
69-- | Hard linebreak.
67nl :: WriterOptions -> Html
70nl :: WriterOptions -> Html
@@ -219,7 +222,7 @@ elementToListItem _ (Blk _) = return Nothing
219elementToListItem opts (Sec _ num id' headerText subsecs) = do
222elementToListItem opts (Sec _ num id' headerText subsecs) = do
220 let sectnum = if writerNumberSections opts
223 let sectnum = if writerNumberSections opts
221 then (thespan ! [theclass "toc-section-number"] << showSecNum num) +++
224 then (thespan ! [theclass "toc-section-number"] << showSecNum num) +++
222− stringToHtml " "
225+ stringToHtml opts" "
223 else noHtml
226 else noHtml
224 txt <- liftM (sectnum +++) $ inlineListToHtml opts headerText
227 txt <- liftM (sectnum +++) $ inlineListToHtml opts headerText
225 subHeads <- mapM (elementToListItem opts) subsecs >>= return . catMaybes
228 subHeads <- mapM (elementToListItem opts) subsecs >>= return . catMaybes
@@ -301,7 +304,7 @@ obfuscateLink opts txt s =
301 linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) +++
304 linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) +++
302 noscript (primHtml $ obfuscateString altText)
305 noscript (primHtml $ obfuscateString altText)
303 _ -> error $ "Unknown obfuscation method: " ++ show meth
306 _ -> error $ "Unknown obfuscation method: " ++ show meth
304− _ -> anchor ! [href s] $ stringToHtml txt -- malformed email
307+ _ -> anchor ! [href s] $ stringToHtml opts txt -- malformed email
305
308
306-- | Obfuscate character as entity.
309-- | Obfuscate character as entity.
307obfuscateChar :: Char -> String
310obfuscateChar :: Char -> String
@@ -353,7 +356,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
353 else unlines . lines
356 else unlines . lines
354 in return $ pre ! attrs $ thecode <<
357 in return $ pre ! attrs $ thecode <<
355 (replicate (length leadingBreaks) br +++
358 (replicate (length leadingBreaks) br +++
356− [stringToHtml $ addBird rawCode'])
359+ [stringToHtml opts $ addBird rawCode'])
357 Right h -> modify (\st -> st{ stHighlighting = True }) >>
360 Right h -> modify (\st -> st{ stHighlighting = True }) >>
358 return h
361 return h
359blockToHtml opts (BlockQuote blocks) =
362blockToHtml opts (BlockQuote blocks) =
@@ -379,7 +382,7 @@ blockToHtml opts (Header level lst) = do
379 secnum <- liftM stSecNum get
382 secnum <- liftM stSecNum get
380 let contents' = if writerNumberSections opts
383 let contents' = if writerNumberSections opts
381 then (thespan ! [theclass "header-section-number"] << showSecNum secnum) +++
384 then (thespan ! [theclass "header-section-number"] << showSecNum secnum) +++
382− stringToHtml " " +++ contents
385+ stringToHtml opts " " +++ contents
383 else contents
386 else contents
384 let contents'' = if writerTableOfContents opts
387 let contents'' = if writerTableOfContents opts
385 then anchor ! [href $ "#" ++ writerIdentifierPrefix opts ++ "TOC"] $ contents'
388 then anchor ! [href $ "#" ++ writerIdentifierPrefix opts ++ "TOC"] $ contents'
@@ -512,19 +515,19 @@ inlineListToHtml opts lst =
512inlineToHtml :: WriterOptions -> Inline -> State WriterState Html
515inlineToHtml :: WriterOptions -> Inline -> State WriterState Html
513inlineToHtml opts inline =
516inlineToHtml opts inline =
514 case inline of
517 case inline of
515− (Str str) -> return $ stringToHtml str
518+ (Str str) -> return $ stringToHtml opts str
516− (Space) -> return $ stringToHtml " "
519+ (Space) -> return $ stringToHtml opts " "
517 (LineBreak) -> return br
520 (LineBreak) -> return br
518− (EmDash) -> return $ stringToHtml "—"
521+ (EmDash) -> return $ stringToHtml opts "—"
519− (EnDash) -> return $ stringToHtml "–"
522+ (EnDash) -> return $ stringToHtml opts "–"
520− (Ellipses) -> return $ stringToHtml "…"
523+ (Ellipses) -> return $ stringToHtml opts "…"
521− (Apostrophe) -> return $ stringToHtml "’"
524+ (Apostrophe) -> return $ stringToHtml opts "’"
522 (Emph lst) -> inlineListToHtml opts lst >>= return . emphasize
525 (Emph lst) -> inlineListToHtml opts lst >>= return . emphasize
523 (Strong lst) -> inlineListToHtml opts lst >>= return . strong
526 (Strong lst) -> inlineListToHtml opts lst >>= return . strong
524 (Code attr str) -> case highlightHtml True attr str of
527 (Code attr str) -> case highlightHtml True attr str of
525 Left _ -> return
528 Left _ -> return
526 $ thecode ! (attrsToHtml opts attr)
529 $ thecode ! (attrsToHtml opts attr)
527− $ stringToHtml str
530+ $ stringToHtml opts str
528 Right h -> return h
531 Right h -> return h
529 (Strikeout lst) -> inlineListToHtml opts lst >>=
532 (Strikeout lst) -> inlineListToHtml opts lst >>=
530 return . (thespan ! [thestyle "text-decoration: line-through;"])
533 return . (thespan ! [thestyle "text-decoration: line-through;"])
@@ -534,10 +537,10 @@ inlineToHtml opts inline =
534 (Subscript lst) -> inlineListToHtml opts lst >>= return . sub
537 (Subscript lst) -> inlineListToHtml opts lst >>= return . sub
535 (Quoted quoteType lst) ->
538 (Quoted quoteType lst) ->
536 let (leftQuote, rightQuote) = case quoteType of
539 let (leftQuote, rightQuote) = case quoteType of
537− SingleQuote -> (stringToHtml "‘",
540+ SingleQuote -> (stringToHtml opts "‘",
538− stringToHtml "’")
541+ stringToHtml opts "’")
539− DoubleQuote -> (stringToHtml "“",
542+ DoubleQuote -> (stringToHtml opts "“",
540− stringToHtml "”")
543+ stringToHtml opts "”")
541 in do contents <- inlineListToHtml opts lst
544 in do contents <- inlineListToHtml opts lst
542 return $ leftQuote +++ contents +++ rightQuote
545 return $ leftQuote +++ contents +++ rightQuote
543 (Math t str) -> modify (\st -> st {stMath = True}) >>
546 (Math t str) -> modify (\st -> st {stMath = True}) >>
src/pandoc.hs+11−2
@@ -123,6 +123,7 @@ data Opt = Opt
123 , optBibliography :: [String]
123 , optBibliography :: [String]
124 , optCslFile :: FilePath
124 , optCslFile :: FilePath
125 , optListings :: Bool -- ^ Use listings package for code blocks
125 , optListings :: Bool -- ^ Use listings package for code blocks
126+ , optAscii :: Bool -- ^ Avoid using nonascii characters
126 }
127 }
127
128
128-- | Defaults for command-line options.
129-- | Defaults for command-line options.
@@ -166,6 +167,7 @@ defaultOpts = Opt
166 , optBibliography = []
167 , optBibliography = []
167 , optCslFile = ""
168 , optCslFile = ""
168 , optListings = False
169 , optListings = False
170+ , optAscii = False
169 }
171 }
170
172
171-- | A list of functions, each transforming the options data structure
173-- | A list of functions, each transforming the options data structure
@@ -347,6 +349,11 @@ options =
347 "NUMBER")
349 "NUMBER")
348 "" -- "Length of line in characters"
350 "" -- "Length of line in characters"
349
351
352+ , Option "" ["ascii"]
353+ (NoArg
354+ (\opt -> return opt { optAscii = True }))
355+ "" -- "Avoid using non-ascii characters in output"
356+
350 , Option "" ["email-obfuscation"]
357 , Option "" ["email-obfuscation"]
351 (ReqArg
358 (ReqArg
352 (\arg opt -> do
359 (\arg opt -> do
@@ -681,7 +688,8 @@ main = do
681 , optBibliography = reffiles
688 , optBibliography = reffiles
682 , optCslFile = cslfile
689 , optCslFile = cslfile
683 , optCiteMethod = citeMethod
690 , optCiteMethod = citeMethod
684− , optListings = listings
691+ , optListings = listings
692+ , optAscii = ascii
685 } = opts
693 } = opts
686
694
687 when dumpArgs $
695 when dumpArgs $
@@ -803,7 +811,8 @@ main = do
803 writerHtml5 = html5 &&
811 writerHtml5 = html5 &&
804 "html" `isPrefixOf` writerName',
812 "html" `isPrefixOf` writerName',
805 writerChapters = chapters,
813 writerChapters = chapters,
806− writerListings = listings }
814+ writerListings = listings,
815+ writerAscii = ascii }
807
816
808 when (isNonTextOutput writerName' && outputFile == "-") $
817 when (isNonTextOutput writerName' && outputFile == "-") $
809 do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++
818 do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName ++ " output to stdout.\n" ++