diff options
author | Daniele D'Orazio <daniele@develer.com> | 2016-10-26 12:18:58 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-10-26 12:18:58 +0200 |
commit | 78e4fbda51a243f96176be001af8e538fcbc33c8 (patch) | |
tree | 7b96d333cafae242cbe4ab329209dc3b6ec70762 | |
parent | c46ad7c8db5bb6a8c1666f60b21184f5b75bf3ab (diff) | |
download | pandoc-78e4fbda51a243f96176be001af8e538fcbc33c8.tar.gz |
Markdown Reader: add attributes for autolink (#3183)
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 4 | ||||
-rw-r--r-- | tests/Tests/Readers/Markdown.hs | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 2337b733a..f020e1bee 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1828,7 +1828,9 @@ autoLink = try $ do -- final punctuation. for example: in `<http://hi---there>`, -- the URI parser will stop before the dashes. extra <- fromEntities <$> manyTill nonspaceChar (char '>') - return $ return $ B.link (src ++ escapeURI extra) "" (B.str $ orig ++ extra) + attr <- option nullAttr $ try $ + guardEnabled Ext_link_attributes >> attributes + return $ return $ B.linkWith attr (src ++ escapeURI extra) "" (B.str $ orig ++ extra) image :: MarkdownParser (F Inlines) image = try $ do diff --git a/tests/Tests/Readers/Markdown.hs b/tests/Tests/Readers/Markdown.hs index 9219b6930..739763e77 100644 --- a/tests/Tests/Readers/Markdown.hs +++ b/tests/Tests/Readers/Markdown.hs @@ -34,7 +34,10 @@ testBareLink (inp, ils) = inp (inp, doc $ para ils) autolink :: String -> Inlines -autolink s = link s "" (str s) +autolink = autolinkWith nullAttr + +autolinkWith :: Attr -> String -> Inlines +autolinkWith attr s = linkWith attr s "" (str s) bareLinkTests :: [(String, Inlines)] bareLinkTests = @@ -217,6 +220,12 @@ tests = [ testGroup "inline code" , "a partial URL (#2277)" =: "<www.boe.es/buscar/act.php?id=BOE-A-1996-8930#a66>" =?> para (text "<www.boe.es/buscar/act.php?id=BOE-A-1996-8930#a66>") + , "with some attributes" =: + "<http://foo.bar>{#i .j .z k=v}" =?> + para (autolinkWith ("i", ["j", "z"], [("k", "v")]) "http://foo.bar") + , "with some attributes and spaces" =: + "<http://foo.bar> {#i .j .z k=v}" =?> + para (autolink "http://foo.bar" <> space <> text "{#i .j .z k=v}") ] , testGroup "links" [ "no autolink inside link" =: |