diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-28 06:38:49 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-07-28 06:38:49 +0000 |
commit | f273965e16317af4e0756db4fa24a0d8fe296d7b (patch) | |
tree | cda828e15e6b34d3d5e89da4a6bef878364e70dd /src | |
parent | d3404581d4acba1d41831bad3db3b8a1271c2ee2 (diff) | |
download | pandoc-f273965e16317af4e0756db4fa24a0d8fe296d7b.tar.gz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 25 |
1 files changed, 11 insertions, 14 deletions
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 ("'<code>'+e+'</code>'", 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 $ "<a href=\"" ++ (obfuscateString src') - ++ "\">" ++ (obfuscateString text') ++ "</a>" + ++ "\">" ++ (obfuscateString text) ++ "</a>" else (script ! [thetype "text/javascript"] $ primHtml ("\n<!--\nh='" ++ obfuscateString domain ++ "';a='" ++ at' ++ "';n='" ++ @@ -158,7 +155,7 @@ obfuscateLink opts text src = "document.write('<a h'+'ref'+'=\"ma'+'ilto'+':'+e+'\">'+" ++ linkText ++ "+'<\\/'+'a'+'>');\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] ++ |