git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: use 'uri' or 'email' class for autolinks.

This allows them to be styled specially. Closes #1501.

commit81157c7cc6ab72fc70bfba18f90c3f12142b7e4e authorJohn MacFarlane <jgm@berkeley.edu> dateTue 12 Aug 2014, 15:49 (12 years ago) parentda507dc
2 files changed+13−10
src/Text/Pandoc/Writers/HTML.hs+8−5 tests/writer.html+5−5
src/Text/Pandoc/Writers/HTML.hs+8−5
@@ -40,7 +40,7 @@ import Text.Pandoc.Slides
4040import Text.Pandoc.Highlighting ( highlight, styleToCss,
4141 formatHtmlInline, formatHtmlBlock )
4242import Text.Pandoc.XML (fromEntities, escapeStringForXML)
43−import Network.URI ( parseURIReference, URI(..) )
43+import Network.URI ( parseURIReference, URI(..), unEscapeString )
4444import Network.HTTP ( urlEncode )
4545import Numeric ( showHex )
4646import Data.Char ( ord, toLower )
@@ -361,13 +361,13 @@ obfuscateLink opts txt s =
361361 ReferenceObfuscation ->
362362 -- need to use preEscapedString or &'s are escaped to &amp; in URL
363363 preEscapedString $ "<a href=\"" ++ (obfuscateString s')
364− ++ "\">" ++ (obfuscateString txt) ++ "</a>"
364+ ++ "\" class=\"email\">" ++ (obfuscateString txt) ++ "</a>"
365365 JavascriptObfuscation ->
366366 (H.script ! A.type_ "text/javascript" $
367367 preEscapedString ("\n<!--\nh='" ++
368368 obfuscateString domain ++ "';a='" ++ at' ++ "';n='" ++
369369 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\">'+" ++
371371 linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) >>
372372 H.noscript (preEscapedString $ obfuscateString altText)
373373 _ -> error $ "Unknown obfuscation method: " ++ show meth
@@ -739,9 +739,12 @@ inlineToHtml opts inline =
739739 RevealJsSlides -> '#':'/':xs
740740 _ -> s
741741 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
742745 return $ if null tit
743− then link
744− else link ! A.title (toValue tit)
746+ then link'
747+ else link' ! A.title (toValue tit)
745748 (Image txt (s,tit)) | treatAsImage s -> do
746749 let alternate' = stringify txt
747750 let attributes = [A.src $ toValue s] ++
tests/writer.html+5−5
@@ -480,7 +480,7 @@ Blah
480480<p><script type="text/javascript">
481481<!--
482482h='&#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'+'>');
484484// -->
485485</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>
486486<p><a href="">Empty</a>.</p>
@@ -503,20 +503,20 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>')
503503<p>Here’s an <a href="/script?foo=1&amp;bar=2">inline link</a>.</p>
504504<p>Here’s an <a href="/script?foo=1&amp;bar=2">inline link in pointy braces</a>.</p>
505505<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>
507507<ul>
508508<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>
510510<li>It should.</li>
511511</ul>
512512<p>An e-mail address: <script type="text/javascript">
513513<!--
514514h='&#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'+'>');
516516// -->
517517</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>
518518<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>
520520</blockquote>
521521<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
522522<pre><code>or here: &lt;http://example.com/&gt;</code></pre>