packages feed

mmark-cli 0.0.5.0 → 0.0.5.1

raw patch · 5 files changed

+258/−251 lines, 5 filesdep −unordered-containersdep ~aesondep ~basedep ~optparse-applicative

Dependencies removed: unordered-containers

Dependency ranges changed: aeson, base, optparse-applicative, text

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+## MMark CLI 0.0.5.1++* Dropped support for GHC 8.6 and older.+* Works with aeson 2.+ ## MMark CLI 0.0.5.0  * Added support for the `ghcSyntaxHighlighter` extension. Only available
LICENSE.md view
@@ -1,4 +1,4 @@-Copyright © 2018 Mark Karpov+Copyright © 2018–present Mark Karpov  All rights reserved. 
README.md view
@@ -4,7 +4,7 @@ [![Hackage](https://img.shields.io/hackage/v/mmark-cli.svg?style=flat)](https://hackage.haskell.org/package/mmark-cli) [![Stackage Nightly](http://stackage.org/package/mmark-cli/badge/nightly)](http://stackage.org/nightly/package/mmark-cli) [![Stackage LTS](http://stackage.org/package/mmark-cli/badge/lts)](http://stackage.org/lts/package/mmark-cli)-[![Build Status](https://travis-ci.org/mmark-md/mmark-cli.svg?branch=master)](https://travis-ci.org/mmark-md/mmark-cli)+![CI](https://github.com/mmark-md/mmark-cli/workflows/CI/badge.svg?branch=master)  * [Templates](#templates) * [Extensions](#extensions)@@ -106,7 +106,7 @@  * Option: `--ext-font-awesome` -This allows to turn autolinks with `fa` scheme into font awesome icons:+This allows us to turn autolinks with `fa` scheme into font awesome icons:  ``` $ mmark --ext-font-awesome@@ -200,7 +200,7 @@  * Option: `--ext-mathjax` -The extension allows to transform inline code spans into MathJax inline+The extension allows us to transform inline code spans into MathJax inline spans and code blocks with the info string `"mathjax"` (case-sensitive) into MathJax display spans. Every line in such a code block will produce a separate display span, i.e. a separate line with a formula (which is@@ -278,7 +278,7 @@ demonstrates the effect):  ```-[mark@arch ~]$ mmark --ext-punctuation+$ mmark --ext-punctuation Something---we don't know what, happened... ----------------------- Control-D <p>Something—we don’t know what, happened…</p>@@ -299,7 +299,7 @@ Example:  ````-[mark@arch ~]$ mmark --ext-skylighting+$ mmark --ext-ghc-highlighter Some Haskell:  ```haskell@@ -328,7 +328,7 @@ Example:  ````-[mark@arch ~]$ mmark --ext-skylighting+$ mmark --ext-skylighting Some Haskell:  ```haskell@@ -353,7 +353,7 @@ For example:  ````-[mark@arch ~]$ mmark --ext-toc 2-4+$ mmark --ext-toc 2-4 # Story of my life  ```toc@@ -402,6 +402,6 @@  ## License -Copyright © 2018 Mark Karpov+Copyright © 2018–present Mark Karpov  Distributed under BSD 3 clause license.
app/Main.hs view
@@ -1,41 +1,40 @@-{-# LANGUAGE CPP               #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE RecordWildCards   #-}-{-# LANGUAGE TemplateHaskell   #-}-{-# LANGUAGE TupleSections     #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TupleSections #-}  module Main (main) where  import Control.Applicative import Control.Monad-import Data.Aeson ((.=), Value (..))+import Data.Aeson (Value (..), (.=))+import qualified Data.Aeson as Aeson+import qualified Data.Aeson.KeyMap as Aeson.KeyMap+import qualified Data.ByteString.Lazy.Char8 as BL import Data.List (intercalate) import Data.Text (Text)+import qualified Data.Text as T+import qualified Data.Text.IO as T+import qualified Data.Text.Lazy as TL import Data.Version (showVersion) import Data.Void import Development.GitRev+import qualified Lucid as L import Options.Applicative hiding (ParseError) import Paths_mmark_cli (version) import System.Directory (makeAbsolute) import System.Exit (exitFailure) import Text.MMark (MMarkErr)-import Text.Megaparsec (Parsec, ParseErrorBundle (..), SourcePos (..))-import qualified Data.Aeson                  as Aeson-import qualified Data.ByteString.Lazy.Char8  as BL-import qualified Data.HashMap.Strict         as HM-import qualified Data.Text                   as T-import qualified Data.Text.IO                as T-import qualified Data.Text.Lazy              as TL-import qualified Lucid                       as L-import qualified Text.MMark                  as MMark+import qualified Text.MMark as MMark import qualified Text.MMark.Extension.Common as Ext-import qualified Text.Megaparsec             as M-import qualified Text.Megaparsec.Char        as MC-import qualified Text.Megaparsec.Char.Lexer  as MCL-import qualified Text.Mustache               as U+import Text.Megaparsec (ParseErrorBundle (..), Parsec, SourcePos (..))+import qualified Text.Megaparsec as M+import qualified Text.Megaparsec.Char as MC+import qualified Text.Megaparsec.Char.Lexer as MCL+import qualified Text.Mustache as U  -- | Entry point of the program.- main :: IO () main = do   Opts {..} <- execParser optsParserInfo@@ -52,215 +51,218 @@         else putStr (M.errorBundlePretty bundle)       exitFailure     Right doc -> do-      let exts = mconcat-            [ g optExtComment               Ext.commentParagraph-            , f optExtFontAwesome           Ext.fontAwesome-            , f optExtFootnotes             Ext.footnotes-            , f optExtKbd                   Ext.kbd-            , f optExtLinkTarget            Ext.linkTarget-            , f optExtMathJax               (Ext.mathJax (Just '$'))-            , g optExtObfuscateEmail        Ext.obfuscateEmail-            , f optExtPunctuationPrettifier Ext.punctuationPrettifier-#if __GLASGOW_HASKELL__ >= 804-            , f optExtGhcSyntaxHighlighter  Ext.ghcSyntaxHighlighter-#endif-            , f optExtSkylighting           Ext.skylighting-            , g optExtToc $ \(from,to) ->-               Ext.toc "toc" . MMark.runScanner doc . Ext.tocScanner $ \x ->-                 from <= x && x <= to-            ]+      let exts =+            mconcat+              [ g optExtComment Ext.commentParagraph,+                f optExtFontAwesome Ext.fontAwesome,+                f optExtFootnotes Ext.footnotes,+                f optExtKbd Ext.kbd,+                f optExtLinkTarget Ext.linkTarget,+                f optExtMathJax (Ext.mathJax (Just '$')),+                g optExtObfuscateEmail Ext.obfuscateEmail,+                f optExtPunctuationPrettifier Ext.punctuationPrettifier,+                f optExtGhcSyntaxHighlighter Ext.ghcSyntaxHighlighter,+                f optExtSkylighting Ext.skylighting,+                g optExtToc $ \(from, to) ->+                  Ext.toc "toc" . MMark.runScanner doc . Ext.tocScanner $ \x ->+                    from <= x && x <= to+              ]           f p x = if p then x else mempty           g p x = maybe mempty x p           applyTemplate tfile output = do             t <- U.compileMustacheFile tfile             return . TL.toStrict . U.renderMustache t $               case MMark.projectYaml doc of-                Just (Object m) -> Object $-                  HM.insert "output" (String output) m-                _ -> Aeson.object-                  [ "output" .= output-                  ]-      htmlOutput <- maybe return applyTemplate optTemplate-        . TL.toStrict-        . L.renderText-        . MMark.render-        . MMark.useExtension exts-        $ doc+                Just (Object m) ->+                  Object $+                    Aeson.KeyMap.insert "output" (String output) m+                _ ->+                  Aeson.object+                    [ "output" .= output+                    ]+      htmlOutput <-+        maybe return applyTemplate optTemplate+          . TL.toStrict+          . L.renderText+          . MMark.render+          . MMark.useExtension exts+          $ doc       if optJson-        then maybe BL.putStrLn BL.writeFile optOutputFile $-               Aeson.encode (htmlDocJson htmlOutput)+        then+          maybe BL.putStrLn BL.writeFile optOutputFile $+            Aeson.encode (htmlDocJson htmlOutput)         else maybe T.putStr T.writeFile optOutputFile htmlOutput  ---------------------------------------------------------------------------- -- Command line options parsing  -- | Command line options.- data Opts = Opts-  { optInputFile  :: !(Maybe FilePath)-    -- ^ File from which to read input (otherwise use stdin)-  , optOutputFile :: !(Maybe FilePath)-    -- ^ File to which to save output (otherwise use stdout)-  , optJson :: !Bool-    -- ^ Whether to output JSON-  , optTemplate :: !(Maybe FilePath)-    -- ^ Use the template located at this path--  , optExtComment :: !(Maybe Text)-    -- ^ Enable extension: 'Ext.commentParagraph'-  , optExtFontAwesome :: !Bool-    -- ^ Enable extension: 'Ext.fontAwesome'-  , optExtFootnotes :: !Bool-    -- ^ Enable extension: 'Ext.footnotes'-  , optExtKbd :: !Bool-    -- ^ Enable extension: 'Ext.kbd'-  , optExtLinkTarget :: !Bool-    -- ^ Enable extension: 'Ext.linkTarget'-  , optExtMathJax :: !Bool-    -- ^ Enable extension: 'Ext.mathJax'-  , optExtObfuscateEmail :: !(Maybe Text)-    -- ^ Enable extension: 'Ext.obfuscateEmail'-  , optExtPunctuationPrettifier :: !Bool-    -- ^ Enable extension: 'Ext.punctuationPrettifier'-#if __GLASGOW_HASKELL__ >= 804-  , optExtGhcSyntaxHighlighter :: !Bool-    -- ^ Enable extension: 'Ext.ghcSyntaxHighlighter'-#endif-  , optExtSkylighting :: !Bool-    -- ^ Enable extension: 'Ext.skylighting'-  , optExtToc :: !(Maybe (Int, Int))-    -- ^ Enable extension: 'Ext.toc'+  { -- | File from which to read input (otherwise use stdin)+    optInputFile :: !(Maybe FilePath),+    -- | File to which to save output (otherwise use stdout)+    optOutputFile :: !(Maybe FilePath),+    -- | Whether to output JSON+    optJson :: !Bool,+    -- | Use the template located at this path+    optTemplate :: !(Maybe FilePath),+    -- | Enable extension: 'Ext.commentParagraph'+    optExtComment :: !(Maybe Text),+    -- | Enable extension: 'Ext.fontAwesome'+    optExtFontAwesome :: !Bool,+    -- | Enable extension: 'Ext.footnotes'+    optExtFootnotes :: !Bool,+    -- | Enable extension: 'Ext.kbd'+    optExtKbd :: !Bool,+    -- | Enable extension: 'Ext.linkTarget'+    optExtLinkTarget :: !Bool,+    -- | Enable extension: 'Ext.mathJax'+    optExtMathJax :: !Bool,+    -- | Enable extension: 'Ext.obfuscateEmail'+    optExtObfuscateEmail :: !(Maybe Text),+    -- | Enable extension: 'Ext.punctuationPrettifier'+    optExtPunctuationPrettifier :: !Bool,+    -- | Enable extension: 'Ext.ghcSyntaxHighlighter'+    optExtGhcSyntaxHighlighter :: !Bool,+    -- | Enable extension: 'Ext.skylighting'+    optExtSkylighting :: !Bool,+    -- | Enable extension: 'Ext.toc'+    optExtToc :: !(Maybe (Int, Int))   }  optsParserInfo :: ParserInfo Opts-optsParserInfo = info (helper <*> ver <*> optsParser) . mconcat $-  [ fullDesc-  , progDesc "Command line interface to the MMark markdown processor"-  , header   "mmark—command line interface to the MMark markdown processor"-  ]+optsParserInfo =+  info (helper <*> ver <*> optsParser) . mconcat $+    [ fullDesc,+      progDesc "Command line interface to the MMark markdown processor",+      header "mmark—command line interface to the MMark markdown processor"+    ]   where     ver :: Parser (a -> a)-    ver = infoOption verStr . mconcat $-      [ long  "version"-      , short 'v'-      , help  "Print version of the program"-      ]-    verStr = intercalate "\n"-      [ unwords-        [ "mmark"-        , showVersion version-        , $gitBranch-        , $gitHash+    ver =+      infoOption verStr . mconcat $+        [ long "version",+          short 'v',+          help "Print version of the program"         ]-      , "using mmark     (library) " ++ VERSION_mmark-      , "using mmark-ext (library) " ++ VERSION_mmark_ext-      ]+    verStr =+      intercalate+        "\n"+        [ unwords+            [ "mmark",+              showVersion version,+              $gitBranch,+              $gitHash+            ],+          "using mmark     (library) " ++ VERSION_mmark,+          "using mmark-ext (library) " ++ VERSION_mmark_ext+        ]  optsParser :: Parser Opts-optsParser = Opts-  <$> (optional . strOption . mconcat)-    [ long    "ifile"-    , short   'i'-    , metavar "IFILE"-    , help    "Read markdown source from this file (otherwise read from stdin)"-    ]-  <*> (optional . strOption . mconcat)-    [ long    "ofile"-    , short   'o'-    , metavar "OFILE"-    , help    "Save rendered HTML document to this file (otherwise write to stdout)"-    ]-  <*> (switch . mconcat)-    [ long    "json"-    , short   'j'-    , help    "Output parse errors and result in JSON format"-    ]-  <*> (optional . strOption . mconcat)-    [ long    "template"-    , short   't'-    , metavar "FILE"-    , help    "Use the template located at this path"-    ]-  <*> (optional . fmap T.pack . strOption . mconcat)-    [ long    "ext-comment"-    , metavar "PREFIX"-    , help    "Remove paragraphs that start with the given prefix"-    ]-  <*> (switch . mconcat)-    [ long    "ext-font-awesome"-    , help    "Enable support for inserting font awesome icons"-    ]-  <*> (switch . mconcat)-    [ long    "ext-footnotes"-    , help    "Enable support for footnotes"-    ]-  <*> (switch . mconcat)-    [ long    "ext-kbd"-    , help    "Enable support for wrapping things in kbd tags"-    ]-  <*> (switch . mconcat)-    [ long    "ext-link-target"-    , help    "Enable support for specifying link targets"-    ]-  <*> (switch . mconcat)-    [ long    "ext-mathjax"-    , help    "Enable support for MathJax formulas"-    ]-  <*> (optional . fmap T.pack . strOption . mconcat)-    [ long    "ext-obfuscate-email"-    , metavar "CLASS"-    , help    "Obfuscate email addresses assigning the specified class"-    ]-  <*> (switch . mconcat)-    [ long    "ext-punctuation"-    , help    "Enable punctuation prettifier"-    ]-#if __GLASGOW_HASKELL__ >= 804-  <*> (switch . mconcat)-    [ long    "ext-ghc-highlighter"-    , help    "Enable GHC syntax highlighter for Haskell code"-    ]-#endif-  <*> (switch . mconcat)-    [ long    "ext-skylighting"-    , help    "Enable syntax highlighting of code snippets with Skylighting"-    ]-  <*> (optional . option parseRange . mconcat)-    [ long    "ext-toc"-    , metavar "RANGE"-    , help    ("Enable generation of table of contents using the supplied "-      ++       "range of headers to include, e.g. \"1-6\" or \"2-4\"")-    ]+optsParser =+  Opts+    <$> (optional . strOption . mconcat)+      [ long "ifile",+        short 'i',+        metavar "IFILE",+        help "Read markdown source from this file (otherwise read from stdin)"+      ]+    <*> (optional . strOption . mconcat)+      [ long "ofile",+        short 'o',+        metavar "OFILE",+        help "Save rendered HTML document to this file (otherwise write to stdout)"+      ]+    <*> (switch . mconcat)+      [ long "json",+        short 'j',+        help "Output parse errors and result in JSON format"+      ]+    <*> (optional . strOption . mconcat)+      [ long "template",+        short 't',+        metavar "FILE",+        help "Use the template located at this path"+      ]+    <*> (optional . fmap T.pack . strOption . mconcat)+      [ long "ext-comment",+        metavar "PREFIX",+        help "Remove paragraphs that start with the given prefix"+      ]+    <*> (switch . mconcat)+      [ long "ext-font-awesome",+        help "Enable support for inserting font awesome icons"+      ]+    <*> (switch . mconcat)+      [ long "ext-footnotes",+        help "Enable support for footnotes"+      ]+    <*> (switch . mconcat)+      [ long "ext-kbd",+        help "Enable support for wrapping things in kbd tags"+      ]+    <*> (switch . mconcat)+      [ long "ext-link-target",+        help "Enable support for specifying link targets"+      ]+    <*> (switch . mconcat)+      [ long "ext-mathjax",+        help "Enable support for MathJax formulas"+      ]+    <*> (optional . fmap T.pack . strOption . mconcat)+      [ long "ext-obfuscate-email",+        metavar "CLASS",+        help "Obfuscate email addresses assigning the specified class"+      ]+    <*> (switch . mconcat)+      [ long "ext-punctuation",+        help "Enable punctuation prettifier"+      ]+    <*> (switch . mconcat)+      [ long "ext-ghc-highlighter",+        help "Enable GHC syntax highlighter for Haskell code"+      ]+    <*> (switch . mconcat)+      [ long "ext-skylighting",+        help "Enable syntax highlighting of code snippets with Skylighting"+      ]+    <*> (optional . option parseRange . mconcat)+      [ long "ext-toc",+        metavar "RANGE",+        help+          ( "Enable generation of table of contents using the supplied "+              ++ "range of headers to include, e.g. \"1-6\" or \"2-4\""+          )+      ]  ---------------------------------------------------------------------------- -- Helpers  -- | Represent the given collection of parse errors as a 'Value'.- parseErrorsJson :: ParseErrorBundle Text MMarkErr -> Value-parseErrorsJson ParseErrorBundle {..}-  = Aeson.toJSON-  . fmap parseErrorObj-  . fst-  $ M.attachSourcePos M.errorOffset bundleErrors bundlePosState+parseErrorsJson ParseErrorBundle {..} =+  Aeson.toJSON+    . fmap parseErrorObj+    . fst+    $ M.attachSourcePos M.errorOffset bundleErrors bundlePosState   where     parseErrorObj :: (M.ParseError Text MMarkErr, SourcePos) -> Value-    parseErrorObj (err, SourcePos {..}) = Aeson.object-      [ "file"   .= sourceName-      , "line"   .= M.unPos sourceLine-      , "column" .= M.unPos sourceColumn-      , "text"   .= M.parseErrorTextPretty err-      ]+    parseErrorObj (err, SourcePos {..}) =+      Aeson.object+        [ "file" .= sourceName,+          "line" .= M.unPos sourceLine,+          "column" .= M.unPos sourceColumn,+          "text" .= M.parseErrorTextPretty err+        ]  -- | Represent the given rendered HTML document as 'Aeson.Value'.- htmlDocJson :: Text -> Value-htmlDocJson html = Aeson.object-  [ "html" .= html-  ]+htmlDocJson html =+  Aeson.object+    [ "html" .= html+    ]  -- | Parse a range as two positive numbers separated by a hyphen.- parseRange :: ReadM (Int, Int) parseRange = eitherReader $ \s ->   case M.parse p "" s of@@ -271,5 +273,5 @@     p = do       from <- MCL.decimal       void (MC.char '-')-      to   <- MCL.decimal+      to <- MCL.decimal       return (from, to)
mmark-cli.cabal view
@@ -1,54 +1,54 @@-name:                 mmark-cli-version:              0.0.5.0-cabal-version:        1.18-tested-with:          GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.2-license:              BSD3-license-file:         LICENSE.md-author:               Mark Karpov <markkarpov92@gmail.com>-maintainer:           Mark Karpov <markkarpov92@gmail.com>-homepage:             https://github.com/mmark-md/mmark-cli-bug-reports:          https://github.com/mmark-md/mmark-cli/issues-category:             Text, CLI-synopsis:             Command line interface to the MMark markdown processor-build-type:           Simple-description:          Command line interface to the MMark markdown processor.-extra-doc-files:      CHANGELOG.md-                    , README.md+cabal-version:   1.18+name:            mmark-cli+version:         0.0.5.1+license:         BSD3+license-file:    LICENSE.md+maintainer:      Mark Karpov <markkarpov92@gmail.com>+author:          Mark Karpov <markkarpov92@gmail.com>+tested-with:     ghc ==8.8.4 ghc ==8.10.5 ghc ==9.0.1+homepage:        https://github.com/mmark-md/mmark-cli+bug-reports:     https://github.com/mmark-md/mmark-cli/issues+synopsis:        Command line interface to the MMark markdown processor+description:     Command line interface to the MMark markdown processor.+category:        Text, CLI+build-type:      Simple+extra-doc-files:+    CHANGELOG.md+    README.md  source-repository head-  type:               git-  location:           https://github.com/mmark-md/mmark-cli.git+    type:     git+    location: https://github.com/mmark-md/mmark-cli.git  flag dev-  description:        Turn on development settings.-  manual:             True-  default:            False+    description: Turn on development settings.+    default:     False+    manual:      True  executable mmark-  main-is:            Main.hs-  hs-source-dirs:     app-  build-depends:      aeson            >= 0.11  && < 1.5-                    , base             >= 4.9   && < 5.0-                    , bytestring       >= 0.9.2 && < 0.11-                    , directory        >= 1.2.2 && < 1.4-                    , gitrev           >= 1.3   && < 1.4-                    , lucid            >= 2.6   && < 3.0-                    , megaparsec       >= 7.0   && < 8.0-                    , mmark            >= 0.0.6 && < 0.1-                    , mmark-ext        >= 0.2   && < 0.3-                    , optparse-applicative >= 0.14 && < 0.15-                    , stache           >= 2.0   && < 3.0-                    , text             >= 0.2   && < 1.3-                    , unordered-containers >= 0.2.5 && < 0.3-  other-modules:      Paths_mmark_cli-  if impl(ghc >= 8.4)-    build-depends:    ghc-syntax-highlighter >= 0.0.1 && < 0.1-  if flag(dev)-    ghc-options:      -Wall -Werror -Wcompat-                      -Wincomplete-record-updates-                      -Wincomplete-uni-patterns-                      -Wnoncanonical-monad-instances-                      -Wnoncanonical-monadfail-instances-  else-    ghc-options:      -O2 -Wall-  default-language:   Haskell2010+    main-is:          Main.hs+    hs-source-dirs:   app+    other-modules:    Paths_mmark_cli+    default-language: Haskell2010+    build-depends:+        aeson >=0.11 && <3,+        base >=4.13 && <5.0,+        bytestring >=0.9.2 && <0.12,+        directory >=1.2.2 && <1.4,+        ghc-syntax-highlighter >=0.0.1 && <0.1,+        gitrev >=1.3 && <1.4,+        lucid >=2.6 && <3.0,+        megaparsec >=7.0 && <10.0,+        mmark >=0.0.6 && <0.1,+        mmark-ext >=0.2 && <0.3,+        optparse-applicative >=0.14 && <0.17,+        stache >=2.0 && <3.0,+        text >=0.2 && <1.3++    if flag(dev)+        ghc-options:+            -Wall -Werror -Wcompat -Wincomplete-record-updates+            -Wincomplete-uni-patterns -Wnoncanonical-monad-instances++    else+        ghc-options: -O2 -Wall