git.iko.soy/typeable/pandoc
on master help sign in
Docx Reader: Clean up guards
ab76bbeJesse Rosenthal
src/Text/Pandoc/Readers/Docx.hs+9−9
@@ -1,3 +1,5 @@
1+{-# LANGUAGE PatternGuards #-}
2+
1{-
3{-
2Copyright (C) 2014 Jesse Rosenthal <jrosenthal@jhu.edu>
4Copyright (C) 2014 Jesse Rosenthal <jrosenthal@jhu.edu>
3
5
@@ -82,7 +84,7 @@ import Text.Pandoc.Walk
82import Text.Pandoc.Readers.Docx.Parse
84import Text.Pandoc.Readers.Docx.Parse
83import Text.Pandoc.Readers.Docx.Lists
85import Text.Pandoc.Readers.Docx.Lists
84import Text.Pandoc.Readers.Docx.Reducible
86import Text.Pandoc.Readers.Docx.Reducible
85−import Data.Maybe (mapMaybe, isJust, fromJust)
87+import Data.Maybe (mapMaybe)
86import Data.List (delete, isPrefixOf, (\\))
88import Data.List (delete, isPrefixOf, (\\))
87import qualified Data.ByteString as BS
89import qualified Data.ByteString as BS
88import qualified Data.ByteString.Lazy as B
90import qualified Data.ByteString.Lazy as B
@@ -148,12 +150,10 @@ runStyleToContainers rPr =
148
150
149
151
150divAttrToContainers :: [String] -> [(String, String)] -> [Container Block]
152divAttrToContainers :: [String] -> [(String, String)] -> [Container Block]
151−divAttrToContainers (c:cs) _ | isJust (isHeaderClass c) =
153+divAttrToContainers (c:cs) _ | Just n <- isHeaderClass c =
152− let n = fromJust (isHeaderClass c)
153− in
154− [(Container $ \blks ->
154+ [(Container $ \blks ->
155− makeHeaderAnchor $
155+ makeHeaderAnchor $
156− Header n ("", delete ("Heading" ++ show n) cs, []) (blksToInlines blks))]
156+ Header n ("", delete ("Heading" ++ show n) cs, []) (blksToInlines blks))]
157divAttrToContainers (c:cs) kvs | c `elem` divsToKeep =
157divAttrToContainers (c:cs) kvs | c `elem` divsToKeep =
158 (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs)
158 (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs)
159divAttrToContainers (c:cs) kvs | c `elem` codeDivs =
159divAttrToContainers (c:cs) kvs | c `elem` codeDivs =
@@ -167,10 +167,10 @@ divAttrToContainers (c:cs) kvs | c `elem` listParagraphDivs =
167divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
167divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
168 (Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
168 (Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
169divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
169divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
170−divAttrToContainers [] kvs | isJust (lookup "indent" kvs) =
170+divAttrToContainers [] kvs | Just numString <- lookup "indent" kvs =
171 let kvs' = filter (\(k,_) -> k /= "indent") kvs
171 let kvs' = filter (\(k,_) -> k /= "indent") kvs
172 in
172 in
173− case fromJust (lookup "indent" kvs) of
173+ case numString of
174 "0" -> divAttrToContainers [] kvs'
174 "0" -> divAttrToContainers [] kvs'
175 ('-' : _) -> divAttrToContainers [] kvs'
175 ('-' : _) -> divAttrToContainers [] kvs'
176 _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
176 _ -> (Container BlockQuote) : divAttrToContainers [] kvs'