@@ -535,8 +535,15 @@ enclosedInlines start end = try $
535535-- FIXME: This is a hack
536536inlinesEnclosedBy :: Char
537537 -> OrgParser Inlines
538−inlinesEnclosedBy c = enclosedInlines (atStart (char c) <* endsOnThisOrNextLine c)
539− (atEnd $ char c)
538+inlinesEnclosedBy c = try $ do
539+ updateState $ \st -> st { orgInlineCharStack = c:(orgInlineCharStack st) }
540+ res <- enclosedInlines (atStart (char c) <* endsOnThisOrNextLine c)
541+ (atEnd $ char c)
542+ updateState $ \st -> st { orgInlineCharStack = shift . orgInlineCharStack $ st }
543+ return res
544+ where shift xs
545+ | null xs = []
546+ | otherwise = tail xs
540547
541548enclosedRaw :: OrgParser a
542549 -> OrgParser b
@@ -561,11 +568,16 @@ atStart p = do
561568
562569-- | succeeds only if we're at the end of a word
563570atEnd :: OrgParser a -> OrgParser a
564−atEnd p = try $ p <* lookingAtEndOfWord
565− where lookingAtEndOfWord = lookAhead . oneOf $ postWordChars
571+atEnd p = try $ do
572+ p <* lookingAtEndOfWord
573+ where lookingAtEndOfWord = lookAhead . oneOf =<< postWordChars
566574
567−postWordChars :: [Char]
568−postWordChars = "\t\n\r !\"'),-.:?}"
575+postWordChars :: OrgParser [Char]
576+postWordChars = do
577+ st <- getState
578+ return $ "\t\n\r !\"'),-.:?}" ++ (safeSecond . orgInlineCharStack $ st)
579+ where safeSecond (_:x2:_) = [x2]
580+ safeSecond _ = []
569581
570582-- FIXME: These functions are hacks and should be replaced
571583endsOnThisOrNextLine :: Char
@@ -580,9 +592,10 @@ endsOnThisLine :: [Char]
580592 -> ([Char] -> OrgParser ())
581593 -> OrgParser ()
582594endsOnThisLine input c doOnOtherLines = do
595+ postWordChars' <- postWordChars
583596 case break (`elem` c:"\n") input of
584597 (_,'\n':rest) -> doOnOtherLines rest
585− (_,_:rest@(n:_)) -> if n `elem` postWordChars
598+ (_,_:rest@(n:_)) -> if n `elem` postWordChars'
586599 then return ()
587600 else endsOnThisLine rest c doOnOtherLines
588601 _ -> mzero