From f273965e16317af4e0756db4fa24a0d8fe296d7b Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 28 Jul 2007 06:38:49 +0000 Subject: Fixed problems with obfuscateLink introduced by last round of changes. Changed type so that text parameter is String, not HTML, which allows easier testing for autolinks. git-svn-id: https://pandoc.googlecode.com/svn/trunk@819 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Writers/HTML.hs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/Text/Pandoc/Writers/HTML.hs') diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index d61094975..3d46ba1c9 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -131,26 +131,23 @@ footnoteSection opts notes = hr +++ (olist << notes) -- | Obfuscate a "mailto:" link using Javascript. -obfuscateLink :: WriterOptions -> Html -> String -> Html +obfuscateLink :: WriterOptions -> String -> String -> Html obfuscateLink opts text src = - let emailRegex = mkRegex "mailto:*([^@]*)@(.*)" - text' = show $ text + let emailRegex = mkRegex "^mailto:([^@]*)@(.*)$" src' = map toLower src in case (matchRegex emailRegex src') of (Just [name, domain]) -> let domain' = substitute "." " dot " domain at' = obfuscateChar '@' (linkText, altText) = - if "mailto:" `isPrefixOf` src' && - text' == drop 7 src' - then ("e", name ++ " at " ++ domain') - else ("'" ++ text' ++ "'", - text' ++ " (" ++ name ++ " at " ++ - domain' ++ ")") in + if text == drop 7 src' -- autolink + then ("''+e+''", name ++ " at " ++ domain') + else ("'" ++ text ++ "'", text ++ " (" ++ name ++ " at " ++ + domain' ++ ")") in if writerStrictMarkdown opts then -- need to use primHtml or &'s are escaped to & in URL primHtml $ "" ++ (obfuscateString text') ++ "" + ++ "\">" ++ (obfuscateString text) ++ "" else (script ! [thetype "text/javascript"] $ primHtml ("\n\n")) +++ noscript (primHtml $ obfuscateString altText) - _ -> anchor ! [href src] $ text -- malformed email + _ -> anchor ! [href src] $ primHtml text -- malformed email -- | Obfuscate character as entity. obfuscateChar :: Char -> String @@ -369,11 +366,11 @@ inlineToHtml opts inline = else return () return $ stringToHtml str (HtmlInline str) -> return $ primHtml str - (Link [Code str] (src,tit)) | src == "mailto:" ++ str -> - return $ obfuscateLink opts (stringToHtml str) src + (Link [Code str] (src,tit)) | "mailto:" `isPrefixOf` src -> + do return $ obfuscateLink opts str src (Link txt (src,tit)) | "mailto:" `isPrefixOf` src -> do linkText <- inlineListToHtml opts txt - return $ obfuscateLink opts linkText src + return $ obfuscateLink opts (show linkText) src (Link txt (src,tit)) -> do linkText <- inlineListToHtml opts txt return $ anchor ! ([href src] ++ -- cgit v1.2.3