From 2806aee9b210c338037176bff467b76a394b120f Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 24 Jan 2009 19:58:48 +0000 Subject: Added --email-obfuscation option. + Added writer option for email obfuscation. + Implemented email obfuscation options in HTML writer. + Added option to option parser. + Documented in README and pandoc man page. + Resolves Issue #97. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1523 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Shared.hs | 73 +++++++++++++++++++++++++-------------------- Text/Pandoc/Writers/HTML.hs | 16 ++++++---- 2 files changed, 52 insertions(+), 37 deletions(-) (limited to 'Text/Pandoc') diff --git a/Text/Pandoc/Shared.hs b/Text/Pandoc/Shared.hs index c607a4e5b..6854e5ae6 100644 --- a/Text/Pandoc/Shared.hs +++ b/Text/Pandoc/Shared.hs @@ -99,6 +99,7 @@ module Text.Pandoc.Shared ( isHeaderBlock, -- * Writer options HTMLMathMethod (..), + ObfuscationMethod (..), WriterOptions (..), defaultWriterOptions, -- * File handling @@ -889,45 +890,53 @@ data HTMLMathMethod = PlainMath | MimeTeX String -- url of mimetex.cgi deriving (Show, Read, Eq) +-- | Methods for obfuscating email addresses in HTML. +data ObfuscationMethod = NoObfuscation + | ReferenceObfuscation + | JavascriptObfuscation + deriving (Show, Read, Eq) + -- | Options for writers data WriterOptions = WriterOptions - { writerStandalone :: Bool -- ^ Include header and footer - , writerHeader :: String -- ^ Header for the document - , writerTitlePrefix :: String -- ^ Prefix for HTML titles - , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs - , writerTableOfContents :: Bool -- ^ Include table of contents - , writerS5 :: Bool -- ^ We're writing S5 - , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML - , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc) - , writerIncremental :: Bool -- ^ Incremental S5 lists - , writerNumberSections :: Bool -- ^ Number sections in LaTeX - , writerIncludeBefore :: String -- ^ String to include before the body - , writerIncludeAfter :: String -- ^ String to include after the body - , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax - , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst - , writerWrapText :: Bool -- ^ Wrap text to line length - , writerLiterateHaskell :: Bool -- ^ Write as literate haskell + { writerStandalone :: Bool -- ^ Include header and footer + , writerHeader :: String -- ^ Header for the document + , writerTitlePrefix :: String -- ^ Prefix for HTML titles + , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs + , writerTableOfContents :: Bool -- ^ Include table of contents + , writerS5 :: Bool -- ^ We're writing S5 + , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML + , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc) + , writerIncremental :: Bool -- ^ Incremental S5 lists + , writerNumberSections :: Bool -- ^ Number sections in LaTeX + , writerIncludeBefore :: String -- ^ String to include before the body + , writerIncludeAfter :: String -- ^ String to include after the body + , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax + , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst + , writerWrapText :: Bool -- ^ Wrap text to line length + , writerLiterateHaskell :: Bool -- ^ Write as literate haskell + , writerEmailObfuscation :: ObfuscationMethod -- ^ How to obfuscate emails } deriving Show -- | Default writer options. defaultWriterOptions :: WriterOptions defaultWriterOptions = - WriterOptions { writerStandalone = False - , writerHeader = "" - , writerTitlePrefix = "" - , writerTabStop = 4 - , writerTableOfContents = False - , writerS5 = False - , writerHTMLMathMethod = PlainMath - , writerIgnoreNotes = False - , writerIncremental = False - , writerNumberSections = False - , writerIncludeBefore = "" - , writerIncludeAfter = "" - , writerStrictMarkdown = False - , writerReferenceLinks = False - , writerWrapText = True - , writerLiterateHaskell = False + WriterOptions { writerStandalone = False + , writerHeader = "" + , writerTitlePrefix = "" + , writerTabStop = 4 + , writerTableOfContents = False + , writerS5 = False + , writerHTMLMathMethod = PlainMath + , writerIgnoreNotes = False + , writerIncremental = False + , writerNumberSections = False + , writerIncludeBefore = "" + , writerIncludeAfter = "" + , writerStrictMarkdown = False + , writerReferenceLinks = False + , writerWrapText = True + , writerLiterateHaskell = False + , writerEmailObfuscation = JavascriptObfuscation } -- diff --git a/Text/Pandoc/Writers/HTML.hs b/Text/Pandoc/Writers/HTML.hs index 087fff623..fb7320e92 100644 --- a/Text/Pandoc/Writers/HTML.hs +++ b/Text/Pandoc/Writers/HTML.hs @@ -193,10 +193,13 @@ parseMailto ('m':'a':'i':'l':'t':'o':':':addr) = in Just (name', domain) parseMailto _ = Nothing --- | Obfuscate a "mailto:" link using Javascript. +-- | Obfuscate a "mailto:" link. obfuscateLink :: WriterOptions -> String -> String -> Html +obfuscateLink opts txt s | writerEmailObfuscation opts == NoObfuscation = + anchor ! [href s] << txt obfuscateLink opts txt s = - let s' = map toLower s + let meth = writerEmailObfuscation opts + s' = map toLower s in case parseMailto s' of (Just (name', domain)) -> let domain' = substitute "." " dot " domain @@ -206,17 +209,20 @@ obfuscateLink opts txt s = then ("''+e+''", name' ++ " at " ++ domain') else ("'" ++ txt ++ "'", txt ++ " (" ++ name' ++ " at " ++ domain' ++ ")") - in if writerStrictMarkdown opts - then -- need to use primHtml or &'s are escaped to & in URL + in case meth of + ReferenceObfuscation -> + -- need to use primHtml or &'s are escaped to & in URL primHtml $ "" ++ (obfuscateString txt) ++ "" - else (script ! [thetype "text/javascript"] $ + JavascriptObfuscation -> + (script ! [thetype "text/javascript"] $ primHtml ("\n\n")) +++ noscript (primHtml $ obfuscateString altText) + _ -> error $ "Unknown obfuscation method: " ++ show meth _ -> anchor ! [href s] $ primHtml txt -- malformed email -- | Obfuscate character as entity. -- cgit v1.2.3