From e555a5703d4581f11c6b5020811bf60b5ec98c41 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 7 Apr 2014 21:23:39 -0700 Subject: Textile reader: Improved link parsing. In particular we now pick up on attributes. Since pandoc links can't have attributes, we enclose the whole link in a span if there are attributes. Closes #1008. --- src/Text/Pandoc/Readers/Textile.hs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 81994e6bd..ae9c0cc8e 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -62,7 +62,7 @@ import Text.HTML.TagSoup.Match import Data.List ( intercalate ) import Data.Char ( digitToInt, isUpper) import Control.Monad ( guard, liftM ) -import Control.Applicative ((<$>), (*>), (<*)) +import Control.Applicative ((<$>), (*>), (<*), (<$)) import Data.Monoid -- | Parse a Textile text and return a Pandoc document. @@ -498,25 +498,21 @@ rawLaTeXInline' = try $ do -- | Textile standard link syntax is "label":target. But we -- can also have ["label":target]. link :: Parser [Char] ParserState Inlines -link = linkB <|> linkNoB - -linkNoB :: Parser [Char] ParserState Inlines -linkNoB = try $ do - name <- mconcat <$> surrounded (char '"') (withQuoteContext InDoubleQuote inline) - char ':' - let stopChars = "!.,;:" - url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline))) - let name' = if B.toList name == [Str "$"] then B.str url else name - return $ B.link url "" name' - -linkB :: Parser [Char] ParserState Inlines -linkB = try $ do - char '[' - name <- mconcat <$> surrounded (char '"') inline - char ':' - url <- manyTill nonspaceChar (char ']') +link = try $ do + bracketed <- (True <$ char '[') <|> return False + char '"' *> notFollowedBy (oneOf " \t\n\r") + attr <- attributes + name <- trimInlines . mconcat <$> + withQuoteContext InSingleQuote (manyTill inline (try (string "\":"))) + let stop = if bracketed + then char ']' + else lookAhead $ space <|> + try (oneOf "!.,;:" *> (space <|> newline)) + url <- manyTill nonspaceChar stop let name' = if B.toList name == [Str "$"] then B.str url else name - return $ B.link url "" name' + return $ if attr == nullAttr + then B.link url "" name' + else B.spanWith attr $ B.link url "" name' -- | image embedding image :: Parser [Char] ParserState Inlines -- cgit v1.2.3