@@ -37,7 +37,7 @@ import Control.Arrow (second)
3737import Control.Monad (forM_, guard, liftM, mplus, mzero, when)
3838import Control.Monad.Except (throwError)
3939import Control.Monad.Identity (Identity (..))
40−import Data.Char (isHexDigit, isSpace, toLower, toUpper)
40+import Data.Char (isHexDigit, isSpace, toLower, toUpper, isAlphaNum)
4141import Data.List (deleteFirstsBy, elemIndex, intercalate, isInfixOf, isSuffixOf,
4242 nub, sort, transpose, union)
4343import qualified Data.Map as M
@@ -1385,7 +1385,6 @@ strong = B.strong . trimInlines . mconcat <$>
13851385--
13861386-- TODO:
13871387-- - Classes are silently discarded in addNewRole
1388−-- - Lacks sensible implementation for title-reference (which is the default)
13891388-- - Allows direct use of the :raw: role, rST only allows inherited use.
13901389interpretedRole :: PandocMonad m => RSTParser m Inlines
13911390interpretedRole = try $ do
@@ -1395,12 +1394,12 @@ interpretedRole = try $ do
13951394renderRole :: PandocMonad m
13961395 => String -> Maybe String -> String -> Attr -> RSTParser m Inlines
13971396renderRole contents fmt role attr = case role of
1398− "sup" -> return $ B.superscript $ B.str contents
1399− "superscript" -> return $ B.superscript $ B.str contents
1400− "sub" -> return $ B.subscript $ B.str contents
1401− "subscript" -> return $ B.subscript $ B.str contents
1402− "emphasis" -> return $ B.emph $ B.str contents
1403− "strong" -> return $ B.strong $ B.str contents
1397+ "sup" -> return $ B.superscript $ treatAsText contents
1398+ "superscript" -> return $ B.superscript $ treatAsText contents
1399+ "sub" -> return $ B.subscript $ treatAsText contents
1400+ "subscript" -> return $ B.subscript $ treatAsText contents
1401+ "emphasis" -> return $ B.emph $ treatAsText contents
1402+ "strong" -> return $ B.strong $ treatAsText contents
14041403 "rfc-reference" -> return $ rfcLink contents
14051404 "RFC" -> return $ rfcLink contents
14061405 "pep-reference" -> return $ pepLink contents
@@ -1411,7 +1410,7 @@ renderRole contents fmt role attr = case role of
14111410 "title" -> titleRef contents
14121411 "t" -> titleRef contents
14131412 "code" -> return $ B.codeWith (addClass "sourceCode" attr) contents
1414− "span" -> return $ B.spanWith attr $ B.str contents
1413+ "span" -> return $ B.spanWith attr $ treatAsText contents
14151414 "raw" -> return $ B.rawInline (fromMaybe "" fmt) contents
14161415 custom -> do
14171416 customRoles <- stateRstCustomRoles <$> getState
@@ -1419,14 +1418,20 @@ renderRole contents fmt role attr = case role of
14191418 Just (newRole, newFmt, newAttr) ->
14201419 renderRole contents newFmt newRole newAttr
14211420 Nothing -> -- undefined role
1422− return $ B.spanWith ("",[],[("role",role)]) (B.str contents)
1421+ return $ B.codeWith ("",["interpreted-text"],[("role",role)])
1422+ contents
14231423 where
1424− titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
1424+ titleRef ref = return $ B.spanWith ("",["title-ref"],[]) $ treatAsText ref
14251425 rfcLink rfcNo = B.link rfcUrl ("RFC " ++ rfcNo) $ B.str ("RFC " ++ rfcNo)
14261426 where rfcUrl = "http://www.faqs.org/rfcs/rfc" ++ rfcNo ++ ".html"
14271427 pepLink pepNo = B.link pepUrl ("PEP " ++ pepNo) $ B.str ("PEP " ++ pepNo)
14281428 where padNo = replicate (4 - length pepNo) '0' ++ pepNo
14291429 pepUrl = "http://www.python.org/dev/peps/pep-" ++ padNo ++ "/"
1430+ treatAsText = B.text . handleEscapes
1431+ handleEscapes [] = []
1432+ handleEscapes ('\\':' ':cs) = handleEscapes cs
1433+ handleEscapes ('\\':c:cs) = c : handleEscapes cs
1434+ handleEscapes (c:cs) = c : handleEscapes cs
14301435
14311436addClass :: String -> Attr -> Attr
14321437addClass c (ident, classes, keyValues) = (ident, classes `union` [c], keyValues)
@@ -1450,7 +1455,18 @@ roleAfter = try $ do
14501455 return (role,contents)
14511456
14521457unmarkedInterpretedText :: PandocMonad m => RSTParser m [Char]
1453−unmarkedInterpretedText = enclosed (atStart $ char '`') (char '`') anyChar
1458+unmarkedInterpretedText = try $ do
1459+ atStart (char '`')
1460+ contents <- mconcat <$> (many1
1461+ ( many1 (noneOf "`\\\n")
1462+ <|> (char '\\' >> ((\c -> ['\\',c]) <$> noneOf "\n"))
1463+ <|> (string "\n" <* notFollowedBy blankline)
1464+ <|> try (string "`" <*
1465+ notFollowedBy (() <$ roleMarker) <*
1466+ lookAhead (satisfy isAlphaNum))
1467+ ))
1468+ char '`'
1469+ return contents
14541470
14551471whitespace :: PandocMonad m => RSTParser m Inlines
14561472whitespace = B.space <$ skipMany1 spaceChar <?> "whitespace"