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
This commit is contained in:
parent
0646eef976
commit
ca6cb23f23
2 changed files with 14 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -575,16 +575,15 @@ Here's an [inline link in pointy braces](/script?foo=1&bar=2).
|
|||
|
||||
## Autolinks
|
||||
|
||||
With an ampersand:
|
||||
[http://example.com/?foo=1&bar=2](http://example.com/?foo=1&bar=2)
|
||||
With an ampersand: <http://example.com/?foo=1&bar=2>
|
||||
|
||||
- In a list?
|
||||
- [http://example.com/](http://example.com/)
|
||||
- <http://example.com/>
|
||||
- It should.
|
||||
|
||||
An e-mail address: [nobody@nowhere.net](mailto:nobody@nowhere.net)
|
||||
An e-mail address: <nobody@nowhere.net>
|
||||
|
||||
> Blockquoted: [http://example.com/](http://example.com/)
|
||||
> Blockquoted: <http://example.com/>
|
||||
|
||||
Auto-links should not occur here: `<http://example.com/>`
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue