@@ -54,7 +54,6 @@ module Text.Pandoc.Parsing ( (>>~),
56 characterReference,
56 characterReference,
58 anyOrderedListMarker,
57 anyOrderedListMarker,
59 orderedListMarker,
58 orderedListMarker,
@@ -66,11 +65,14 @@ module Text.Pandoc.Parsing ( (>>~),
66 testStringWith,
65 testStringWith,
67 guardEnabled,
66 guardEnabled,
68 guardDisabled,
67 guardDisabled,
69 ParserState (..),
70 ParserState (..),
70 HasReaderOptions (..),
71 HasReaderOptions (..),
71 HasHeaderMap (..),
72 HasHeaderMap (..),
72 HasIdentifierList (..),
73 HasIdentifierList (..),
73 HasMacros (..),
74 HasMacros (..),
75+ HasLastStrPosition (..),
74 defaultParserState,
76 defaultParserState,
75 HeaderType (..),
77 HeaderType (..),
76 ParserContext (..),
78 ParserContext (..),
@@ -904,6 +906,14 @@ instance HasMacros ParserState where
904 extractMacros = stateMacros
906 extractMacros = stateMacros
905 updateMacros f st = st{ stateMacros = f $ stateMacros st }
907 updateMacros f st = st{ stateMacros = f $ stateMacros st }
909+class HasLastStrPosition st where
910+ setLastStrPos :: SourcePos -> st -> st
911+ getLastStrPos :: st -> Maybe SourcePos
913+instance HasLastStrPosition ParserState where
914+ setLastStrPos pos st = st{ stateLastStrPos = Just pos }
915+ getLastStrPos st = stateLastStrPos st
907defaultParserState :: ParserState
917defaultParserState :: ParserState
908defaultParserState =
918defaultParserState =
909 ParserState { stateOptions = def,
919 ParserState { stateOptions = def,
@@ -938,6 +948,17 @@ guardEnabled ext = getOption readerExtensions >>= guard . Set.member ext
938guardDisabled :: HasReaderOptions st => Extension -> Parser s st ()
948guardDisabled :: HasReaderOptions st => Extension -> Parser s st ()
939guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
949guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
951+-- | Update the position on which the last string ended.
952+updateLastStrPos :: HasLastStrPosition st => Parser s st ()
953+updateLastStrPos = getPosition >>= updateState . setLastStrPos
955+-- | Whether we are right after the end of a string.
956+notAfterString :: HasLastStrPosition st => Parser s st Bool
960+ return $ getLastStrPos st /= Just pos
941data HeaderType
962data HeaderType
942 = SingleHeader Char -- ^ Single line of characters underneath
963 = SingleHeader Char -- ^ Single line of characters underneath
943 | DoubleHeader Char -- ^ Lines of characters above and below
964 | DoubleHeader Char -- ^ Lines of characters above and below
@@ -1049,17 +1070,11 @@ charOrRef cs =
1049 guard (c `elem` cs)
1070 guard (c `elem` cs)
1050 return c)
1071 return c)
1052−updateLastStrPos :: Parser [Char] ParserState ()
1053−updateLastStrPos = getPosition >>= \p ->
1054− updateState $ \s -> s{ stateLastStrPos = Just p }
1056singleQuoteStart :: Parser [Char] ParserState ()
1073singleQuoteStart :: Parser [Char] ParserState ()
1057singleQuoteStart = do
1074singleQuoteStart = do
1058 failIfInQuoteContext InSingleQuote
1075 failIfInQuoteContext InSingleQuote
1061 -- single quote start can't be right after str
1076 -- single quote start can't be right after str
1062− guard $ stateLastStrPos st /= Just pos
1077+ guard =<< notAfterString
1063 () <$ charOrRef "'\8216\145"
1078 () <$ charOrRef "'\8216\145"
1065singleQuoteEnd :: Parser [Char] st ()
1080singleQuoteEnd :: Parser [Char] st ()
@@ -1156,4 +1171,3 @@ applyMacros' target = do
1156 then do macros <- extractMacros `fmap` getState
1171 then do macros <- extractMacros `fmap` getState
1157 return $ applyMacros macros target
1172 return $ applyMacros macros target
1158 else return target
1173 else return target