diff options
| author | despresc <[email protected]> | 2019-11-09 14:20:08 -0500 |
|---|---|---|
| committer | despresc <[email protected]> | 2019-11-09 14:20:08 -0500 |
| commit | bca7292ec09f46d82fb654e43fd8b263054a92ac (patch) | |
| tree | 768ab6db34b0d35b413d0e064f47403d1d4537e3 | |
| parent | 536fa204c32fd72ef0e656ba3bce036bb946360e (diff) | |
Switch benchmark to Text, avoid incomplete pattern match warnings in Writers
| -rw-r--r-- | benchmark/benchmark-pandoc.hs | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Ms.hs | 19 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Muse.hs | 12 |
3 files changed, 19 insertions, 16 deletions
diff --git a/benchmark/benchmark-pandoc.hs b/benchmark/benchmark-pandoc.hs index e99032872..7e4576632 100644 --- a/benchmark/benchmark-pandoc.hs +++ b/benchmark/benchmark-pandoc.hs @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import Prelude import Text.Pandoc import Text.Pandoc.MIME --- import Text.Pandoc.Error (PandocError(..)) TODO text: restore +import Text.Pandoc.Error (PandocError(..)) import Control.Monad.Except (throwError) import qualified Text.Pandoc.UTF8 as UTF8 import qualified Data.ByteString as B @@ -53,7 +53,7 @@ readerBench doc name = _ -> throwError $ PandocSomeError $ "not a text format: " ++ name -getImages :: IO [(FilePath, String, BL.ByteString)] -- TODO text: replace String with MimeType +getImages :: IO [(FilePath, MimeType, BL.ByteString)] -- TODO text: replace String with MimeType getImages = do ll <- BL.readFile "test/lalune.jpg" mv <- BL.readFile "test/movie.jpg" diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs index 219e8232c..7e0a58134 100644 --- a/src/Text/Pandoc/Writers/Ms.hs +++ b/src/Text/Pandoc/Writers/Ms.hs @@ -94,15 +94,16 @@ escapeStr opts = escapeUri :: Text -> Text escapeUri = T.pack . escapeURIString (\c -> c /= '@' && isAllowedInURI c) . T.unpack -toSmallCaps :: WriterOptions -> Text -> Text -- TODO text: refactor -toSmallCaps _ "" = "" -toSmallCaps opts s@(T.uncons -> Just (c,cs)) - | isLower c = let (lowers,rest) = T.span isLower s - in "\\s-2" <> escapeStr opts (T.toUpper lowers) <> - "\\s0" <> toSmallCaps opts rest - | isUpper c = let (uppers,rest) = T.span isUpper s - in escapeStr opts uppers <> toSmallCaps opts rest - | otherwise = escapeStr opts (T.singleton c) <> toSmallCaps opts cs +toSmallCaps :: WriterOptions -> Text -> Text +toSmallCaps opts s = case T.uncons s of + Nothing -> "" + Just (c, cs) + | isLower c -> let (lowers,rest) = T.span isLower s + in "\\s-2" <> escapeStr opts (T.toUpper lowers) <> + "\\s0" <> toSmallCaps opts rest + | isUpper c -> let (uppers,rest) = T.span isUpper s + in escapeStr opts uppers <> toSmallCaps opts rest + | otherwise -> escapeStr opts (T.singleton c) <> toSmallCaps opts cs -- We split inline lists into sentences, and print one sentence per -- line. roff treats the line-ending period differently. diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index 9e70fccf8..5b5566bfc 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -468,10 +468,10 @@ startsWithSpace (SoftBreak:_) = True startsWithSpace (Str s:_) = stringStartsWithSpace s startsWithSpace _ = False -endsWithSpace :: [Inline] -> Bool -- TODO text: refactor +endsWithSpace :: [Inline] -> Bool endsWithSpace [Space] = True endsWithSpace [SoftBreak] = True -endsWithSpace [Str s] = stringStartsWithSpace $ T.reverse s +endsWithSpace [Str s] = stringEndsWithSpace s endsWithSpace (_:xs) = endsWithSpace xs endsWithSpace [] = False @@ -486,9 +486,11 @@ urlEscapeBrackets' [] = [] isHorizontalRule :: Text -> Bool isHorizontalRule s = T.length s >= 4 && T.all (== '-') s -stringStartsWithSpace :: Text -> Bool -- TODO text: refactor -stringStartsWithSpace (T.uncons -> Just (x,_)) = isSpace x -stringStartsWithSpace "" = False +stringStartsWithSpace :: Text -> Bool +stringStartsWithSpace = maybe False (isSpace . fst) . T.uncons + +stringEndsWithSpace :: Text -> Bool +stringEndsWithSpace = maybe False (isSpace . snd) . T.unsnoc -- TODO text: refactor, exists for fixOrEscape fixOrEscapeStr :: Bool -> String -> Bool |
