git.iko.soy/typeable/pandoc
on master help sign in
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.

commitf68b05e74b7cc0dd0e217cc2650169a3fe7a41a0 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 13 Jul 2012, 14:01 (14 years ago) parent2192f02
3 files changed+19−3
src/Text/Pandoc/Readers/Textile.hs+16−3 tests/textile-reader.native+1 tests/textile-reader.textile+2
src/Text/Pandoc/Readers/Textile.hs+16−3
@@ -466,12 +466,25 @@ rawLaTeXInline' = try $ do
466466 failIfStrict
467467 rawLaTeXInline
468468
469−-- | Textile standard link syntax is "label":target
469+-- | Textile standard link syntax is "label":target. But we
470+-- can also have ["label":target].
470471link :: GenParser Char ParserState Inline
471−link = try $ do
472+link = linkB <|> linkNoB
473+
474+linkNoB :: GenParser Char ParserState Inline
475+linkNoB = try $ do
476+ name <- surrounded (char '"') inline
477+ char ':'
478+ let stopChars = "!.,;:"
479+ url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline)))
480+ return $ Link name (url, "")
481+
482+linkB :: GenParser Char ParserState Inline
483+linkB = try $ do
484+ char '['
472485 name <- surrounded (char '"') inline
473486 char ':'
474− url <- manyTill (anyChar) (lookAhead $ (space <|> try (oneOf ".;,:" >> (space <|> newline))))
487+ url <- manyTill nonspaceChar (char ']')
475488 return $ Link name (url, "")
476489
477490-- | Detect plain links to http or email.
tests/textile-reader.native+1
@@ -83,6 +83,7 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
8383,Para [Link [Str "Email",Space,Str "link"] ("mailto:nobody@nowhere.net","")]
8484,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 "."]
8585,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 "."]
86+,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 "."]
8687,Header 1 [Str "Tables"]
8788,Para [Str "Textile",Space,Str "allows",Space,Str "tables",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "headers",Space,Str ":"]
8889,Header 2 [Str "Without",Space,Str "headers"]
tests/textile-reader.textile+2
@@ -155,6 +155,8 @@ Automatic linking to http://www.example.com and foobar@example.com.
155155
156156"Example":http://www.example.com/: Example of a link followed by a colon.
157157
158+A link["with brackets":http://www.example.com]and no spaces.
159+
158160h1. Tables
159161
160162Textile allows tables with and without headers :