Textile reader: properly handle links with surrounding brackets.

Square brackets need to be used when the link isn't surrounded by
spaces or punctuation, or when the URL ending may be ambiguous.

Closes #564.
This commit is contained in:
John MacFarlane 2012-07-13 14:01:56 -07:00
parent 2192f02e19
commit f68b05e74b
3 changed files with 19 additions and 3 deletions

View file

@ -466,12 +466,25 @@ rawLaTeXInline' = try $ do
failIfStrict
rawLaTeXInline
-- | Textile standard link syntax is "label":target
-- | Textile standard link syntax is "label":target. But we
-- can also have ["label":target].
link :: GenParser Char ParserState Inline
link = try $ do
link = linkB <|> linkNoB
linkNoB :: GenParser Char ParserState Inline
linkNoB = try $ do
name <- surrounded (char '"') inline
char ':'
url <- manyTill (anyChar) (lookAhead $ (space <|> try (oneOf ".;,:" >> (space <|> newline))))
let stopChars = "!.,;:"
url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline)))
return $ Link name (url, "")
linkB :: GenParser Char ParserState Inline
linkB = try $ do
char '['
name <- surrounded (char '"') inline
char ':'
url <- manyTill nonspaceChar (char ']')
return $ Link name (url, "")
-- | Detect plain links to http or email.

View file

@ -83,6 +83,7 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
,Para [Link [Str "Email",Space,Str "link"] ("mailto:nobody@nowhere.net","")]
,Para [Str "Automatic",Space,Str "linking",Space,Str "to",Space,Link [Str "http://www.example.com"] ("http://www.example.com",""),Space,Str "and",Space,Link [Str "foobar@example.com"] ("mailto:foobar@example.com",""),Str "."]
,Para [Link [Str "Example"] ("http://www.example.com/",""),Str ":",Space,Str "Example",Space,Str "of",Space,Str "a",Space,Str "link",Space,Str "followed",Space,Str "by",Space,Str "a",Space,Str "colon",Str "."]
,Para [Str "A",Space,Str "link",Link [Str "with",Space,Str "brackets"] ("http://www.example.com",""),Str "and",Space,Str "no",Space,Str "spaces",Str "."]
,Header 1 [Str "Tables"]
,Para [Str "Textile",Space,Str "allows",Space,Str "tables",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "headers",Space,Str ":"]
,Header 2 [Str "Without",Space,Str "headers"]

View file

@ -155,6 +155,8 @@ Automatic linking to http://www.example.com and foobar@example.com.
"Example":http://www.example.com/: Example of a link followed by a colon.
A link["with brackets":http://www.example.com]and no spaces.
h1. Tables
Textile allows tables with and without headers :