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

commite555a5703d4581f11c6b5020811bf60b5ec98c41 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 7 Apr 2014, 21:23 (13 years ago) parentbfd598e
1 file changed+15−19
src/Text/Pandoc/Readers/Textile.hs+15−19
src/Text/Pandoc/Readers/Textile.hs+15−19
@@ -62,7 +62,7 @@ import Text.HTML.TagSoup.Match
6262import Data.List ( intercalate )
6363import Data.Char ( digitToInt, isUpper)
6464import Control.Monad ( guard, liftM )
65−import Control.Applicative ((<$>), (*>), (<*))
65+import Control.Applicative ((<$>), (*>), (<*), (<$))
6666import Data.Monoid
6767
6868-- | Parse a Textile text and return a Pandoc document.
@@ -498,25 +498,21 @@ rawLaTeXInline' = try $ do
498498-- | Textile standard link syntax is "label":target. But we
499499-- can also have ["label":target].
500500link :: Parser [Char] ParserState Inlines
501−link = linkB <|> linkNoB
502−
503−linkNoB :: Parser [Char] ParserState Inlines
504−linkNoB = try $ do
505− name <- mconcat <$> surrounded (char '"') (withQuoteContext InDoubleQuote inline)
506− char ':'
507− let stopChars = "!.,;:"
508− url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline)))
509− let name' = if B.toList name == [Str "$"] then B.str url else name
510− return $ B.link url "" name'
511−
512−linkB :: Parser [Char] ParserState Inlines
513−linkB = try $ do
514− char '['
515− name <- mconcat <$> surrounded (char '"') inline
516− char ':'
517− url <- manyTill nonspaceChar (char ']')
501+link = try $ do
502+ bracketed <- (True <$ char '[') <|> return False
503+ char '"' *> notFollowedBy (oneOf " \t\n\r")
504+ attr <- attributes
505+ name <- trimInlines . mconcat <$>
506+ withQuoteContext InSingleQuote (manyTill inline (try (string "\":")))
507+ let stop = if bracketed
508+ then char ']'
509+ else lookAhead $ space <|>
510+ try (oneOf "!.,;:" *> (space <|> newline))
511+ url <- manyTill nonspaceChar stop
518512 let name' = if B.toList name == [Str "$"] then B.str url else name
519− return $ B.link url "" name'
513+ return $ if attr == nullAttr
514+ then B.link url "" name'
515+ else B.spanWith attr $ B.link url "" name'
520516
521517-- | image embedding
522518image :: Parser [Char] ParserState Inlines