git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: properly handle links with surrounding brackets.
f68b05eJohn MacFarlane
src/Text/Pandoc/Readers/Textile.hs+16−3
@@ -466,12 +466,25 @@ rawLaTeXInline' = try $ do
466 failIfStrict
466 failIfStrict
467 rawLaTeXInline
467 rawLaTeXInline
468
468
469−-- | Textile standard link syntax is "label":target
469+-- | Textile standard link syntax is "label":target. But we
470+-- can also have ["label":target].
470link :: GenParser Char ParserState Inline
471link :: 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 '['
472 name <- surrounded (char '"') inline
485 name <- surrounded (char '"') inline
473 char ':'
486 char ':'
474− url <- manyTill (anyChar) (lookAhead $ (space <|> try (oneOf ".;,:" >> (space <|> newline))))
487+ url <- manyTill nonspaceChar (char ']')
475 return $ Link name (url, "")
488 return $ Link name (url, "")
476
489
477-- | Detect plain links to http or email.
490-- | Detect plain links to http or email.
tests/textile-reader.native+1
@@ -83,6 +83,7 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
83,Para [Link [Str "Email",Space,Str "link"] ("mailto:nobody@nowhere.net","")]
83,Para [Link [Str "Email",Space,Str "link"] ("mailto:nobody@nowhere.net","")]
84,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 "."]
84,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 "."]
85,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 "."]
85,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 "."]
86,Header 1 [Str "Tables"]
87,Header 1 [Str "Tables"]
87,Para [Str "Textile",Space,Str "allows",Space,Str "tables",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "headers",Space,Str ":"]
88,Para [Str "Textile",Space,Str "allows",Space,Str "tables",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "headers",Space,Str ":"]
88,Header 2 [Str "Without",Space,Str "headers"]
89,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.
155
155
156"Example":http://www.example.com/: Example of a link followed by a colon.
156"Example":http://www.example.com/: Example of a link followed by a colon.
157
157
158+A link["with brackets":http://www.example.com]and no spaces.
159+
158h1. Tables
160h1. Tables
159
161
160Textile allows tables with and without headers :
162Textile allows tables with and without headers :