git.iko.soy/typeable/pandoc
on master help sign in
Replace read with safeRead. Closes #5162.
commit404e96761a9301e750a332524137639e204e44d0 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 17 Dec 2018, 10:24 (8 years ago) parent90c820d
3 files changed+8−11
src/Text/Pandoc/Readers/Docx/Lists.hs+4−4 src/Text/Pandoc/Readers/Odt/StyleReader.hs+3−6 src/Text/Pandoc/Readers/Org/Meta.hs+1−1
src/Text/Pandoc/Readers/Docx/Lists.hs+4−4
@@ -39,21 +39,21 @@ import Data.List
3939import Data.Maybe
4040import Text.Pandoc.Generic (bottomUp)
4141import Text.Pandoc.JSON
42−import Text.Pandoc.Shared (trim)
42+import Text.Pandoc.Shared (trim, safeRead)
4343
4444isListItem :: Block -> Bool
4545isListItem (Div (_, classes, _) _) | "list-item" `elem` classes = True
4646isListItem _ = False
4747
4848getLevel :: Block -> Maybe Integer
49−getLevel (Div (_, _, kvs) _) = read <$> lookup "level" kvs
49+getLevel (Div (_, _, kvs) _) = lookup "level" kvs >>= safeRead
5050getLevel _ = Nothing
5151
5252getLevelN :: Block -> Integer
5353getLevelN b = fromMaybe (-1) (getLevel b)
5454
5555getNumId :: Block -> Maybe Integer
56−getNumId (Div (_, _, kvs) _) = read <$> lookup "num-id" kvs
56+getNumId (Div (_, _, kvs) _) = lookup "num-id" kvs >>= safeRead
5757getNumId _ = Nothing
5858
5959getNumIdN :: Block -> Integer
@@ -89,7 +89,7 @@ getListType b@(Div (_, _, kvs) _) | isListItem b =
8989 Just f ->
9090 case txt of
9191 Just t -> Just $ Enumerated (
92− read (fromMaybe "1" start) :: Int,
92+ fromMaybe 1 (start >>= safeRead) :: Int,
9393 fromMaybe DefaultStyle (lookup f listStyleMap),
9494 fromMaybe DefaultDelim (lookup t listDelimMap))
9595 Nothing -> Nothing
src/Text/Pandoc/Readers/Odt/StyleReader.hs+3−6
@@ -62,7 +62,6 @@ import Prelude
6262import Control.Applicative hiding (liftA, liftA2, liftA3)
6363import Control.Arrow
6464
65−import Data.Char (isDigit)
6665import Data.Default
6766import qualified Data.Foldable as F
6867import Data.List (unfoldr)
@@ -72,6 +71,8 @@ import qualified Data.Set as S
7271
7372import qualified Text.XML.Light as XML
7473
74+import Text.Pandoc.Shared (safeRead)
75+
7576import Text.Pandoc.Readers.Odt.Arrows.Utils
7677
7778import Text.Pandoc.Readers.Odt.Generic.Fallible
@@ -576,11 +577,7 @@ readListLevelStyle levelType = readAttr NsText "level"
576577 toListLevelStyle _ p s LinfNone b = ListLevelStyle LltBullet p s LinfNone (startValue b)
577578 toListLevelStyle _ p s f@(LinfString _) b = ListLevelStyle LltBullet p s f (startValue b)
578579 toListLevelStyle t p s f b = ListLevelStyle t p s f (startValue b)
579− startValue (Just "") = 1
580− startValue (Just v) = if all isDigit v
581− then read v
582− else 1
583− startValue Nothing = 1
580+ startValue mbx = fromMaybe 1 (mbx >>= safeRead)
584581
585582--
586583chooseMostSpecificListLevelStyle :: S.Set ListLevelStyle -> Maybe ListLevelStyle
src/Text/Pandoc/Readers/Org/Meta.hs+1−1
@@ -265,7 +265,7 @@ macroDefinition = try $ do
265265 return (macroName, expander)
266266 where
267267 placeholder :: Monad m => OrgParser m Int
268− placeholder = try . fmap read $ char '$' *> many1 digit
268+ placeholder = try . fmap (fromMaybe 1 . safeRead) $ char '$' *> many1 digit
269269
270270 expansionPart :: Monad m => OrgParser m String
271271 expansionPart = try $ many (notFollowedBy placeholder *> noneOf "\n\r")