wordchoice 0.1.2.0 → 0.1.2.1
raw patch · 5 files changed
+26/−52 lines, 5 filesdep ~basedep ~pandoc
Dependency ranges changed: base, pandoc
Files
- default.nix +0/−20
- release.nix +0/−5
- src/Data/Text/WordCount/FileRead.hs +22/−22
- stack.yaml +3/−2
- wordchoice.cabal +1/−3
− default.nix
@@ -1,20 +0,0 @@-{ mkDerivation, base, bytestring, Chart, Chart-diagrams, containers-, Glob, lens, optparse-applicative, pandoc, stdenv, system-filepath-, text-}:-mkDerivation {- pname = "wordchoice";- version = "0.1.0.5";- src = ./.;- isLibrary = true;- isExecutable = true;- libraryHaskellDepends = [- base bytestring Chart Chart-diagrams containers Glob lens- optparse-applicative pandoc system-filepath text- ];- executableHaskellDepends = [ base ];- testHaskellDepends = [ base ];- homepage = "https://github.com/githubuser/wordchoice#readme";- description = "Get word counts and distributions";- license = stdenv.lib.licenses.bsd3;-}
− release.nix
@@ -1,5 +0,0 @@-let- pkgs = import <nixpkgs> { };--in- pkgs.haskell.lib.justStaticExecutables (pkgs.haskellPackages.callPackage ./default.nix { })
src/Data/Text/WordCount/FileRead.hs view
@@ -1,35 +1,35 @@ -- | Module with function to read file in with pandoc and discard everything superfluous. module Data.Text.WordCount.FileRead where -import Text.Pandoc-import Filesystem.Path.CurrentOS as F-import qualified Data.Text as T-import qualified Data.Text.IO as TIO-import qualified Data.ByteString.Lazy as BSL-import System.FilePath.Glob--eitherError = either (error . show) id+import Control.Monad ((<=<))+import Control.Monad.IO.Class (liftIO)+import qualified Data.ByteString.Lazy as BSL+import qualified Data.Text as T+import qualified Data.Text.IO as TIO+import Filesystem.Path.CurrentOS as F+import System.FilePath.Glob+import Text.Pandoc hiding (glob) -- | Process files given a filename glob globFile :: String -> IO T.Text globFile str = do files <- glob str- fmap T.concat . sequence $ fmap processFile files+ fmap T.concat . sequence $ fmap runIOorExplode $ fmap processFile files -- | Process a file given a filename. Return text only, discarding superflouous material.-processFile :: String -> IO T.Text-processFile filepath = T.filter goodChar <$> case (extension . decodeString $ filepath) of- (Just "md") -> T.pack . writePlain def . filterCode . eitherError . readMarkdown def . T.unpack <$> TIO.readFile filepath- (Just "dbk") -> T.pack . writePlain def . filterCode . eitherError . readDocBook def . T.unpack <$> TIO.readFile filepath- (Just "docx") -> T.pack . writePlain def . filterCode . fst . eitherError . readDocx def <$> BSL.readFile filepath- (Just "epub") -> T.pack . writePlain def . filterCode . fst . eitherError . readEPUB def <$> BSL.readFile filepath- (Just "html") -> T.pack . writePlain def . filterCode . eitherError . readHtml def . T.unpack <$> TIO.readFile filepath- (Just "tex") -> T.pack . writePlain def . filterCode . eitherError . readLaTeX def . T.unpack <$> TIO.readFile filepath- (Just "xml") -> T.pack . writePlain def . filterCode . eitherError . readOPML def . T.unpack <$> TIO.readFile filepath- (Just "odt") -> T.pack . writePlain def . filterCode . fst . eitherError . readOdt def <$> BSL.readFile filepath- (Just "rst") -> T.pack . writePlain def . filterCode . eitherError . readRST def . T.unpack <$> TIO.readFile filepath- (Just "textile") -> T.pack . writePlain def . filterCode . eitherError . readTextile def . T.unpack <$> TIO.readFile filepath- _ -> TIO.readFile filepath+processFile :: String -> PandocIO T.Text+processFile filepath = (T.filter goodChar) <$> case (extension . decodeString $ filepath) of+ (Just "md") -> (writePlain def <=< fmap filterCode . (readMarkdown def =<<)) <$> liftIO $ TIO.readFile filepath+ (Just "dbk") -> (writePlain def <=< fmap filterCode . (readDocBook def =<<)) <$> liftIO $ TIO.readFile filepath+ (Just "docx") -> (writePlain def <=< fmap filterCode . (readDocx def =<<)) $ liftIO $ BSL.readFile filepath+ (Just "epub") -> (writePlain def <=< fmap filterCode . (readEPUB def =<<)) $ liftIO $ BSL.readFile filepath+ (Just "html") -> (writePlain def <=< fmap filterCode . (readHtml def =<<)) $ liftIO $ TIO.readFile filepath+ (Just "tex") -> (writePlain def <=< fmap filterCode . (readLaTeX def =<<)) $ liftIO $ TIO.readFile filepath+ (Just "xml") -> (writePlain def <=< fmap filterCode . (readOPML def =<<)) $ liftIO $ TIO.readFile filepath+ (Just "odt") -> (writePlain def <=< fmap filterCode . (readOdt def =<<)) $ liftIO $ BSL.readFile filepath+ (Just "rst") -> (writePlain def <=< fmap filterCode . (readRST def =<<)) $ liftIO $ TIO.readFile filepath+ (Just "textile") -> (writePlain def <=< fmap filterCode . (readTextile def =<<)) $ liftIO $ TIO.readFile filepath+ _ -> liftIO $ TIO.readFile filepath goodChar :: Char -> Bool goodChar = not . flip any (".,?_()![]{}*&$#" :: String) . (==)
stack.yaml view
@@ -1,7 +1,8 @@-resolver: lts-8.23+resolver: lts-9.10 packages: - '.'-extra-deps: []+extra-deps:+- composition-prelude-0.1.1.0 flags: wordchoice: llvm-fast: true
wordchoice.cabal view
@@ -1,5 +1,5 @@ name: wordchoice-version: 0.1.2.0+version: 0.1.2.1 synopsis: Get word counts and distributions description: A command line tool to compute the word distribution from various types of document, converting to text with pandoc. homepage: https://github.com/githubuser/wordchoice#readme@@ -13,8 +13,6 @@ extra-source-files: README.md , stack.yaml , cabal.project.local- , default.nix- , release.nix cabal-version: >=1.10 Flag llvm-fast {