From 8c48bd8feb97e6c291df2e0ca09f62fb34711d33 Mon Sep 17 00:00:00 2001 From: John MacFarlane <fiddlosopher@gmail.com> Date: Sun, 6 Jan 2013 20:51:51 -0800 Subject: Don't put the text of an autolink in Code font. --- src/Text/Pandoc/Readers/DocBook.hs | 6 +++--- src/Text/Pandoc/Readers/LaTeX.hs | 2 +- src/Text/Pandoc/Readers/Markdown.hs | 4 ++-- src/Text/Pandoc/Writers/AsciiDoc.hs | 4 ++-- src/Text/Pandoc/Writers/ConTeXt.hs | 8 ++++++-- src/Text/Pandoc/Writers/Docbook.hs | 2 +- src/Text/Pandoc/Writers/HTML.hs | 4 +++- src/Text/Pandoc/Writers/LaTeX.hs | 2 +- src/Text/Pandoc/Writers/Man.hs | 5 +++-- src/Text/Pandoc/Writers/Markdown.hs | 4 ++-- src/Text/Pandoc/Writers/MediaWiki.hs | 2 +- src/Text/Pandoc/Writers/Org.hs | 2 +- src/Text/Pandoc/Writers/RST.hs | 7 +++++-- src/Text/Pandoc/Writers/Texinfo.hs | 2 +- 14 files changed, 32 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index 8e4c8e9d4..0058e889c 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -877,15 +877,15 @@ parseInline (Elem e) = "varargs" -> return $ code "(...)" "xref" -> return $ str "?" -- so at least you know something is there "email" -> return $ link ("mailto:" ++ strContent e) "" - $ code $ strContent e - "uri" -> return $ link (strContent e) "" $ code $ strContent e + $ str $ strContent e + "uri" -> return $ link (strContent e) "" $ str $ strContent e "ulink" -> link (attrValue "url" e) "" <$> innerInlines "link" -> do ils <- innerInlines let href = case findAttr (QName "href" (Just "http://www.w3.org/1999/xlink") Nothing) e of Just h -> h _ -> ('#' : attrValue "linkend" e) - let ils' = if ils == mempty then code href else ils + let ils' = if ils == mempty then str href else ils return $ link href "" ils' "foreignphrase" -> emph <$> innerInlines "emphasis" -> case attrValue "role" e of diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 8848be028..5362b1b53 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -426,7 +426,7 @@ inlineCommands = M.fromList $ , ("lstinline", doverb) , ("texttt", (code . stringify . toList) <$> tok) , ("url", (unescapeURL <$> braced) >>= \url -> - pure (link url "" (codeWith ("",["url"],[]) url))) + pure (link url "" (str url))) , ("href", (unescapeURL <$> braced <* optional sp) >>= \url -> tok >>= \lab -> pure (link url "" lab)) diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 985d1d0f2..8c4855076 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1519,14 +1519,14 @@ bareURL :: MarkdownParser (F Inlines) bareURL = try $ do guardEnabled Ext_autolink_urls (orig, src) <- uri <|> emailAddress - return $ return $ B.link src "" (B.codeWith ("",["url"],[]) orig) + return $ return $ B.link src "" (B.str orig) autoLink :: MarkdownParser (F Inlines) autoLink = try $ do char '<' (orig, src) <- uri <|> emailAddress char '>' - return $ return $ B.link src "" (B.codeWith ("",["url"],[]) orig) + return $ return $ B.link src "" (B.str orig) image :: MarkdownParser (F Inlines) image = try $ do 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 -- cgit v1.2.3