markdown2svg 0.0.1.2 → 0.0.1.3
raw patch · 2 files changed
+31/−9 lines, 2 files
Files
- markdown2svg.cabal +2/−2
- src/markdown2svg.hs +29/−7
markdown2svg.cabal view
@@ -2,7 +2,7 @@ cabal-version: >=1.8 name: markdown2svg-version: 0.0.1.2+version: 0.0.1.3 stability: Experimental author: Yoshikuni Jujo <PAF01143@nifty.ne.jp> maintainer: Yoshikuni Jujo <PAF01143@nifty.ne.jp>@@ -31,7 +31,7 @@ source-repository this type: git location: git://github.com/YoshikuniJujo/markdown2svg.git- tag: 0.0.1.2+ tag: 0.0.1.3 executable markdown2svg hs-source-dirs: src
src/markdown2svg.hs view
@@ -1,26 +1,48 @@+import Control.Applicative import Control.Monad import System.Environment import System.FilePath+import System.Console.GetOpt+import System.Exit import Parser import SVG main :: IO () main = do- fp : as <- getArgs- let size = case as of- [s] -> read s- _ -> 0.15+ (opts, [fp], emsgs) <- getOpt Permute options <$> getArgs+ mapM_ putStrLn emsgs+ when (not $ null emsgs) exitFailure+ let size = getSizeR opts+ dir = getDir opts cnt <- readFile fp case parseMrd cnt of Just t -> forM_ (zip [1 ..] $ textToSVG True size t) $ \(i, s) ->- writeFile (mkSVGFileName fp i) s+ writeFile (mkSVGFileName dir fp i) s _ -> return () -mkSVGFileName :: FilePath -> Int -> FilePath-mkSVGFileName fp i = (dropExtension fp ++ show2 i) <.> "svg"+mkSVGFileName :: Maybe FilePath -> FilePath -> Int -> FilePath+mkSVGFileName (Just dir) fp i = dir </> (takeBaseName fp ++ show2 i) <.> "svg"+mkSVGFileName _ fp i = (dropExtension fp ++ show2 i) <.> "svg" show2 :: Show a => a -> String show2 x = replicate (2 - length s) '0' ++ s where s = show x++data Option = Dir FilePath | Size Double deriving Show++options :: [OptDescr Option]+options = [+ Option "d" [] (ReqArg Dir "output directory") "set ouput directory",+ Option "s" [] (ReqArg (Size . read) "size ratio") "set size ratio" ]++getDir :: [Option] -> Maybe FilePath+getDir [] = Nothing+getDir (Dir d : _) = Just d+getDir (_ : ops) = getDir ops++getSizeR :: [Option] -> Double+getSizeR [] = 0.15+getSizeR (Size sr : _) = sr+getSizeR (_ : ops) = getSizeR ops