Skip to content

Commit ec1648f

Browse files
committed
fix: separate --watch and --live
1 parent 928a8ec commit ec1648f

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,56 @@
33
Converts Markdown documents into themed HTML pages with support
44
for code syntax highlighting, LaTeX and Mermaid diagrams.
55

6-
Supports PDF conversion via headless chromium.
6+
Supports preview with **hot-reload** and **PDF** conversion via [headless chromium](https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md).
77

88
> **Note** When converting to PDF it will automatically download a suitable
99
> headless chrome binary if one is not present on your system
1010
1111
<!--toc:start-->
12-
- [Examples](#examples)
13-
- [Install](#install)
14-
- [Help](#help)
15-
- [Build](#build)
12+
13+
- [Examples](#examples)
14+
- [Install](#install)
15+
- [Help](#help)
16+
- [Build](#build)
1617
<!--toc:end-->
1718

1819
## Examples
1920

2021
Convert `doc.md` to `doc.html`
22+
2123
```bash
2224
marky doc.md
2325
```
2426

2527
Convert to PDF
28+
2629
```bash
2730
marky doc.md --pdf
2831
```
2932

33+
Start a local server with hot-reload
34+
3035
Start a live file watcher (will recompile your document on each save)
36+
3137
```bash
3238
marky doc.md --watch
3339
```
3440

3541
Enable extensions
42+
3643
```bash
3744
# Or use --all to enable all
3845
marky doc.md --math --diagrams --highlight
3946
```
4047

4148
Select and use a different theme with fzf
49+
4250
```bash
4351
marky doc.md --theme $(marky --list-themes | fzf)
4452
```
4553

4654
Pipe from stdout and open compiled file
55+
4756
```bash
4857
cat doc.md | marky --out doc.html --open
4958
```

src/cli.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ use std::{io, path::PathBuf};
1616
.args(&["out", "stdout"])
1717
.conflicts_with("info")
1818
))]
19-
19+
#[clap(group(
20+
ArgGroup::new("watchers")
21+
.args(&["watch", "live"])
22+
.conflicts_with("info")
23+
))]
2024
pub struct Cli {
2125
#[arg(long = "completion", value_enum)]
2226
pub generator: Option<Shell>,
@@ -30,8 +34,8 @@ pub struct Cli {
3034
#[arg(long, help = "Read input from string")]
3135
pub string: Option<String>,
3236

33-
#[arg(short, long, group = "info", help = "List available themes")]
34-
pub list_themes: bool,
37+
#[arg(long, group = "info", help = "List available themes")]
38+
pub themes: bool,
3539

3640
#[arg(long, group = "info", help = "Print config path")]
3741
pub where_config: bool,
@@ -58,10 +62,10 @@ pub struct Cli {
5862
#[arg(short = 'A', long, help = "Enable all extra renderers")]
5963
pub all: bool,
6064

61-
#[arg(short, long, help = "Enable file watcher")]
65+
#[arg(short, long, help = "Recompile file on save")]
6266
pub watch: bool,
6367

64-
#[arg(long, help = "Enable live file preview")]
68+
#[arg(short, long, help = "Live preview in the browser")]
6569
pub live: bool,
6670

6771
#[arg(long, default_value = "8080", help = "Port of the live server")]

src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
2323
return Ok(());
2424
}
2525

26-
if cli.list_themes {
26+
if cli.themes {
2727
for theme in themes::available_themes()?.themes.into_iter() {
2828
println!("{}", theme.name);
2929
}
@@ -83,7 +83,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
8383
}
8484
};
8585

86-
if cli.watch {
86+
if cli.watch || cli.live {
8787
if cli.path.is_none() {
8888
die!("watcher needs a file to watch");
8989
}
@@ -96,8 +96,6 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
9696
watcher::watch_file(path, &out, &options).await?;
9797
}
9898

99-
// watcher::watch(&cli.path.unwrap(), &out, &options).await?;
100-
10199
return Ok(());
102100
}
103101

0 commit comments

Comments
 (0)