@@ -34,7 +34,7 @@ import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
3535import Text.Pandoc.Parsing
3636import Text.ParserCombinators.Parsec
37−import Control.Monad ( when, liftM )
37+import Control.Monad ( when, liftM, guard )
3838import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
3939import qualified Data.Map as M
4040import Text.Printf ( printf )
@@ -58,7 +58,7 @@ underlineChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
5858
5959-- treat these as potentially non-text when parsing inline:
6060specialChars :: [Char]
61−specialChars = "\\`|*_<>$:[]()-.\"'\8216\8217\8220\8221"
61+specialChars = "\\`|*_<>$:/[]{}()-.\"'\8216\8217\8220\8221"
6262
6363--
6464-- parsing documents
@@ -831,12 +831,21 @@ code = try $ do
831831 return $ Code nullAttr
832832 $ removeLeadingTrailingSpace $ intercalate " " $ lines result
833833
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
836+atStart p = do
837+ pos <- getPosition
838+ st <- getState
839+ -- single quote start can't be right after str
840+ guard $ stateLastStrPos st /= Just pos
841+ p
842+
834843emph :: GenParser Char ParserState Inline
835−emph = enclosed (char '*') (char '*') inline >>=
844+emph = enclosed (atStart $ char '*') (char '*') inline >>=
836845 return . Emph . normalizeSpaces
837846
838847strong :: GenParser Char ParserState Inline
839−strong = enclosed (string "**") (try $ string "**") inline >>=
848+strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
840849 return . Strong . normalizeSpaces
841850
842851-- Parses inline interpreted text which is required to have the given role.
@@ -856,7 +865,7 @@ interpreted role = try $ do
856865 -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
857866 -- but it should be good enough for most purposes
858867 unmarkedInterpretedText = do
859− result <- enclosed (char '`') (char '`') anyChar
868+ result <- enclosed (atStart $ char '`') (char '`') anyChar
860869 return result
861870
862871superscript :: GenParser Char ParserState Inline
@@ -873,9 +882,9 @@ whitespace = many1 spaceChar >> return Space <?> "whitespace"
873882
874883str :: GenParser Char ParserState Inline
875884str = do
876− result <- many1 (noneOf (specialChars ++ "\t\n "))
877− pos <- getPosition
878− updateState $ \s -> s{ stateLastStrPos = Just pos }
885+ let strChar = noneOf ("\t\n " ++ specialChars)
886+ result <- many1 strChar
887+ updateLastStrPos
879888 return $ Str result
880889
881890-- an endline character that can be treated as a space, not a structural break