Changes to fit new charsInBalanced.

This commit is contained in:
John MacFarlane
2011-12-05 20:55:23 -08:00
parent fa255f68ba
commit d34f85613a
2 changed files with 13 additions and 8 deletions
+2 -2
View File
@@ -59,7 +59,7 @@ specialChars = "\\`$%^&_~#{}[]\n \t|<>'\"-"
-- | Returns text between brackets and its matching pair.
bracketedText :: Char -> Char -> GenParser Char st [Char]
bracketedText openB closeB = do
result <- charsInBalanced' openB closeB
result <- charsInBalanced openB closeB anyChar
return $ [openB] ++ result ++ [closeB]
-- | Returns an option or argument of a LaTeX command.
@@ -888,7 +888,7 @@ ensureMath = try $ do
url :: GenParser Char ParserState Inline
url = try $ do
string "\\url"
url' <- charsInBalanced '{' '}'
url' <- charsInBalanced '{' '}' anyChar
return $ Link [Code ("",["url"],[]) url'] (escapeURI url', "")
link :: GenParser Char ParserState Inline
+11 -6
View File
@@ -108,6 +108,11 @@ atMostSpaces :: Int -> GenParser Char ParserState ()
atMostSpaces 0 = notFollowedBy (char ' ')
atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
litChar :: GenParser Char ParserState Char
litChar = escapedChar'
<|> noneOf "\n"
<|> (newline >> notFollowedBy blankline >> return ' ')
-- | Fail unless we're at beginning of a line.
failUnlessBeginningOfLine :: GenParser tok st ()
failUnlessBeginningOfLine = do
@@ -233,12 +238,12 @@ referenceKey = try $ do
-- return blanks so line count isn't affected
return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
referenceTitle :: GenParser Char st String
referenceTitle = try $ do
referenceTitle :: GenParser Char ParserState String
referenceTitle = try $ do
skipSpaces >> optional newline >> skipSpaces
tit <- (charsInBalanced '(' ')' >>= return . unwords . words)
tit <- (charsInBalanced '(' ')' litChar >>= return . unwords . words)
<|> do delim <- char '\'' <|> char '"'
manyTill anyChar (try (char delim >> skipSpaces >>
manyTill litChar (try (char delim >> skipSpaces >>
notFollowedBy (noneOf ")\n")))
return $ decodeCharacterReferences tit
@@ -1136,9 +1141,9 @@ reference = do notFollowedBy' (string "[^") -- footnote reference
return $ normalizeSpaces result
-- source for a link, with optional title
source :: GenParser Char st (String, [Char])
source :: GenParser Char ParserState (String, [Char])
source =
(try $ charsInBalanced '(' ')' >>= parseFromString source') <|>
(try $ charsInBalanced '(' ')' litChar >>= parseFromString source') <|>
-- the following is needed for cases like: [ref](/url(a).
(enclosed (char '(') (char ')') anyChar >>=
parseFromString source')