git.iko.soy/typeable/pandoc
on master help sign in
Replace read with safeRead (#5186)

closes #5180

commitc8b79b0a04c113e0ea41099b0201576710158a49 authorMauro Bieg <mb21@users.noreply.github.com> dateTue 1 Jan 2019, 00:26 (8 years ago) parenta1ad5bb
3 files changed+18−13
src/Text/Pandoc/Readers/TikiWiki.hs+6−3 src/Text/Pandoc/Writers/Docx.hs+5−5 src/Text/Pandoc/Writers/LaTeX.hs+7−5
src/Text/Pandoc/Readers/TikiWiki.hs+6−3
@@ -32,7 +32,7 @@ import Text.Pandoc.Definition
3232import Text.Pandoc.Logging (Verbosity (..))
3333import Text.Pandoc.Options
3434import Text.Pandoc.Parsing hiding (enclosed, nested)
35−import Text.Pandoc.Shared (crFilter)
35+import Text.Pandoc.Shared (crFilter, safeRead)
3636import Text.Pandoc.XML (fromEntities)
3737import Text.Printf (printf)
3838
@@ -500,9 +500,12 @@ emph = try $ fmap B.emph (enclosed (string "''") nestedInlines)
500500escapedChar :: PandocMonad m => TikiWikiParser m B.Inlines
501501escapedChar = try $ do
502502 string "~"
503− inner <- many1 $ oneOf "0123456789"
503+ mNumber <- safeRead <$> many1 digit
504504 string "~"
505− return $B.str [toEnum (read inner :: Int) :: Char]
505+ return $ B.str $
506+ case mNumber of
507+ Just number -> [toEnum (number :: Int) :: Char]
508+ Nothing -> []
506509
507510-- UNSUPPORTED, as there doesn't seem to be any facility in calibre
508511-- for this
src/Text/Pandoc/Writers/Docx.hs+5−5
@@ -234,11 +234,11 @@ writeDocx opts doc@(Pandoc meta _) = do
234234
235235 -- Get the available area (converting the size and the margins to int and
236236 -- doing the difference
237− let pgContentWidth = (-) <$> (read <$> mbAttrSzWidth ::Maybe Integer)
238− <*> (
239− (+) <$> (read <$> mbAttrMarRight ::Maybe Integer)
240− <*> (read <$> mbAttrMarLeft ::Maybe Integer)
241− )
237+ let pgContentWidth = mbAttrSzWidth >>= safeRead
238+ >>= subtrct mbAttrMarRight
239+ >>= subtrct mbAttrMarLeft
240+ where
241+ subtrct mbStr = \x -> mbStr >>= safeRead >>= (\y -> Just $ x - y)
242242
243243 -- styles
244244 mblang <- toLang $ getLang opts meta
src/Text/Pandoc/Writers/LaTeX.hs+7−5
@@ -553,16 +553,18 @@ blockToLaTeX (Div (identifier,classes,kvs) bs)
553553 else id
554554 wrapColumn = if "column" `elem` classes
555555 then \contents ->
556− let fromPct xs =
557− case reverse xs of
558− '%':ds -> showFl (read (reverse ds) / 100 :: Double)
559− _ -> xs
560− w = maybe "0.48" fromPct (lookup "width" kvs)
556+ let w = maybe "0.48" fromPct (lookup "width" kvs)
561557 in inCmd "begin" "column" <>
562558 braces (text w <> "\\textwidth")
563559 $$ contents
564560 $$ inCmd "end" "column"
565561 else id
562+ fromPct xs =
563+ case reverse xs of
564+ '%':ds -> case safeRead (reverse ds) of
565+ Just digits -> showFl (digits / 100 :: Double)
566+ Nothing -> xs
567+ _ -> xs
566568 wrapDir = case lookup "dir" kvs of
567569 Just "rtl" -> align "RTL"
568570 Just "ltr" -> align "LTR"