Skip to content

Commit

Permalink
RST reader: tighten up rules fro when emphasis can start.
Browse files Browse the repository at this point in the history
Closes #9805.
  • Loading branch information
jgm committed May 27, 2024
1 parent a7c6a29 commit 205e54c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Text/Pandoc/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ Conversion from reStructuredText to 'Pandoc' document.
-}
module Text.Pandoc.Readers.RST ( readRST ) where
import Control.Arrow (second)
import Control.Monad (forM_, guard, liftM, mplus, mzero, when)
import Control.Monad (forM_, guard, liftM, mplus, mzero, when, unless)
import Control.Monad.Except (throwError)
import Control.Monad.Identity (Identity (..))
import Data.Char (isHexDigit, isSpace, toUpper, isAlphaNum)
import Data.Char (isHexDigit, isSpace, toUpper, isAlphaNum, generalCategory,
GeneralCategory(OpenPunctuation, InitialQuote, FinalQuote,
DashPunctuation, OtherSymbol))
import Data.List (deleteFirstsBy, elemIndex, nub, partition, sort, transpose)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, maybeToList, isJust)
Expand Down Expand Up @@ -1391,17 +1393,24 @@ hyphens = do
-- don't want to treat endline after hyphen or dash as a space
return $ B.str result

escapedChar :: Monad m => ParsecT Sources st m Inlines
escapedChar :: Monad m => RSTParser m Inlines
escapedChar = do c <- escaped anyChar
unless (canPrecedeOpener c) $ updateLastStrPos
return $ if c == ' ' || c == '\n' || c == '\r'
-- '\ ' is null in RST
then mempty
else B.str $ T.singleton c

canPrecedeOpener :: Char -> Bool
canPrecedeOpener c =
generalCategory c `elem`
[OpenPunctuation, InitialQuote, FinalQuote, DashPunctuation, OtherSymbol]

symbol :: Monad m => RSTParser m Inlines
symbol = do
result <- oneOf specialChars
return $ B.str $ T.singleton result
c <- oneOf specialChars
unless (canPrecedeOpener c) $ updateLastStrPos
return $ B.str $ T.singleton c

-- parses inline code, between codeStart and codeEnd
code :: Monad m => RSTParser m Inlines
Expand Down
10 changes: 10 additions & 0 deletions test/command/9805.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```
% pandoc -f rst -t native
word.*word
------------
* abc
^D
[ Header 1 ( "word.word" , [] , [] ) [ Str "word.*word" ]
, BulletList [ [ Plain [ Str "abc" ] ] ]
]
```

0 comments on commit 205e54c

Please sign in to comment.