Skip to content

Commit

Permalink
w.i.p
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaprieto committed Oct 16, 2023
1 parent 1a82a22 commit 4dd80e7
Show file tree
Hide file tree
Showing 16 changed files with 1,216 additions and 88 deletions.
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [ ] Smoke test for
- juvix markdown file.md [FLAGS]
- Parsing
- juvix typecheck/compile file.md [FLAGS]
32 changes: 32 additions & 0 deletions app/Commands/Markdown.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Commands.Markdown where

import Commands.Base
import Commands.Markdown.Options

import Juvix.Compiler.Backend.Markdown.Data.Types


import Commonmark qualified as MK

-- import Text.Show.Pretty (ppShow, pPrint)
-- import Commonmark.Parser qualified as MK
-- import Commonmark.Types qualified as MK
-- import Data.Text qualified as T
-- import Juvix.Prelude


runCommand ::
(Members '[Embed IO, App] r) =>
MarkdownOptions
-> Sem r ()
runCommand opts = do
f <- fromAppPathFile (opts ^. markdownInputFile)
input <- liftIO $ readFile (toFilePath f)
res :: Either MK.ParseError Mk
<- MK.commonmarkWith
(MK.defaultSyntaxSpec)
(toFilePath f) input
case res of
Right (r :: Mk) ->
liftIO $ putStrLn $ MK.toPlainText r
Left _ -> error "error"
59 changes: 59 additions & 0 deletions app/Commands/Markdown/Options.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Commands.Markdown.Options where

import CommonOptions

data MarkdownOptions = MarkdownOptions
{
_markdownInputFile :: AppPath File,
_markdownOutputDir :: AppPath Dir,
_markdownUrlPrefix :: String,
_markdownIdPrefix :: String,
_markdownOnlyCheck :: Bool,
_markdownNoHtml :: Bool
}
deriving stock (Data)

makeLenses ''MarkdownOptions

parseMarkdown :: Parser MarkdownOptions
parseMarkdown = do
_markdownInputFile <- parseInputMarkdownFile
_markdownOutputDir <-
parseGenericOutputDir
( value "markdown"
<> showDefault
<> help "Markdown output directory"
<> action "directory"
)
_markdownUrlPrefix <-
strOption
( value ""
<> long "prefix-url"
<> showDefault
<> help "Prefix used for inner Juvix hyperlinks"
)
_markdownUrlPrefix <-
strOption
( value ""
<> long "prefix-id"
<> showDefault
<> help "Prefix used for HTML element IDs"
)
_markdownOnlyCheck <-
switch
( long "only-check"
<> help "Only check the input file for errors"
)
_markdownNoHtml <-
switch
( long "no-html"
<> help "Do not replace Juvix code blocks with HTML"
)
_markdownIdPrefix <-
strOption
( value ""
<> long "prefix-id"
<> showDefault
<> help "Prefix used for HTML element IDs"
)
pure MarkdownOptions {..}
14 changes: 14 additions & 0 deletions app/CommonOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ parseInputCFile = do
)
pure AppPath {_pathIsInput = True, ..}

parseInputMarkdownFile :: Parser (AppPath File)
parseInputMarkdownFile = do
_pathPath <-
argument
somePreFileOpt
( metavar "MARKDOWN_FILE"
<> help "Path to a .md file"
<> completer markdownCompleter
)
pure AppPath {_pathIsInput = True, ..}

parseGenericInputFile :: Parser (AppPath File)
parseGenericInputFile = do
_pathPath <-
Expand Down Expand Up @@ -167,6 +178,9 @@ juvixAsmCompleter = extCompleter "jva"
juvixCCompleter :: Completer
juvixCCompleter = extCompleter "c"

markdownCompleter :: Completer
markdownCompleter = extCompleter "md"

requote :: String -> String
requote s =
let -- Bash doesn't appear to allow "mixed" escaping
Expand Down
2 changes: 2 additions & 0 deletions app/TopCommand.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Commands.Eval qualified as Eval
import Commands.Format qualified as Format
import Commands.Html qualified as Html
import Commands.Init qualified as Init
import Commands.Markdown qualified as Markdown
import Commands.Repl qualified as Repl
import Commands.Typecheck qualified as Typecheck
import Juvix.Extra.Version
Expand Down Expand Up @@ -37,6 +38,7 @@ runTopCommand = \case
Clean -> runFilesIO Clean.runCommand
Eval opts -> Eval.runCommand opts
Html opts -> Html.runCommand opts
Markdown opts -> Markdown.runCommand opts
JuvixRepl opts -> Repl.runCommand opts
JuvixFormat opts -> runFilesIO (Format.runCommand opts)
Dependencies opts -> Dependencies.runCommand opts
12 changes: 11 additions & 1 deletion app/TopCommand/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Commands.Doctor.Options
import Commands.Eval.Options
import Commands.Format.Options
import Commands.Html.Options
import Commands.Markdown.Options
import Commands.Repl.Options
import Commands.Typecheck.Options
import CommonOptions hiding (Doc)
Expand All @@ -23,6 +24,7 @@ data TopCommand
| Clean
| Eval EvalOptions
| Html HtmlOptions
| Markdown MarkdownOptions
| Dev Dev.DevCommand
| Doctor DoctorOptions
| Init
Expand Down Expand Up @@ -186,6 +188,13 @@ commandHtml =
(Html <$> parseHtml)
(progDesc "Generate HTML for a Juvix file")

commandMarkdown :: Mod CommandFields TopCommand
commandMarkdown =
command "markdown" $
info
(Markdown <$> parseMarkdown)
(progDesc "Translate Juvix code blocks in a Markdown file to HTML")

commandDev :: Mod CommandFields TopCommand
commandDev =
command "dev" $
Expand All @@ -202,7 +211,8 @@ parseCompilerCommand =
commandCheck,
commandCompile,
commandEval,
commandHtml
commandHtml,
commandMarkdown
]
)

Expand Down
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ dependencies:
- language-c == 0.9.*
- libyaml == 0.1.*
- megaparsec == 9.3.*
- commonmark == 0.2.*
- parsec == 3.1.*
- microlens-platform == 0.4.*
- parser-combinators == 1.3.*
- path == 0.9.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ kindSuffix = \case
HtmlOnly -> ""

data GenSourceHtmlArgs = GenSourceHtmlArgs
{
_genSourceHtmlArgsConcreteOpts :: Options,
{ _genSourceHtmlArgsConcreteOpts :: Options,
_genSourceHtmlArgsAssetsDir :: Text,
_genSourceHtmlArgsHtmlKind :: HtmlKind,
_genSourceHtmlArgsParamBase :: Text,
Expand All @@ -58,7 +57,6 @@ data GenSourceHtmlArgs = GenSourceHtmlArgs
_genSourceHtmlArgsNoPath :: Bool,
_genSourceHtmlArgsComments :: Comments,
_genSourceHtmlArgsTheme :: Theme

}

makeLenses ''GenSourceHtmlArgs
Expand Down
Loading

0 comments on commit 4dd80e7

Please sign in to comment.