git.iko.soy/typeable/pandoc
on master help sign in
Markdown Reader: add attributes for autolink (#3183)
commit78e4fbda51a243f96176be001af8e538fcbc33c8 authorDaniele D'Orazio <daniele@develer.com> dateWed 26 Oct 2016, 12:18 (10 years ago) parentc46ad7c
2 files changed+13−2
src/Text/Pandoc/Readers/Markdown.hs+3−1 tests/Tests/Readers/Markdown.hs+10−1
src/Text/Pandoc/Readers/Markdown.hs+3−1
@@ -1828,7 +1828,9 @@ autoLink = try $ do
18281828 -- final punctuation. for example: in `<http://hi---there>`,
18291829 -- the URI parser will stop before the dashes.
18301830 extra <- fromEntities <$> manyTill nonspaceChar (char '>')
1831− return $ return $ B.link (src ++ escapeURI extra) "" (B.str $ orig ++ extra)
1831+ attr <- option nullAttr $ try $
1832+ guardEnabled Ext_link_attributes >> attributes
1833+ return $ return $ B.linkWith attr (src ++ escapeURI extra) "" (B.str $ orig ++ extra)
18321834
18331835image :: MarkdownParser (F Inlines)
18341836image = try $ do
tests/Tests/Readers/Markdown.hs+10−1
@@ -34,7 +34,10 @@ testBareLink (inp, ils) =
3434 inp (inp, doc $ para ils)
3535
3636autolink :: String -> Inlines
37−autolink s = link s "" (str s)
37+autolink = autolinkWith nullAttr
38+
39+autolinkWith :: Attr -> String -> Inlines
40+autolinkWith attr s = linkWith attr s "" (str s)
3841
3942bareLinkTests :: [(String, Inlines)]
4043bareLinkTests =
@@ -217,6 +220,12 @@ tests = [ testGroup "inline code"
217220 , "a partial URL (#2277)" =:
218221 "<www.boe.es/buscar/act.php?id=BOE-A-1996-8930#a66>" =?>
219222 para (text "<www.boe.es/buscar/act.php?id=BOE-A-1996-8930#a66>")
223+ , "with some attributes" =:
224+ "<http://foo.bar>{#i .j .z k=v}" =?>
225+ para (autolinkWith ("i", ["j", "z"], [("k", "v")]) "http://foo.bar")
226+ , "with some attributes and spaces" =:
227+ "<http://foo.bar> {#i .j .z k=v}" =?>
228+ para (autolink "http://foo.bar" <> space <> text "{#i .j .z k=v}")
220229 ]
221230 , testGroup "links"
222231 [ "no autolink inside link" =: