aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-01-24 19:06:30 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-01-24 19:06:30 +0000
commitca6cb23f23724d01b5f7d6ee7a3c9527ca8807e6 (patch)
treeb010e6c7117c1d876d2999499c1f16bb13a255b9 /src/Text
parent0646eef97691794eeac5549db18ac82cb6b84576 (diff)
downloadpandoc-ca6cb23f23724d01b5f7d6ee7a3c9527ca8807e6.tar.gz
Modified Markdown writer to use autolinks when possible.
So, instead of [site.com](site.com) we get <site.com>. Changed test suite accordingly. git-svn-id: https://pandoc.googlecode.com/svn/trunk@508 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 297f2dc36..5eff079f8 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -35,7 +35,7 @@ module Text.Pandoc.Writers.Markdown (
import Text.Regex ( matchRegex, mkRegex )
import Text.Pandoc.Definition
import Text.Pandoc.Shared
-import Data.List ( group )
+import Data.List ( group, isPrefixOf, drop )
import Text.PrettyPrint.HughesPJ hiding ( Str )
-- | Convert Pandoc to Markdown.
@@ -183,11 +183,15 @@ inlineToMarkdown Space = char ' '
inlineToMarkdown (Link txt (Src src tit)) =
let linktext = if (null txt) || (txt == [Str ""])
then text "link"
- else inlineListToMarkdown txt in
- char '[' <> linktext <> char ']' <> char '(' <> text src <>
- (if tit /= ""
- then text (" \"" ++ (escapeLinkTitle tit) ++ "\"")
- else empty) <> char ')'
+ else inlineListToMarkdown txt
+ linktitle = if null tit
+ then empty
+ else text (" \"" ++ (escapeLinkTitle tit) ++ "\"")
+ srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src in
+ if (null tit) && (txt == [Str srcSuffix])
+ then char '<' <> text srcSuffix <> char '>'
+ else char '[' <> linktext <> char ']' <> char '(' <> text src <>
+ linktitle <> char ')'
inlineToMarkdown (Link txt (Ref ref)) =
let first = char '[' <> inlineListToMarkdown txt <> char ']'
second = if (txt == ref)