summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Highlighting.hs7
-rw-r--r--src/Text/Pandoc/Readers/Native.hs31
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs6
3 files changed, 23 insertions, 21 deletions
diff --git a/src/Text/Pandoc/Highlighting.hs b/src/Text/Pandoc/Highlighting.hs
index 080acebee..95df88099 100644
--- a/src/Text/Pandoc/Highlighting.hs
+++ b/src/Text/Pandoc/Highlighting.hs
@@ -47,6 +47,7 @@ module Text.Pandoc.Highlighting ( languages
, Style
) where
import Text.Pandoc.Definition
+import Text.Pandoc.Shared (safeRead)
import Text.Highlighting.Kate
import Data.List (find)
import Data.Maybe (fromMaybe)
@@ -60,9 +61,9 @@ highlight :: (FormatOptions -> [SourceLine] -> a) -- ^ Formatter
-> String -- ^ Raw contents of the CodeBlock
-> Maybe a -- ^ Maybe the formatted result
highlight formatter (_, classes, keyvals) rawCode =
- let firstNum = case reads (fromMaybe "1" $ lookup "startFrom" keyvals) of
- ((n,_):_) -> n
- [] -> 1
+ let firstNum = case safeRead (fromMaybe "1" $ lookup "startFrom" keyvals) of
+ Just n -> n
+ Nothing -> 1
fmtOpts = defaultFormatOpts{
startNumber = firstNum,
numberLines = any (`elem`
diff --git a/src/Text/Pandoc/Readers/Native.hs b/src/Text/Pandoc/Readers/Native.hs
index 410c44a37..a0e5a0635 100644
--- a/src/Text/Pandoc/Readers/Native.hs
+++ b/src/Text/Pandoc/Readers/Native.hs
@@ -31,6 +31,7 @@ Conversion of a string representation of a pandoc type (@Pandoc@,
module Text.Pandoc.Readers.Native ( readNative ) where
import Text.Pandoc.Definition
+import Text.Pandoc.Shared (safeRead)
nullMeta :: Meta
nullMeta = Meta{ docTitle = []
@@ -51,31 +52,31 @@ nullMeta = Meta{ docTitle = []
readNative :: String -- ^ String to parse (assuming @'\n'@ line endings)
-> Pandoc
readNative s =
- case reads s of
- (d,_):_ -> d
- [] -> Pandoc nullMeta $ readBlocks s
+ case safeRead s of
+ Just d -> d
+ Nothing -> Pandoc nullMeta $ readBlocks s
readBlocks :: String -> [Block]
readBlocks s =
- case reads s of
- (d,_):_ -> d
- [] -> [readBlock s]
+ case safeRead s of
+ Just d -> d
+ Nothing -> [readBlock s]
readBlock :: String -> Block
readBlock s =
- case reads s of
- (d,_):_ -> d
- [] -> Plain $ readInlines s
+ case safeRead s of
+ Just d -> d
+ Nothing -> Plain $ readInlines s
readInlines :: String -> [Inline]
readInlines s =
- case reads s of
- (d,_):_ -> d
- [] -> [readInline s]
+ case safeRead s of
+ Just d -> d
+ Nothing -> [readInline s]
readInline :: String -> Inline
readInline s =
- case reads s of
- (d,_):_ -> d
- [] -> error "Cannot parse document"
+ case safeRead s of
+ Just d -> d
+ Nothing -> error "Cannot parse document"
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 9a6f9670f..1a2764cb6 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -309,9 +309,9 @@ ppTopElement = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ++) . unEntity .
unEntity ('&':'#':xs) =
let (ds,ys) = break (==';') xs
rest = drop 1 ys
- in case reads ('\'':'\\':ds ++ "'") of
- ((x,_):_) -> x : unEntity rest
- _ -> '&':'#':unEntity xs
+ in case safeRead ('\'':'\\':ds ++ "'") of
+ Just x -> x : unEntity rest
+ Nothing -> '&':'#':unEntity xs
unEntity (x:xs) = x : unEntity xs
imageTypeOf :: FilePath -> Maybe String