From f68b05e74b7cc0dd0e217cc2650169a3fe7a41a0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 13 Jul 2012 14:01:56 -0700 Subject: 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. --- src/Text/Pandoc/Readers/Textile.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 348900d38..9f6289289 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -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 ':' + 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 (anyChar) (lookAhead $ (space <|> try (oneOf ".;,:" >> (space <|> newline)))) + url <- manyTill nonspaceChar (char ']') return $ Link name (url, "") -- | Detect plain links to http or email. -- cgit v1.2.3