@@ -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
@@ -60,8 +61,10 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stHighlighting =
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
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
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 }) >>
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}) >>