comark (empty) → 0.1.0
raw patch · 5 files changed
+187/−0 lines, 5 filesdep +basedep +comarkdep +comark-htmlsetup-changed
Dependencies added: base, comark, comark-html, comark-parser, comark-syntax, text
Files
- LICENSE +30/−0
- Main.hs +81/−0
- Setup.hs +2/−0
- comark.cabal +43/−0
- src/Comark.hs +31/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, 2016, 2017 Konstantin Zudov++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Konstantin Zudov nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Main.hs view
@@ -0,0 +1,81 @@+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE RecordWildCards #-}+module Main where++import Control.Monad (forM_, (<=<))+import Data.Monoid ((<>))+import Data.Text (Text)+import qualified Data.Text as Text+import qualified Data.Text.IO as Text++import System.Environment+import System.Exit+import System.IO++import qualified Comark++main :: IO ()+main = do+ eOpts <- parseArgs <$> getArgs+ case eOpts of+ Left err -> do+ hPutStrLn stderr err+ exitFailure+ Right opts@Options{inputFiles = [] } ->+ Text.interact (processor opts)+ Right opts@Options{inputFiles = files } ->+ forM_ files $+ Text.putStrLn . processor opts <=< Text.readFile++processor :: Options -> Text -> Text+processor Options{..} = render . Comark.parse [ Comark.Normalize | normalize ]+ where+ render =+ case outputFormat of+ Native -> Text.pack . show+ Html -> Comark.render++data Options = Options+ { outputFormat :: Format+ , normalize :: Bool+ , inputFiles :: [FilePath]+ }+ deriving (Show)++initOpts :: Options+initOpts = Options+ { outputFormat = Html+ , normalize = False+ , inputFiles = mempty+ }++usage :: String+usage = unlines+ [ "Usage: comark-hs [OPTIONS*] [FILE*]"+ , "Options:"+ , " --to, -t FORMAT Specify output format (html, native)"+ , " --normalize Consolidate adjacent text nodes"+ , " --help, -h Print usage information"+ ]++parseArgs :: [String] -> Either String Options+parseArgs = parse initOpts+ where+ parse opts = \case+ [] -> Right opts+ ("-t":[]) -> Left "No argument provided for -t"+ (arg:format:args) | arg == "-t" || arg == "--to"+ -> readFormat format >>= \f -> parse opts { outputFormat = f } args+ ("--normalize":args) -> parse opts { normalize = True } args+ ("--":files) -> Right opts { inputFiles = files <> inputFiles opts }+ (('-':_):_) -> Left usage+ files -> Right opts { inputFiles = files <> inputFiles opts }+++data Format = Native | Html deriving (Show)++readFormat :: String -> Either String Format+readFormat "html" = Right Html+readFormat "native" = Right Native+readFormat format = Left $ "Unknown format " <> format+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ comark.cabal view
@@ -0,0 +1,43 @@+-- This file has been generated from package.yaml by hpack version 0.17.0.+--+-- see: https://github.com/sol/hpack++name: comark+version: 0.1.0+synopsis: Commonmark processing in pure haskell.+description: See <https://github.com/zudov/haskell-comark#readme README>+license: BSD3+license-file: LICENSE+author: Konstantin Zudov+maintainer: co@zudov.me+copyright: (c) Konstantin Zudov, 2015, 2016, 2017+category: Text+build-type: Simple+cabal-version: >= 1.10++library+ exposed-modules:+ Comark+ other-modules:+ Paths_comark+ hs-source-dirs:+ src+ build-depends:+ base >=4.7 && <5+ , text+ , comark-syntax+ , comark-parser+ , comark-html+ default-language: Haskell2010+ ghc-options: -Wall++executable comark-hs+ main-is: Main.hs+ hs-source-dirs:+ ./.+ ghc-options: -Wall -threaded+ build-depends:+ base >=4.7 && <5+ , text+ , comark+ default-language: Haskell2010
+ src/Comark.hs view
@@ -0,0 +1,31 @@+-- | It mostly contains reexports from the following modules:+--+-- - "Comark.Syntax"+-- - "Comark.Parser"+-- - "Comark.Parser.Options"+-- - "Comark.Html"++module Comark+ ( -- * Parser+ parse+ , ParserOption(..)+ -- * HTML Rendererer+ , render+ -- * AST types+ -- ** Document+ , Doc(..)+ -- *** Blocks+ , Blocks+ , Block(..)+ , HeadingLevel(..)+ , ListType(..)+ , Delimiter(..)+ , BulletMarker(..)+ -- * Inlines+ , Inlines+ , Inline(..)+ ) where++import Comark.Html+import Comark.Parser+import Comark.Syntax