git.iko.soy/typeable/pandoc
on master help sign in
Modified Markdown writer to use autolinks when possible.
ca6cb23fiddlosopher
src/Text/Pandoc/Writers/Markdown.hs+10−6
@@ -35,7 +35,7 @@ module Text.Pandoc.Writers.Markdown (
35import Text.Regex ( matchRegex, mkRegex )
35import Text.Regex ( matchRegex, mkRegex )
36import Text.Pandoc.Definition
36import Text.Pandoc.Definition
37import Text.Pandoc.Shared
37import Text.Pandoc.Shared
38−import Data.List ( group )
38+import Data.List ( group, isPrefixOf, drop )
39import Text.PrettyPrint.HughesPJ hiding ( Str )
39import Text.PrettyPrint.HughesPJ hiding ( Str )
40
40
41-- | Convert Pandoc to Markdown.
41-- | Convert Pandoc to Markdown.
@@ -183,11 +183,15 @@ inlineToMarkdown Space = char ' '
183inlineToMarkdown (Link txt (Src src tit)) =
183inlineToMarkdown (Link txt (Src src tit)) =
184 let linktext = if (null txt) || (txt == [Str ""])
184 let linktext = if (null txt) || (txt == [Str ""])
185 then text "link"
185 then text "link"
186− else inlineListToMarkdown txt in
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 '>'
187− char '[' <> linktext <> char ']' <> char '(' <> text src <>
193+ else char '[' <> linktext <> char ']' <> char '(' <> text src <>
188− (if tit /= ""
194+ linktitle <> char ')'
189− then text (" \"" ++ (escapeLinkTitle tit) ++ "\"")
190− else empty) <> char ')'
191inlineToMarkdown (Link txt (Ref ref)) =
195inlineToMarkdown (Link txt (Ref ref)) =
192 let first = char '[' <> inlineListToMarkdown txt <> char ']'
196 let first = char '[' <> inlineListToMarkdown txt <> char ']'
193 second = if (txt == ref)
197 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).
575
575
576## Autolinks
576## Autolinks
577
577
578−With an ampersand:
578+With an ampersand: <http://example.com/?foo=1&bar=2>
579−[http://example.com/?foo=1&bar=2](http://example.com/?foo=1&bar=2)
580
579
581- In a list?
580- In a list?
582−- [http://example.com/](http://example.com/)
581+- <http://example.com/>
583- It should.
582- It should.
584
583
585−An e-mail address: [nobody@nowhere.net](mailto:nobody@nowhere.net)
584+An e-mail address: <nobody@nowhere.net>
586
585
587−> Blockquoted: [http://example.com/](http://example.com/)
586+> Blockquoted: <http://example.com/>
588
587
589Auto-links should not occur here: `<http://example.com/>`
588Auto-links should not occur here: `<http://example.com/>`
590
589