HTML writer: use 'uri' or 'email' class for autolinks.
This allows them to be styled specially. Closes #1501.
This commit is contained in:
parent
da507dcb84
commit
81157c7cc6
2 changed files with 13 additions and 10 deletions
|
@ -40,7 +40,7 @@ import Text.Pandoc.Slides
|
||||||
import Text.Pandoc.Highlighting ( highlight, styleToCss,
|
import Text.Pandoc.Highlighting ( highlight, styleToCss,
|
||||||
formatHtmlInline, formatHtmlBlock )
|
formatHtmlInline, formatHtmlBlock )
|
||||||
import Text.Pandoc.XML (fromEntities, escapeStringForXML)
|
import Text.Pandoc.XML (fromEntities, escapeStringForXML)
|
||||||
import Network.URI ( parseURIReference, URI(..) )
|
import Network.URI ( parseURIReference, URI(..), unEscapeString )
|
||||||
import Network.HTTP ( urlEncode )
|
import Network.HTTP ( urlEncode )
|
||||||
import Numeric ( showHex )
|
import Numeric ( showHex )
|
||||||
import Data.Char ( ord, toLower )
|
import Data.Char ( ord, toLower )
|
||||||
|
@ -361,13 +361,13 @@ obfuscateLink opts txt s =
|
||||||
ReferenceObfuscation ->
|
ReferenceObfuscation ->
|
||||||
-- need to use preEscapedString or &'s are escaped to & in URL
|
-- need to use preEscapedString or &'s are escaped to & in URL
|
||||||
preEscapedString $ "<a href=\"" ++ (obfuscateString s')
|
preEscapedString $ "<a href=\"" ++ (obfuscateString s')
|
||||||
++ "\">" ++ (obfuscateString txt) ++ "</a>"
|
++ "\" class=\"email\">" ++ (obfuscateString txt) ++ "</a>"
|
||||||
JavascriptObfuscation ->
|
JavascriptObfuscation ->
|
||||||
(H.script ! A.type_ "text/javascript" $
|
(H.script ! A.type_ "text/javascript" $
|
||||||
preEscapedString ("\n<!--\nh='" ++
|
preEscapedString ("\n<!--\nh='" ++
|
||||||
obfuscateString domain ++ "';a='" ++ at' ++ "';n='" ++
|
obfuscateString domain ++ "';a='" ++ at' ++ "';n='" ++
|
||||||
obfuscateString name' ++ "';e=n+a+h;\n" ++
|
obfuscateString name' ++ "';e=n+a+h;\n" ++
|
||||||
"document.write('<a h'+'ref'+'=\"ma'+'ilto'+':'+e+'\">'+" ++
|
"document.write('<a h'+'ref'+'=\"ma'+'ilto'+':'+e+'\" clas'+'s=\"em' + 'ail\">'+" ++
|
||||||
linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) >>
|
linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) >>
|
||||||
H.noscript (preEscapedString $ obfuscateString altText)
|
H.noscript (preEscapedString $ obfuscateString altText)
|
||||||
_ -> error $ "Unknown obfuscation method: " ++ show meth
|
_ -> error $ "Unknown obfuscation method: " ++ show meth
|
||||||
|
@ -739,9 +739,12 @@ inlineToHtml opts inline =
|
||||||
RevealJsSlides -> '#':'/':xs
|
RevealJsSlides -> '#':'/':xs
|
||||||
_ -> s
|
_ -> s
|
||||||
let link = H.a ! A.href (toValue s') $ linkText
|
let link = H.a ! A.href (toValue s') $ linkText
|
||||||
|
let link' = if txt == [Str (unEscapeString s)]
|
||||||
|
then link ! A.class_ "uri"
|
||||||
|
else link
|
||||||
return $ if null tit
|
return $ if null tit
|
||||||
then link
|
then link'
|
||||||
else link ! A.title (toValue tit)
|
else link' ! A.title (toValue tit)
|
||||||
(Image txt (s,tit)) | treatAsImage s -> do
|
(Image txt (s,tit)) | treatAsImage s -> do
|
||||||
let alternate' = stringify txt
|
let alternate' = stringify txt
|
||||||
let attributes = [A.src $ toValue s] ++
|
let attributes = [A.src $ toValue s] ++
|
||||||
|
|
|
@ -480,7 +480,7 @@ Blah
|
||||||
<p><script type="text/javascript">
|
<p><script type="text/javascript">
|
||||||
<!--
|
<!--
|
||||||
h='nowhere.net';a='@';n='nobody';e=n+a+h;
|
h='nowhere.net';a='@';n='nobody';e=n+a+h;
|
||||||
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>');
|
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+'Email link'+'<\/'+'a'+'>');
|
||||||
// -->
|
// -->
|
||||||
</script><noscript>Email link (nobody at nowhere dot net)</noscript></p>
|
</script><noscript>Email link (nobody at nowhere dot net)</noscript></p>
|
||||||
<p><a href="">Empty</a>.</p>
|
<p><a href="">Empty</a>.</p>
|
||||||
|
@ -503,20 +503,20 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>')
|
||||||
<p>Here’s an <a href="/script?foo=1&bar=2">inline link</a>.</p>
|
<p>Here’s an <a href="/script?foo=1&bar=2">inline link</a>.</p>
|
||||||
<p>Here’s an <a href="/script?foo=1&bar=2">inline link in pointy braces</a>.</p>
|
<p>Here’s an <a href="/script?foo=1&bar=2">inline link in pointy braces</a>.</p>
|
||||||
<h2 id="autolinks">Autolinks</h2>
|
<h2 id="autolinks">Autolinks</h2>
|
||||||
<p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
|
<p>With an ampersand: <a href="http://example.com/?foo=1&bar=2" class="uri">http://example.com/?foo=1&bar=2</a></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>In a list?</li>
|
<li>In a list?</li>
|
||||||
<li><a href="http://example.com/">http://example.com/</a></li>
|
<li><a href="http://example.com/" class="uri">http://example.com/</a></li>
|
||||||
<li>It should.</li>
|
<li>It should.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>An e-mail address: <script type="text/javascript">
|
<p>An e-mail address: <script type="text/javascript">
|
||||||
<!--
|
<!--
|
||||||
h='nowhere.net';a='@';n='nobody';e=n+a+h;
|
h='nowhere.net';a='@';n='nobody';e=n+a+h;
|
||||||
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+e+'<\/'+'a'+'>');
|
document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'" clas'+'s="em' + 'ail">'+e+'<\/'+'a'+'>');
|
||||||
// -->
|
// -->
|
||||||
</script><noscript>nobody at nowhere dot net</noscript></p>
|
</script><noscript>nobody at nowhere dot net</noscript></p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
|
<p>Blockquoted: <a href="http://example.com/" class="uri">http://example.com/</a></p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<p>Auto-links should not occur here: <code><http://example.com/></code></p>
|
<p>Auto-links should not occur here: <code><http://example.com/></code></p>
|
||||||
<pre><code>or here: <http://example.com/></code></pre>
|
<pre><code>or here: <http://example.com/></code></pre>
|
||||||
|
|
Loading…
Reference in a new issue