@@ -34,7 +34,7 @@ import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35import Text.Pandoc.Parsing
35import Text.Pandoc.Parsing
36import Text.ParserCombinators.Parsec
36import Text.ParserCombinators.Parsec
37−import Control.Monad ( when, liftM )
37+import Control.Monad ( when, liftM, guard )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
38import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
39import qualified Data.Map as M
39import qualified Data.Map as M
40import Text.Printf ( printf )
40import Text.Printf ( printf )
@@ -58,7 +58,7 @@ underlineChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
59-- treat these as potentially non-text when parsing inline:
59-- treat these as potentially non-text when parsing inline:
60specialChars :: [Char]
60specialChars :: [Char]
61−specialChars = "\\`|*_<>$:[]()-.\"'\8216\8217\8220\8221"
61+specialChars = "\\`|*_<>$:/[]{}()-.\"'\8216\8217\8220\8221"
64-- parsing documents
64-- parsing documents
@@ -831,12 +831,21 @@ code = try $ do
831 return $ Code nullAttr
831 return $ Code nullAttr
832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
834+-- succeeds only if we're not right after a str (ie. in middle of word)
835+atStart :: GenParser Char ParserState a -> GenParser Char ParserState a
839+ -- single quote start can't be right after str
840+ guard $ stateLastStrPos st /= Just pos
834emph :: GenParser Char ParserState Inline
843emph :: GenParser Char ParserState Inline
835−emph = enclosed (char '*') (char '*') inline >>=
844+emph = enclosed (atStart $ char '*') (char '*') inline >>=
836 return . Emph . normalizeSpaces
845 return . Emph . normalizeSpaces
838strong :: GenParser Char ParserState Inline
847strong :: GenParser Char ParserState Inline
839−strong = enclosed (string "**") (try $ string "**") inline >>=
848+strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
840 return . Strong . normalizeSpaces
849 return . Strong . normalizeSpaces
842-- Parses inline interpreted text which is required to have the given role.
851-- Parses inline interpreted text which is required to have the given role.
@@ -856,7 +865,7 @@ interpreted role = try $ do
856 -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
865 -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
857 -- but it should be good enough for most purposes
866 -- but it should be good enough for most purposes
858 unmarkedInterpretedText = do
867 unmarkedInterpretedText = do
859− result <- enclosed (char '`') (char '`') anyChar
868+ result <- enclosed (atStart $ char '`') (char '`') anyChar
860 return result
869 return result
862superscript :: GenParser Char ParserState Inline
871superscript :: GenParser Char ParserState Inline
@@ -873,9 +882,9 @@ whitespace = many1 spaceChar >> return Space <?> "whitespace"
874str :: GenParser Char ParserState Inline
883str :: GenParser Char ParserState Inline
876− result <- many1 (noneOf (specialChars ++ "\t\n "))
885+ let strChar = noneOf ("\t\n " ++ specialChars)
877− pos <- getPosition
886+ result <- many1 strChar
878− updateState $ \s -> s{ stateLastStrPos = Just pos }
887+ updateLastStrPos
879 return $ Str result
888 return $ Str result
881-- an endline character that can be treated as a space, not a structural break
890-- an endline character that can be treated as a space, not a structural break