commonmark-cli 0.2 → 0.2.1
raw patch · 3 files changed
+34/−18 lines, 3 filesdep ~commonmarkdep ~commonmark-extensionsdep ~commonmark-pandoc
Dependency ranges changed: commonmark, commonmark-extensions, commonmark-pandoc
Files
- changelog.md +8/−0
- commonmark-cli.cabal +4/−4
- src/convert.hs +22/−14
changelog.md view
@@ -1,5 +1,13 @@ # Changelog for commonmark-cli +## 0.2.1++ * Add `alerts` as extension (#132).++ * Fix bug in change to JSON handling.++ * Allow `--json` and `--sourcepos` to be used together.+ ## 0.2 * Support `rebase_relative_paths` extension.
commonmark-cli.cabal view
@@ -1,5 +1,5 @@ name: commonmark-cli-version: 0.2+version: 0.2.1 synopsis: Command-line commonmark converter and highlighter. description: This package provides a command-line tool, `commonmark`, for converting and syntax-highlighting commonmark documents.@@ -31,9 +31,9 @@ ghc-options: -Wunused-packages ghc-options: -threaded -rtsopts build-depends: base >= 4.9 && <5- , commonmark >= 0.2 && < 0.3- , commonmark-extensions >= 0.2.1 && < 0.3- , commonmark-pandoc >= 0.2.1 && < 0.3+ , commonmark >= 0.2.4.1 && < 0.3+ , commonmark-extensions >= 0.2.5 && < 0.3+ , commonmark-pandoc >= 0.2.2 && < 0.3 , pandoc-types , aeson , bytestring
src/convert.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -26,9 +25,6 @@ import System.Console.GetOpt import Paths_commonmark_cli (version) import Data.Version (showVersion)-#if !MIN_VERSION_base(4,11,0)-import Data.Monoid-#endif import Control.Exception (AsyncException, catch, throwIO) import GHC.Stack (currentCallStack) import System.Console.ANSI@@ -87,25 +83,33 @@ runIdentity (parseCommonmarkWith spec toks) of Left e -> errExit e Right (_ :: Html (), sm) -> highlightWith sm toks- else- if SourcePos `elem` opts then do- spec <- specFromExtensionNames [x | Extension x <- opts]- case runIdentity (parseCommonmarkWith spec toks) of- Left e -> errExit e- Right (r :: Html SourceRange)- -> TLIO.putStr . renderHtml $ r- else- if PandocJSON `elem` opts then do+ else do+ let sourcepos = SourcePos `elem` opts+ let json = PandocJSON `elem` opts+ case (json, sourcepos) of+ (True, True) -> do spec <- specFromExtensionNames [x | Extension x <- opts] case runIdentity (parseCommonmarkWith spec toks) of Left e -> errExit e+ Right (r :: Cm SourceRange B.Blocks) -> do+ BL.putStr . encode $ B.doc $ unCm r+ BL.putStr "\n"+ (True, False) -> do+ spec <- specFromExtensionNames [x | Extension x <- opts]+ case runIdentity (parseCommonmarkWith spec toks) of+ Left e -> errExit e Right (r :: Cm () B.Blocks) -> do BL.putStr . encode $ B.doc $ unCm r BL.putStr "\n"- else do+ (False, True) -> do spec <- specFromExtensionNames [x | Extension x <- opts] case runIdentity (parseCommonmarkWith spec toks) of Left e -> errExit e+ Right (r :: Html SourceRange) -> TLIO.putStr . renderHtml $ r+ (False, False) -> do+ spec <- specFromExtensionNames [x | Extension x <- opts]+ case runIdentity (parseCommonmarkWith spec toks) of+ Left e -> errExit e Right (r :: Html ()) -> TLIO.putStr . renderHtml $ r) (\(e :: AsyncException) -> do currentCallStack >>= mapM_ (hPutStrLn stderr)@@ -133,6 +137,7 @@ HasDefinitionList il bl, HasDiv bl, HasTaskList il bl,+ HasAlerts il bl, HasFootnote il bl) => [(String, SyntaxSpec m il bl)] extensions =@@ -159,6 +164,7 @@ ,("wikilinks_title_before_pipe", wikilinksSpec TitleBeforePipe) ,("wikilinks_title_after_pipe", wikilinksSpec TitleAfterPipe) ,("rebase_relative_paths", rebaseRelativePathsSpec)+ ,("alerts", alertSpec) ,("gfm", gfmExtensions) ] @@ -182,7 +188,9 @@ HasSubscript il, HasDefinitionList il bl, HasDiv bl,+ HasAlerts il bl, HasTaskList il bl,+ HasAlerts il bl, HasFootnote il bl) => [String] -> IO (SyntaxSpec m il bl) specFromExtensionNames extnames = do