From 21a2acaac9ee59b8c63dde78e99d46262518819c Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Wed, 29 Aug 2007 01:51:03 +0000 Subject: Split 'title' into 'linkTitle' and 'referenceTitle', since the rules are slightly different. git-svn-id: https://pandoc.googlecode.com/svn/trunk@952 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/Markdown.hs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index ad224e212..eb566491d 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -168,10 +168,20 @@ referenceKey = try $ do optional (char '<') src <- many (noneOf "> \n\t") optional (char '>') - tit <- option "" title + tit <- option "" referenceTitle blanklines return $ KeyBlock label (removeTrailingSpace src, tit) +referenceTitle = try $ do + skipSpaces + optional newline + skipSpaces + tit <- (charsInBalanced '(' ')' >>= return . unwords . words) + <|> do delim <- char '\'' <|> char '"' + manyTill anyChar (try (char delim >> skipSpaces >> + notFollowedBy (noneOf ")\n"))) + return $ decodeCharacterReferences tit + noteMarker = string "[^" >> manyTill (noneOf " \t\n") (char ']') rawLine = try $ do @@ -793,25 +803,20 @@ source = try $ do optional (char '<') src <- many (noneOf ")> \t\n") optional (char '>') - tit <- option "" title + tit <- option "" linkTitle skipSpaces char ')' return (removeTrailingSpace src, tit) -titleWith startChar endChar = try $ do - leadingSpace <- many1 (oneOf " \t\n") - if length (filter (=='\n') leadingSpace) > 1 - then fail "title must be separated by space and on same or next line" - else return () - char startChar - tit <- manyTill anyChar (try (char endChar >> skipSpaces >> - notFollowedBy (noneOf ")\n"))) +linkTitle = try $ do + skipSpaces + optional newline + skipSpaces + delim <- char '\'' <|> char '"' + tit <- manyTill anyChar (try (char delim >> skipSpaces >> + notFollowedBy (noneOf ")\n"))) return $ decodeCharacterReferences tit -title = choice [ titleWith '(' ')', - titleWith '"' '"', - titleWith '\'' '\''] "title" - link = try $ do label <- reference src <- source <|> referenceLink label -- cgit v1.2.3