git.iko.soy/typeable/pandoc
on master help sign in
Replace read with safeRead (#5186)
c8b79b0Mauro Bieg
src/Text/Pandoc/Readers/TikiWiki.hs+6−3
@@ -32,7 +32,7 @@ import Text.Pandoc.Definition
32import Text.Pandoc.Logging (Verbosity (..))
32import Text.Pandoc.Logging (Verbosity (..))
33import Text.Pandoc.Options
33import Text.Pandoc.Options
34import Text.Pandoc.Parsing hiding (enclosed, nested)
34import Text.Pandoc.Parsing hiding (enclosed, nested)
35−import Text.Pandoc.Shared (crFilter)
35+import Text.Pandoc.Shared (crFilter, safeRead)
36import Text.Pandoc.XML (fromEntities)
36import Text.Pandoc.XML (fromEntities)
37import Text.Printf (printf)
37import Text.Printf (printf)
38
38
@@ -500,9 +500,12 @@ emph = try $ fmap B.emph (enclosed (string "''") nestedInlines)
500escapedChar :: PandocMonad m => TikiWikiParser m B.Inlines
500escapedChar :: PandocMonad m => TikiWikiParser m B.Inlines
501escapedChar = try $ do
501escapedChar = try $ do
502 string "~"
502 string "~"
503− inner <- many1 $ oneOf "0123456789"
503+ mNumber <- safeRead <$> many1 digit
504 string "~"
504 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 -> []
506
509
507-- UNSUPPORTED, as there doesn't seem to be any facility in calibre
510-- UNSUPPORTED, as there doesn't seem to be any facility in calibre
508-- for this
511-- for this
src/Text/Pandoc/Writers/Docx.hs+5−5
@@ -234,11 +234,11 @@ writeDocx opts doc@(Pandoc meta _) = do
234
234
235 -- Get the available area (converting the size and the margins to int and
235 -- Get the available area (converting the size and the margins to int and
236 -- doing the difference
236 -- doing the difference
237− let pgContentWidth = (-) <$> (read <$> mbAttrSzWidth ::Maybe Integer)
237+ let pgContentWidth = mbAttrSzWidth >>= safeRead
238− <*> (
239− (+) <$> (read <$> mbAttrMarRight ::Maybe Integer)
238+ >>= subtrct mbAttrMarRight
240− <*> (read <$> mbAttrMarLeft ::Maybe Integer)
239+ >>= subtrct mbAttrMarLeft
241− )
240+ where
241+ subtrct mbStr = \x -> mbStr >>= safeRead >>= (\y -> Just $ x - y)
242
242
243 -- styles
243 -- styles
244 mblang <- toLang $ getLang opts meta
244 mblang <- toLang $ getLang opts meta
src/Text/Pandoc/Writers/LaTeX.hs+7−5
@@ -553,16 +553,18 @@ blockToLaTeX (Div (identifier,classes,kvs) bs)
553 else id
553 else id
554 wrapColumn = if "column" `elem` classes
554 wrapColumn = if "column" `elem` classes
555 then \contents ->
555 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)
561 in inCmd "begin" "column" <>
557 in inCmd "begin" "column" <>
562 braces (text w <> "\\textwidth")
558 braces (text w <> "\\textwidth")
563 $$ contents
559 $$ contents
564 $$ inCmd "end" "column"
560 $$ inCmd "end" "column"
565 else id
561 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
566 wrapDir = case lookup "dir" kvs of
568 wrapDir = case lookup "dir" kvs of
567 Just "rtl" -> align "RTL"
569 Just "rtl" -> align "RTL"
568 Just "ltr" -> align "LTR"
570 Just "ltr" -> align "LTR"