git.iko.soy/typeable/pandoc
on master help sign in
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

commitca6cb23f23724d01b5f7d6ee7a3c9527ca8807e6 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateWed 24 Jan 2007, 19:06 (20 years ago) parent0646eef
2 files changed+14−11
src/Text/Pandoc/Writers/Markdown.hs+10−6 tests/writer.markdown+4−5
src/Text/Pandoc/Writers/Markdown.hs+10−6
@@ -35,7 +35,7 @@ module Text.Pandoc.Writers.Markdown (
3535import Text.Regex ( matchRegex, mkRegex )
3636import Text.Pandoc.Definition
3737import Text.Pandoc.Shared
38−import Data.List ( group )
38+import Data.List ( group, isPrefixOf, drop )
3939import Text.PrettyPrint.HughesPJ hiding ( Str )
4040
4141-- | Convert Pandoc to Markdown.
@@ -183,11 +183,15 @@ inlineToMarkdown Space = char ' '
183183inlineToMarkdown (Link txt (Src src tit)) =
184184 let linktext = if (null txt) || (txt == [Str ""])
185185 then text "link"
186− else inlineListToMarkdown txt in
187− char '[' <> linktext <> char ']' <> char '(' <> text src <>
188− (if tit /= ""
189− then text (" \"" ++ (escapeLinkTitle tit) ++ "\"")
190− else empty) <> char ')'
186+ else inlineListToMarkdown txt
187+ linktitle = if null tit
188+ then empty
189+ else text (" \"" ++ (escapeLinkTitle tit) ++ "\"")
190+ srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src in
191+ if (null tit) && (txt == [Str srcSuffix])
192+ then char '<' <> text srcSuffix <> char '>'
193+ else char '[' <> linktext <> char ']' <> char '(' <> text src <>
194+ linktitle <> char ')'
191195inlineToMarkdown (Link txt (Ref ref)) =
192196 let first = char '[' <> inlineListToMarkdown txt <> char ']'
193197 second = if (txt == ref)
tests/writer.markdown+4−5
@@ -575,16 +575,15 @@ Here's an [inline link in pointy braces](/script?foo=1&bar=2).
575575
576576## Autolinks
577577
578−With an ampersand:
579−[http://example.com/?foo=1&bar=2](http://example.com/?foo=1&bar=2)
578+With an ampersand: <http://example.com/?foo=1&bar=2>
580579
581580- In a list?
582−- [http://example.com/](http://example.com/)
581+- <http://example.com/>
583582- It should.
584583
585−An e-mail address: [nobody@nowhere.net](mailto:nobody@nowhere.net)
584+An e-mail address: <nobody@nowhere.net>
586585
587−> Blockquoted: [http://example.com/](http://example.com/)
586+> Blockquoted: <http://example.com/>
588587
589588Auto-links should not occur here: `<http://example.com/>`
590589