@@ -54,7 +54,6 @@ module Text.Pandoc.Parsing ( (>>~),
5454 withRaw,
5555 escaped,
5656 characterReference,
57− updateLastStrPos,
5857 anyOrderedListMarker,
5958 orderedListMarker,
6059 charRef,
@@ -66,11 +65,14 @@ module Text.Pandoc.Parsing ( (>>~),
6665 testStringWith,
6766 guardEnabled,
6867 guardDisabled,
68+ updateLastStrPos,
69+ notAfterString,
6970 ParserState (..),
7071 HasReaderOptions (..),
7172 HasHeaderMap (..),
7273 HasIdentifierList (..),
7374 HasMacros (..),
75+ HasLastStrPosition (..),
7476 defaultParserState,
7577 HeaderType (..),
7678 ParserContext (..),
@@ -904,6 +906,14 @@ instance HasMacros ParserState where
904906 extractMacros = stateMacros
905907 updateMacros f st = st{ stateMacros = f $ stateMacros st }
906908
909+class HasLastStrPosition st where
910+ setLastStrPos :: SourcePos -> st -> st
911+ getLastStrPos :: st -> Maybe SourcePos
912+
913+instance HasLastStrPosition ParserState where
914+ setLastStrPos pos st = st{ stateLastStrPos = Just pos }
915+ getLastStrPos st = stateLastStrPos st
916+
907917defaultParserState :: ParserState
908918defaultParserState =
909919 ParserState { stateOptions = def,
@@ -938,6 +948,17 @@ guardEnabled ext = getOption readerExtensions >>= guard . Set.member ext
938948guardDisabled :: HasReaderOptions st => Extension -> Parser s st ()
939949guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
940950
951+-- | Update the position on which the last string ended.
952+updateLastStrPos :: HasLastStrPosition st => Parser s st ()
953+updateLastStrPos = getPosition >>= updateState . setLastStrPos
954+
955+-- | Whether we are right after the end of a string.
956+notAfterString :: HasLastStrPosition st => Parser s st Bool
957+notAfterString = do
958+ pos <- getPosition
959+ st <- getState
960+ return $ getLastStrPos st /= Just pos
961+
941962data HeaderType
942963 = SingleHeader Char -- ^ Single line of characters underneath
943964 | DoubleHeader Char -- ^ Lines of characters above and below
@@ -1049,17 +1070,11 @@ charOrRef cs =
10491070 guard (c `elem` cs)
10501071 return c)
10511072
1052−updateLastStrPos :: Parser [Char] ParserState ()
1053−updateLastStrPos = getPosition >>= \p ->
1054− updateState $ \s -> s{ stateLastStrPos = Just p }
1055−
10561073singleQuoteStart :: Parser [Char] ParserState ()
10571074singleQuoteStart = do
10581075 failIfInQuoteContext InSingleQuote
1059− pos <- getPosition
1060− st <- getState
10611076 -- single quote start can't be right after str
1062− guard $ stateLastStrPos st /= Just pos
1077+ guard =<< notAfterString
10631078 () <$ charOrRef "'\8216\145"
10641079
10651080singleQuoteEnd :: Parser [Char] st ()
@@ -1156,4 +1171,3 @@ applyMacros' target = do
11561171 then do macros <- extractMacros `fmap` getState
11571172 return $ applyMacros macros target
11581173 else return target
1159−