diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2022-03-24 11:38:55 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2022-03-24 11:38:55 -0700 |
| commit | 9fa2aeb489c1fe9aa6ac8013d77002f3c129f88d (patch) | |
| tree | 3cd21ad228dc1798184248d6c4fb03a5e06608b9 | |
| parent | 512da9aeb996a2cdec9c4ac755174f44a3e1f278 (diff) | |
RTF reader: more efficient parsing of command parameters.
| -rw-r--r-- | src/Text/Pandoc/Readers/RTF.hs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/RTF.hs b/src/Text/Pandoc/Readers/RTF.hs index 7caa3925f..30bbe6c07 100644 --- a/src/Text/Pandoc/Readers/RTF.hs +++ b/src/Text/Pandoc/Readers/RTF.hs @@ -30,7 +30,7 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad (..), insertMedia) import Text.Pandoc.Definition import Text.Pandoc.Options import Text.Pandoc.Parsing -import Text.Pandoc.Shared (safeRead, tshow) +import Text.Pandoc.Shared (tshow) import Data.Char (isAlphaNum, chr, isAscii, isLetter, isSpace, ord) import qualified Data.ByteString.Lazy as BL import Data.Digest.Pure.SHA (sha1, showDigest) @@ -252,10 +252,18 @@ tok = do dat <- BL.pack . map (fromIntegral . ord) <$> count n anyChar return $ BinData dat parameter = do - hyph <- string "-" <|> pure "" + hyph <- option False $ True <$ char '-' rest <- many digit - let pstr = T.pack $ hyph <> rest - return $ safeRead pstr + if null rest + then return Nothing + else do + let pstr = T.pack rest + case TR.decimal pstr of + Right (i,_) -> + return $ Just $ if hyph + then (-1) * i + else i + _ -> return Nothing hexVal = do char '\'' x <- hexDigit |
