mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-17 04:55:39 +00:00
Improved bare autolink detection.
Previously we disallowed `-` at the end of an autolink,
and disallowed the combination `=-`.
This commit liberalizes the rules for allowing punctuation in
a bare URI.
Added test cases.
One potential drawback is that you can no longer put a bare
URI in em dashes like this
this uri---http://example.com---is an example.
But in this respect we now match github's treatment of bare URIs.
Closes #2299.
This commit is contained in:
@@ -448,13 +448,12 @@ uri :: Stream [Char] m Char => ParserT [Char] st m (String, String)
|
||||
uri = try $ do
|
||||
scheme <- uriScheme
|
||||
char ':'
|
||||
-- We allow punctuation except at the end, since
|
||||
-- We allow sentence punctuation except at the end, since
|
||||
-- we don't want the trailing '.' in 'http://google.com.' We want to allow
|
||||
-- http://en.wikipedia.org/wiki/State_of_emergency_(disambiguation)
|
||||
-- as a URL, while NOT picking up the closing paren in
|
||||
-- (http://wikipedia.org). So we include balanced parens in the URL.
|
||||
let isWordChar c = isAlphaNum c || c == '_' || c == '/' || c == '+' ||
|
||||
not (isAscii c)
|
||||
let isWordChar c = isAlphaNum c || c `elem` "#$%*+/@\\_-"
|
||||
let wordChar = satisfy isWordChar
|
||||
let percentEscaped = try $ char '%' >> skipMany1 (satisfy isHexDigit)
|
||||
let entity = () <$ characterReference
|
||||
|
||||
@@ -119,6 +119,10 @@ bareLinkTests =
|
||||
autolink "http://business.timesonline.co.uk/article/0,,9065-2473189,00.html")
|
||||
, ("http://www.mail-archive.com/ruby-talk@ruby-lang.org/",
|
||||
autolink "http://www.mail-archive.com/ruby-talk@ruby-lang.org/")
|
||||
, ("https://example.org/?anchor=lala-",
|
||||
autolink "https://example.org/?anchor=lala-")
|
||||
, ("https://example.org/?anchor=-lala",
|
||||
autolink "https://example.org/?anchor=-lala")
|
||||
]
|
||||
|
||||
{-
|
||||
|
||||
Reference in New Issue
Block a user