1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 18:13:56 +03:00
juvix/app/TopCommand.hs
Jonathan Cubides bd16d3ef2a
Add support for Literate Juvix Markdown (#2448)
This PR adds an initial support for Literate Juvix Markdown files, files
with the extension `.juvix.md`.

Here is a small example of such a file: `Test.juvix.md`.

<pre>
# This is a heading
Lorem ...

```juvix
module Test;

type A := a;

fun : A -> A 
 | _ := a;
```
Other text
</pre>


This initial support enables users to execute common commands such as
typechecking, compilation, and HTML generation. Additionally, a new
command called `markdown` has been introduced. This command replaces
code blocks marked with the juvix attribute with their respective HTML
output, much like the output we obtain when running `juvix html`. In
this version, comments are ignored in the output, including judoc
blocks.

- We intend to use this new feature in combination with this Python
plugin (https://github.com/anoma/juvix-mkdocs) to enhance our
documentation site.



https://github.com/anoma/juvix/assets/1428088/a0c17f36-3d76-42cc-a571-91f885866874


## Future work

Open as issues once this PR is merged, we can work on the following:

- Support imports of Juvix Markdown modules (update the path resolver to
support imports of Literate Markdown files)
- Support (Judoc) comments in md Juvix blocks
- Support Markdown in Judoc blocks
- Update Text editor support, vscode extension and emacs mode (the
highlighting info is a few characters off in the current state)



- Closes #1839 
- Closes #1719
2023-11-10 13:55:36 +01:00

45 lines
1.6 KiB
Haskell

module TopCommand where
import Commands.Base hiding (Format)
import Commands.Clean qualified as Clean
import Commands.Compile qualified as Compile
import Commands.Dependencies qualified as Dependencies
import Commands.Dev qualified as Dev
import Commands.Doctor qualified as Doctor
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
import System.Environment (getProgName)
import TopCommand.Options
showHelpText :: IO ()
showHelpText = do
let p = prefs showHelpOnEmpty
progn <- getProgName
let helpText = parserFailure p descr (ShowHelpText Nothing) []
(msg, _) = renderFailure helpText progn
putStrLn (pack msg)
runTopCommand :: forall r. (Members '[Embed IO, App, Resource] r) => TopCommand -> Sem r ()
runTopCommand = \case
DisplayVersion -> embed runDisplayVersion
DisplayNumericVersion -> embed runDisplayNumericVersion
DisplayHelp -> embed showHelpText
Doctor opts -> runLogIO (Doctor.runCommand opts)
Init opts -> runLogIO (Init.init opts)
Dev opts -> Dev.runCommand opts
Typecheck opts -> Typecheck.runCommand opts
Compile opts -> Compile.runCommand opts
Clean opts -> runFilesIO (Clean.runCommand opts)
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