@@ -128,6 +128,24 @@ failUnlessSmart = do
128 state <- getState
128 state <- getState
129 if stateSmart state then return () else fail "Smart typography feature"
129 if stateSmart state then return () else fail "Smart typography feature"
131+-- | Parse a sequence of inline elements between a string
132+-- @opener@ and a string @closer@, including inlines
133+-- between balanced pairs of @opener@ and a @closer@.
134+inlinesInBalanced :: String -> String -> GenParser Char ParserState [Inline]
135+inlinesInBalanced opener closer = try $ do
136+ let nonOpenerSymbol = try $ do -- succeeds if next inline would be Str opener
137+ res <- inline -- fails if next inline merely begins with opener
138+ if res == Str opener
142+ result <- manyTill ( (do notFollowedBy nonOpenerSymbol
143+ bal <- inlinesInBalanced opener closer
144+ return $ [Str opener] ++ bal ++ [Str closer])
145+ <|> (count 1 inline))
146+ (try (string closer))
147+ return $ concat result
132-- document structure
150-- document structure
@@ -915,22 +933,9 @@ endline = try (do
920− -- allow for embedded brackets:
921− raw <- manyTill (do{res <- rawLabel; return ("[" ++ res ++ "]")} <|>
922− count 1 anyChar) (char labelEnd)
925-- a reference label for a link
936-- a reference label for a link
926−reference = try $ do
937+reference = inlinesInBalanced [labelStart] [labelEnd] >>= (return . normalizeSpaces)
928− oldInput <- getInput
930− label <- many inline
932− return (normalizeSpaces label)
934-- source for a link, with optional title
939-- source for a link, with optional title
935source = try $ do
940source = try $ do
936 char srcStart
941 char srcStart
@@ -948,10 +953,9 @@ titleWith startChar endChar = try (do
948 then fail "title must be separated by space and on same or next line"
953 then fail "title must be separated by space and on same or next line"
949 else return ()
954 else return ()
950 char startChar
955 char startChar
951− tit <- manyTill anyChar (try (do
956+ tit <- manyTill anyChar (try (do char endChar
953− skipSpaces
957+ skipSpaces
954− notFollowedBy (noneOf ")\n")))
958+ notFollowedBy (noneOf ")\n")))
955 return $ decodeEntities tit)
959 return $ decodeEntities tit)
957title = choice [ titleWith '(' ')',
961title = choice [ titleWith '(' ')',
@@ -1011,19 +1015,10 @@ note = try $ do
1011 Nothing -> fail "note not found"
1015 Nothing -> fail "note not found"
1012 Just contents -> return (Note contents)
1016 Just contents -> return (Note contents)
1014−inlinesInBrackets = try $ do
1016− results <- many $ count 1 (choice [link, referenceLink, image]) <|>
1017− try (do{res <- inlinesInBrackets; return
1018− ([Str "["] ++ res ++ [Str "]"])}) <|>
1019− (do{notFollowedBy (char ']'); count 1 inline})
1021− return $ concat results
1023inlineNote = try $ do
1018inlineNote = try $ do
1024 failIfStrict
1019 failIfStrict
1025 char noteStart
1020 char noteStart
1026− contents <- inlinesInBrackets
1021+ contents <- inlinesInBalanced "[" "]"
1027 return (Note [Para contents])
1022 return (Note [Para contents])
1029rawLaTeXInline' = do
1024rawLaTeXInline' = do