git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: use 'uri' or 'email' class for autolinks.
81157c7John MacFarlane
src/Text/Pandoc/Writers/HTML.hs+8−5
@@ -40,7 +40,7 @@ import Text.Pandoc.Slides
40import Text.Pandoc.Highlighting ( highlight, styleToCss,
40import Text.Pandoc.Highlighting ( highlight, styleToCss,
41 formatHtmlInline, formatHtmlBlock )
41 formatHtmlInline, formatHtmlBlock )
42import Text.Pandoc.XML (fromEntities, escapeStringForXML)
42import Text.Pandoc.XML (fromEntities, escapeStringForXML)
43−import Network.URI ( parseURIReference, URI(..) )
43+import Network.URI ( parseURIReference, URI(..), unEscapeString )
44import Network.HTTP ( urlEncode )
44import Network.HTTP ( urlEncode )
45import Numeric ( showHex )
45import Numeric ( showHex )
46import Data.Char ( ord, toLower )
46import Data.Char ( ord, toLower )
@@ -361,13 +361,13 @@ obfuscateLink opts txt s =
361 ReferenceObfuscation ->
361 ReferenceObfuscation ->
362 -- need to use preEscapedString or &'s are escaped to & in URL
362 -- need to use preEscapedString or &'s are escaped to & in URL
363 preEscapedString $ "<a href=\"" ++ (obfuscateString s')
363 preEscapedString $ "<a href=\"" ++ (obfuscateString s')
364− ++ "\">" ++ (obfuscateString txt) ++ "</a>"
364+ ++ "\" class=\"email\">" ++ (obfuscateString txt) ++ "</a>"
365 JavascriptObfuscation ->
365 JavascriptObfuscation ->
366 (H.script ! A.type_ "text/javascript" $
366 (H.script ! A.type_ "text/javascript" $
367 preEscapedString ("\n<!--\nh='" ++
367 preEscapedString ("\n<!--\nh='" ++
368 obfuscateString domain ++ "';a='" ++ at' ++ "';n='" ++
368 obfuscateString domain ++ "';a='" ++ at' ++ "';n='" ++
369 obfuscateString name' ++ "';e=n+a+h;\n" ++
369 obfuscateString name' ++ "';e=n+a+h;\n" ++
370− "document.write('<a h'+'ref'+'=\"ma'+'ilto'+':'+e+'\">'+" ++
370+ "document.write('<a h'+'ref'+'=\"ma'+'ilto'+':'+e+'\" clas'+'s=\"em' + 'ail\">'+" ++
371 linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) >>
371 linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) >>
372 H.noscript (preEscapedString $ obfuscateString altText)
372 H.noscript (preEscapedString $ obfuscateString altText)
373 _ -> error $ "Unknown obfuscation method: " ++ show meth
373 _ -> error $ "Unknown obfuscation method: " ++ show meth
@@ -739,9 +739,12 @@ inlineToHtml opts inline =
739 RevealJsSlides -> '#':'/':xs
739 RevealJsSlides -> '#':'/':xs
740 _ -> s
740 _ -> s
741 let link = H.a ! A.href (toValue s') $ linkText
741 let link = H.a ! A.href (toValue s') $ linkText
742+ let link' = if txt == [Str (unEscapeString s)]
743+ then link ! A.class_ "uri"
744+ else link
742 return $ if null tit
745 return $ if null tit
743− then link
746+ then link'
744− else link ! A.title (toValue tit)
747+ else link' ! A.title (toValue tit)
745 (Image txt (s,tit)) | treatAsImage s -> do
748 (Image txt (s,tit)) | treatAsImage s -> do
746 let alternate' = stringify txt
749 let alternate' = stringify txt
747 let attributes = [A.src $ toValue s] ++
750 let attributes = [A.src $ toValue s] ++
tests/writer.html+5−5
@@ -480,7 +480,7 @@ Blah
480<p><script type="text/javascript">
480<p><script type="text/javascript">
481<!--
481<!--
482h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
482h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
483−document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>');
483+document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+'Email link'+'<\/'+'a'+'>');
484// -->
484// -->
485</script><noscript>&#x45;&#x6d;&#x61;&#x69;&#108;&#32;&#108;&#x69;&#110;&#x6b;&#32;&#40;&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;&#x29;</noscript></p>
485</script><noscript>&#x45;&#x6d;&#x61;&#x69;&#108;&#32;&#108;&#x69;&#110;&#x6b;&#32;&#40;&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;&#x29;</noscript></p>
486<p><a href="">Empty</a>.</p>
486<p><a href="">Empty</a>.</p>
@@ -503,20 +503,20 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>')
503<p>Here’s an <a href="/script?foo=1&amp;bar=2">inline link</a>.</p>
503<p>Here’s an <a href="/script?foo=1&amp;bar=2">inline link</a>.</p>
504<p>Here’s an <a href="/script?foo=1&amp;bar=2">inline link in pointy braces</a>.</p>
504<p>Here’s an <a href="/script?foo=1&amp;bar=2">inline link in pointy braces</a>.</p>
505<h2 id="autolinks">Autolinks</h2>
505<h2 id="autolinks">Autolinks</h2>
506−<p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
506+<p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2" class="uri">http://example.com/?foo=1&amp;bar=2</a></p>
507<ul>
507<ul>
508<li>In a list?</li>
508<li>In a list?</li>
509−<li><a href="http://example.com/">http://example.com/</a></li>
509+<li><a href="http://example.com/" class="uri">http://example.com/</a></li>
510<li>It should.</li>
510<li>It should.</li>
511</ul>
511</ul>
512<p>An e-mail address: <script type="text/javascript">
512<p>An e-mail address: <script type="text/javascript">
513<!--
513<!--
514h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
514h='&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#46;&#110;&#x65;&#116;';a='&#64;';n='&#110;&#x6f;&#98;&#x6f;&#100;&#x79;';e=n+a+h;
515−document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+e+'<\/'+'a'+'>');
515+document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>');
516// -->
516// -->
517</script><noscript>&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript></p>
517</script><noscript>&#110;&#x6f;&#98;&#x6f;&#100;&#x79;&#32;&#x61;&#116;&#32;&#110;&#x6f;&#x77;&#104;&#x65;&#114;&#x65;&#32;&#100;&#x6f;&#116;&#32;&#110;&#x65;&#116;</noscript></p>
518<blockquote>
518<blockquote>
519−<p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
519+<p>Blockquoted: <a href="http://example.com/" class="uri">http://example.com/</a></p>
520</blockquote>
520</blockquote>
521<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
521<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
522<pre><code>or here: &lt;http://example.com/&gt;</code></pre>
522<pre><code>or here: &lt;http://example.com/&gt;</code></pre>