Skip to content

Commit

Permalink
Added CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
nricciardi committed Sep 1, 2024
1 parent f0a988a commit 3afafd0
Show file tree
Hide file tree
Showing 48 changed files with 3,465 additions and 69 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: NMD Cargo Build & Test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Cargo.lock
perf.data
perf.data.old
flamegraph.svg
profile.json
./profile.json
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"./Cargo.toml",
"./Cargo.toml"
],
"rust-analyzer.showUnlinkedFileNotification": false
"rust-analyzer.showUnlinkedFileNotification": false,
"cSpell.words": [
"nuid"
]
}
43 changes: 43 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "nmd"
version = "1.3.0"
authors = ["Nicola Ricciardi"]
edition = "2021"
description = "Official NMD CLI and compiler"
readme = "README.md"
repository = "https://github.com/nricciardi/nmd"
license-file = "LICENSE"
keywords = ["compiler", "nmd", "markdown"]
exclude = [
"test-resources/*",
"logo/*",
"docs/*"
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "4.4.18"
env_logger = "0.10.1"
getset = "0.1.2"
log = "0.4.20"
notify = "6.1.1"
once_cell = "1.19.0"
rayon = "1.8.0"
regex = "1.10.2"
reqwest = { version = "0.11.24", features = ["blocking"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.113"
serde_yaml = "0.9.31"
simple_logger = "4.3.3"
thiserror = "1.0.50"
url = "2.5.0"
tokio = { version = "1", features = ["full"] }
warp = "0.3"
chrono = "0.4.38"
nmd-core = "0.40.0"


[profile.profiling]
inherits = "release"
debug = true
63 changes: 0 additions & 63 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,6 @@

nothing

### Features done

- [x] Use file name instead of absolute path in dossier configuration
- [x] Other sections in dossier configuration to manage all options
- [x] Local math (no CDN)
- [x] List
- [x] List creation check
- [x] Link with identifier
- [x] Link to chapters
- [x] Quote
- [x] Image caption
- [x] Image URL fix meta-characters
- [x] Multiple image in a single row
- [x] Set image dimensions
- [x] Image compression
- [x] Image in dossier: default path to `assets/images`
- [x] Parse image caption
- [x] Focus block
- [x] Light base page style
- [x] Embedded style
- [x] Embedded chapter style
- [x] Custom style files
- [x] Tables
- [x] Embedded Greek letters
- [x] Fix single list item
- [x] Todo modifier with only `todo` or `TODO`
- [x] Todo modifier with text between `TODO:` and `:TODO`
- [x] Relative header (e.g. `#+` to indicate precedent header level + 1, `#=` to indicate same header level of precedente header)
- [x] Short image modifier (without alt)
- [x] `nmd dossier add` auto-add `.nmd`
- [x] `nmd dossier add` accept more than one file
- [x] Escape
- [x] Metadata
- [x] Reference
- [x] Table of contents without page numbers
- [x] Bibliography
- [x] Compile only modified chapters in watcher mode
- [x] Web server to refresh compiled output

### Planned Features

- [ ] All modifiers
- [ ] `* words *`
- [x] Use `getset` crate
- [ ] embed_remote_image
- [ ] Possibility to use a different dossier configuration name
- [ ] PDF compile format
- [x] Vintage style (typewriter)
- [x] Dark style
- [ ] Run code
- [ ] Video
- [x] Scientific style
- [ ] Linkify (convert URL-like strings in links)
- [x] Fast draft (prevent to parse time consuming parts)
- [ ] Dynamics addons (e.g. katex iff math is used)
- [ ] Watcher mode for single file compilation
- [ ] Split CLI lib from compiler
- [x] Compile only a subset of documents
- [ ] Paper format support (A3, A5, ...)
- [x] MD to NMD converter
- [x] Include all .nmd file in running directory as default option in dossier configuration
- [x] Compile single files
- [ ] Table of contents with page numbers
- [ ] Select position of ToC and Bibliography
- [ ] Cover page
- [ ] VS Code extension (https://dev.to/salesforceeng/how-to-build-a-vs-code-extension-for-markdown-preview-using-remark-processor-1169)
125 changes: 121 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
![Logo](logo/logo.png)


[![License](https://img.shields.io/badge/license-GPL3-green.svg)](LICENSE)
[![Version](https://img.shields.io/badge/version-v1.3.0-blue.svg)](CHANGELOG.md)

# New MarkDown

**New way to write in markdown**
Expand Down Expand Up @@ -57,18 +61,131 @@ Why stick to Markdown when you can be cool using **NMD**?

You can find the current NMD's syntax to build nmd documents go to this [link](https://github.com/nricciardi/nmd-core/blob/main/NMD.md).

## NMD command line interface

You can download last release of **NMD command line interface** [here](https://github.com/nricciardi/nmd-cli/releases) or download it through [Cargo](https://github.com/rust-lang/cargo):
## NMD CLI

### Getting Started

Do you want **migrate from Markdown to New Markdown** easily and quickly? Read [how to do that](#markdown-to-new-markdown) using CLI!

### TL;DR

```shell
cargo install nmd

nmd generate dossier -p dossier/input/path -f -w

nmd dossier -p dossier/input/path add -d new-document.nmd

nmd build -i input/path
```

### Installation

You can install NMD using Cargo or downloading last release from Github.

```shell
cargo install nmd
```

### Commands

#### Generate a new dossier

To **generate a new dossier** you can use the following command:

```shell
nmd generate dossier -p dossier/input/path
```

There are many *flags* that you can use in combination with `generate dossier`. For example, if you want *force* the generation you can use `-f`, or if you want a *welcome page* you can use `-w`.

```shell
nmd generate dossier -p dossier/input/path -f -w
```

The Git support is planned, but not implemented yet. You can only add `.gitkeep` files in assets directories using `-k`.

`-n` permits to specify dossier name.

##### Markdown to New Markdown

You can easily convert a standard Markdown file in a New Markdown dossier using `--from-md <md-file-path>` option.

##### Add a new document

To **add a new document** you can use the following command:

```shell
nmd dossier -p dossier/input/path add -d new-document.nmd
```

If the document name doesn't have `nmd` extension, it will be added automatically.

You can add more than one document at the same time:

```shell
nmd dossier -p dossier/input/path add -d new-document-1.nmd -d new-document-2.nmd -d new-document-3.nmd
```

##### Reset dossier configuration

```shell
nmd dossier -p dossier/input/path reset [ -p ]
```

`-p` reset flag to preserve documents list.

#### Build

You can build a dossier or a single file through `build` command.

The only mandatory option is the input path. It can be a path to a directory (dossier) or a file.

```shell
nmd build -i input/path
```

`compile` command has a lot of options. You could specify the output format using `-f <format>` (e.g. `html`, which is the default), the output path with `-o <output-path>` or the theme using `-t <theme>`. The available themes are:

- `light`
- `dark`
- `vintage`
- `scientific`
- `none`


```shell
nmd compile -f html dossier -i dossier/input/path -o artifact/output/path
```

Moreover, if you watch dossier files and compile them if something changes, you should use watcher mode (`-w` option). Watcher mode compile dossier if any change is captured. Changes are captured only if a minimum time is elapsed. To set minimum time use `--watcher-time` option.

`--fast-draft` to create a fast draft of dossier, generally compiler takes less time to generate it.

`--parallelization` to parallelize work (default is single thread).

`-s <document1> -s <documentN>` to compile only a subset of documents in dossier configuration list.

In the end, if you are writing in NMD and you want a preview, you could compile with `-p` option. `-p` renders a preview in a web server on `127.0.0.1:1234` (`--preview-scraping-interval <interval>` to set client scraping interval in *milliseconds*).

`--embed-local-image`, `--embed-remote-image`, `--strict-image-src-check` and `--embed-local-image` to manage images parsing.

You can use `--nuid` to add *NUID*.

#### Analyze

You could want analyze a dossier or a document before build it. `analyze` command print on `stdout` the corresponding JSON.

```shell
nmd analyze -i input/path
```

## NMD x VS Code
You can use `--nuid` to add *NUID* or `--pretty` to print pretty formatted JSON.

You can use the official [NMD x VS Code](https://github.com/nricciardi/nmd-vscode) extension!
## Develop

Develop [check list](DEVELOP.md)

## Author

Expand Down
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

rustup update

cargo test --verbose

cargo build --release --target x86_64-unknown-linux-gnu

cargo build --release --target x86_64-pc-windows-gnu
Loading

0 comments on commit 3afafd0

Please sign in to comment.