summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-01-06 20:51:51 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-06 20:51:51 -0800
commit8c48bd8feb97e6c291df2e0ca09f62fb34711d33 (patch)
tree80821e64776ea6ed605f6134e53a2a93feda3e6c /src/Text/Pandoc/Writers
parent300f8528daaa13b6ee6931bbe8bb70eac914b333 (diff)
Don't put the text of an autolink in Code font.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/AsciiDoc.hs4
-rw-r--r--src/Text/Pandoc/Writers/ConTeXt.hs8
-rw-r--r--src/Text/Pandoc/Writers/Docbook.hs2
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs4
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs2
-rw-r--r--src/Text/Pandoc/Writers/Man.hs5
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs4
-rw-r--r--src/Text/Pandoc/Writers/MediaWiki.hs2
-rw-r--r--src/Text/Pandoc/Writers/Org.hs2
-rw-r--r--src/Text/Pandoc/Writers/RST.hs7
-rw-r--r--src/Text/Pandoc/Writers/Texinfo.hs2
11 files changed, 26 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs
index e314cf70e..b03bc77a8 100644
--- a/src/Text/Pandoc/Writers/AsciiDoc.hs
+++ b/src/Text/Pandoc/Writers/AsciiDoc.hs
@@ -343,8 +343,8 @@ inlineToAsciiDoc opts (Link txt (src, _tit)) = do
else empty
let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
let useAuto = case txt of
- [Code _ s] | s == srcSuffix -> True
- _ -> False
+ [Str s] | escapeURI s == srcSuffix -> True
+ _ -> False
return $ if useAuto
then text srcSuffix
else prefix <> text src <> "[" <> linktext <> "]"
diff --git a/src/Text/Pandoc/Writers/ConTeXt.hs b/src/Text/Pandoc/Writers/ConTeXt.hs
index c67daf13d..fcf76964c 100644
--- a/src/Text/Pandoc/Writers/ConTeXt.hs
+++ b/src/Text/Pandoc/Writers/ConTeXt.hs
@@ -34,7 +34,7 @@ import Text.Pandoc.Shared
import Text.Pandoc.Options
import Text.Pandoc.Generic (queryWith)
import Text.Printf ( printf )
-import Data.List ( intercalate )
+import Data.List ( intercalate, isPrefixOf )
import Control.Monad.State
import Text.Pandoc.Pretty
import Text.Pandoc.Templates ( renderTemplate )
@@ -280,7 +280,11 @@ inlineToConTeXt (RawInline _ _) = return empty
inlineToConTeXt (LineBreak) = return $ text "\\crlf" <> cr
inlineToConTeXt Space = return space
-- autolink
-inlineToConTeXt (Link [Code _ str] (src, tit)) = inlineToConTeXt (Link
+inlineToConTeXt (Link [Str str] (src, tit))
+ | if "mailto:" `isPrefixOf` src
+ then src == escapeURI ("mailto:" ++ str)
+ else src == escapeURI str =
+ inlineToConTeXt (Link
[RawInline "context" "\\hyphenatedurl{", Str str, RawInline "context" "}"]
(src, tit))
-- Handle HTML-like internal document references to sections
diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs
index 70d6a08ea..fe768efc5 100644
--- a/src/Text/Pandoc/Writers/Docbook.hs
+++ b/src/Text/Pandoc/Writers/Docbook.hs
@@ -289,7 +289,7 @@ inlineToDocbook opts (Link txt (src, _)) =
emailLink = inTagsSimple "email" $ text $
escapeStringForXML $ src'
in case txt of
- [Code _ s] | s == src' -> emailLink
+ [Str s] | escapeURI s == src' -> emailLink
_ -> inlinesToDocbook opts txt <+>
char '(' <> emailLink <> char ')'
else (if isPrefixOf "#" src
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 7fe77a69c..68a8a1e09 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -675,7 +675,9 @@ inlineToHtml opts inline =
_ -> return mempty
(RawInline "html" str) -> return $ preEscapedString str
(RawInline _ _) -> return mempty
- (Link [Code _ str] (s,_)) | "mailto:" `isPrefixOf` s ->
+ (Link [Str str] (s,_)) | "mailto:" `isPrefixOf` s &&
+ s == escapeURI ("mailto" ++ str) ->
+ -- autolink
return $ obfuscateLink opts str s
(Link txt (s,_)) | "mailto:" `isPrefixOf` s -> do
linkText <- inlineListToHtml opts txt
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index ec8ffe1bb..8a7e95ea5 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -593,7 +593,7 @@ inlineToLaTeX (Link txt ('#':ident, _)) = do
return $ text "\\hyperref" <> brackets (text ident') <> braces contents
inlineToLaTeX (Link txt (src, _)) =
case txt of
- [Code _ x] | x == src -> -- autolink
+ [Str x] | x == src -> -- autolink
do modify $ \s -> s{ stUrl = True }
src' <- stringToLaTeX True x
return $ text $ "\\url{" ++ src' ++ "}"
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
index 3a8aa1437..10ca961f8 100644
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -332,8 +332,9 @@ inlineToMan opts (Link txt (src, _)) = do
linktext <- inlineListToMan opts txt
let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
return $ case txt of
- [Code _ s]
- | s == srcSuffix -> char '<' <> text srcSuffix <> char '>'
+ [Str s]
+ | escapeURI s == srcSuffix ->
+ char '<' <> text srcSuffix <> char '>'
_ -> linktext <> text " (" <> text src <> char ')'
inlineToMan opts (Image alternate (source, tit)) = do
let txt = if (null alternate) || (alternate == [Str ""]) ||
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 234a9cc76..384851c91 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -630,8 +630,8 @@ inlineToMarkdown opts (Link txt (src, tit)) = do
else text $ " \"" ++ tit ++ "\""
let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
let useAuto = case (tit,txt) of
- ("", [Code _ s]) | s == srcSuffix -> True
- _ -> False
+ ("", [Str s]) | escapeURI s == srcSuffix -> True
+ _ -> False
let useRefLinks = writerReferenceLinks opts && not useAuto
ref <- if useRefLinks then getReference txt (src, tit) else return []
reftext <- inlineListToMarkdown opts ref
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs
index 81e7a6d33..01fc49a10 100644
--- a/src/Text/Pandoc/Writers/MediaWiki.hs
+++ b/src/Text/Pandoc/Writers/MediaWiki.hs
@@ -378,7 +378,7 @@ inlineToMediaWiki _ Space = return " "
inlineToMediaWiki opts (Link txt (src, _)) = do
label <- inlineListToMediaWiki opts txt
case txt of
- [Code _ s] | s == src -> return src
+ [Str s] | escapeURI s == src -> return src
_ -> if isURI src
then return $ "[" ++ src ++ " " ++ label ++ "]"
else return $ "[[" ++ src' ++ "|" ++ label ++ "]]"
diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs
index b885a7a40..86b570c30 100644
--- a/src/Text/Pandoc/Writers/Org.hs
+++ b/src/Text/Pandoc/Writers/Org.hs
@@ -271,7 +271,7 @@ inlineToOrg (LineBreak) = return cr -- there's no line break in Org
inlineToOrg Space = return space
inlineToOrg (Link txt (src, _)) = do
case txt of
- [Code _ x] | x == src -> -- autolink
+ [Str x] | escapeURI x == src -> -- autolink
do modify $ \s -> s{ stLinks = True }
return $ "[[" <> text x <> "]]"
_ -> do contents <- inlineListToOrg txt
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index a415c2de4..40939c6b7 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -348,8 +348,11 @@ inlineToRST (RawInline "rst" x) = return $ text x
inlineToRST (RawInline _ _) = return empty
inlineToRST (LineBreak) = return cr -- there's no line break in RST
inlineToRST Space = return space
-inlineToRST (Link [Code _ str] (src, _)) | src == str ||
- src == "mailto:" ++ str = do
+-- autolink
+inlineToRST (Link [Str str] (src, _))
+ | if "mailto:" `isPrefixOf` src
+ then src == escapeURI ("mailto:" ++ str)
+ else src == escapeURI str = do
let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
return $ text srcSuffix
inlineToRST (Link [Image alt (imgsrc,imgtit)] (src, _tit)) = do
diff --git a/src/Text/Pandoc/Writers/Texinfo.hs b/src/Text/Pandoc/Writers/Texinfo.hs
index 5ced0d9ec..4c29b410d 100644
--- a/src/Text/Pandoc/Writers/Texinfo.hs
+++ b/src/Text/Pandoc/Writers/Texinfo.hs
@@ -425,7 +425,7 @@ inlineToTexinfo (Link txt (src@('#':_), _)) = do
braces (text (stringToTexinfo src) <> text "," <> contents)
inlineToTexinfo (Link txt (src, _)) = do
case txt of
- [Code _ x] | x == src -> -- autolink
+ [Str x] | escapeURI x == src -> -- autolink
do return $ text $ "@url{" ++ x ++ "}"
_ -> do contents <- escapeCommas $ inlineListToTexinfo txt
let src1 = stringToTexinfo src