Skip to content

Commit

Permalink
Bugs fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
nricciardi committed Jul 24, 2024
1 parent 3595069 commit 5a80621
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nmd"
version = "0.36.0"
version = "0.36.1"
authors = ["Nicola Ricciardi"]
edition = "2021"
description = "Official NMD CLI and compiler"
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**New way to write in markdown**

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

NMD stands for **New MarkDown**, or for friends, *Nicola MarkDown* (if Stephen Bourne can name a shell, why can't I name mine NMD?)

Expand Down Expand Up @@ -44,7 +44,7 @@ NMD is full compatible with CommonMark standard.

#### Performance

Being developed in Rust, NMD has incredible performance. In single thread mode, NMD is 10 times faster than the compiler for VS Code, while in multi thread mode it is **20 times faster**!
Being developed in Rust, NMD has incredible performance. In single thread mode, NMD is 2 times faster than the compiler for VS Code, while in multi thread mode it is up to **10 times faster**, but having more features as more modifiers, integrated table of content and bibliography!

#### Extended Syntax

Expand Down Expand Up @@ -182,10 +182,14 @@ Moreover, if you watch dossier files and compile them if something changes, you

`--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.

## Develop

Develop [check list](DEVELOP.md)
Expand Down
73 changes: 68 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::panic;
use std::collections::HashSet;
use std::num::ParseIntError;
use std::sync::Arc;
Expand Down Expand Up @@ -176,6 +177,36 @@ impl NmdCli {
.help("compile only a documents subset")
.action(ArgAction::Append)
)
.arg(
Arg::new("parallelization")
.long("parallelization")
.help("set parallelization")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("embed-local-image")
.long("embed-local-image")
.help("set embed local image")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("embed-remote-image")
.long("embed-remote-image")
.help("set embed remote image")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("compress-embed-image")
.long("compress-embed-image")
.help("set compress embed image")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("strict-image-src-check")
.long("strict-image-src-check")
.help("set strict image source check")
.action(ArgAction::SetTrue)
)
)
.subcommand(
Command::new("generate")
Expand Down Expand Up @@ -383,14 +414,24 @@ impl NmdCli {
},
CompilableResourceType::File => {

compilation_configuration.set_output_location(compilation_configuration.input_location().clone()); // could be a dir or a file
let mut output_path = compilation_configuration.input_location().clone();

if compilation_configuration.output_location().is_dir() {
compilation_configuration.set_output_location(compilation_configuration.output_location().join(file_utility::build_output_file_name(
compilation_configuration.input_location().file_stem().unwrap().to_string_lossy().to_string().as_str(),
if output_path.is_dir() {

output_path = output_path.join(file_utility::build_output_file_name(
output_path.file_stem().unwrap().to_string_lossy().to_string().as_str(),
Some(&compilation_configuration.format().get_extension())
)));
));

} else {

output_path = output_path.parent().unwrap().join(file_utility::build_output_file_name(
output_path.file_stem().unwrap().to_string_lossy().to_string().as_str(),
Some(&compilation_configuration.format().get_extension())
));
}

compilation_configuration.set_output_location(output_path);
},
CompilableResourceType::Unknown => (),
}
Expand Down Expand Up @@ -468,6 +509,28 @@ impl NmdCli {
compilation_configuration.set_styles_raw_path(styles.map(|s| s.clone()).collect());
}

// PARALLELIZATION
if matches.get_flag("parallelization") {
compilation_configuration.set_parallelization(Some(true));
}

// IMAGEs
if matches.get_flag("embed-local-image") {
compilation_configuration.set_embed_local_image(Some(true));
}

if matches.get_flag("embed-remote-image") {
compilation_configuration.set_embed_remote_image(Some(true));
}

if matches.get_flag("compress-embed-image") {
compilation_configuration.set_compress_embed_image(Some(true));
}

if matches.get_flag("strict-image-src-check") {
compilation_configuration.set_strict_image_src_check(Some(true));
}

// DOCUMENT SUBSET (only if dossier)
if let Some(documents_subset) = matches.get_many::<String>("documents-subset") {

Expand Down
14 changes: 9 additions & 5 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Compiler {

let loading_start = Instant::now();

log::info!("compilation configuration (this will override dossier compilation configuration):\n\n{:#?}\n", compilation_configuration);
log::debug!("compilation configuration (this will override dossier compilation configuration):\n\n{:#?}\n", compilation_configuration);

let codex = Arc::new(compilation_configuration.codex());

Expand Down Expand Up @@ -161,6 +161,8 @@ impl Compiler {

dossier.parse(compilation_configuration.format(), Arc::clone(&codex), Arc::new(RwLock::new(parsing_configuration)), Arc::new(parsing_configuration_overlay))?;

log::info!("dossier parsed in {} ms", compilation_start.elapsed().as_millis());

assembler_configuration.set_theme(compilation_configuration.theme().as_ref().unwrap_or(&dossier_theme).clone());
assembler_configuration.set_preview(compilation_configuration.preview());
assembler_configuration.set_watching(compilation_configuration.watching());
Expand Down Expand Up @@ -483,17 +485,17 @@ impl Compiler {

log::info!("start to compile dossier");

let compile_start = Instant::now();
let compilation_start = Instant::now();

log::info!("compilation configuration (this will override dossier compilation configuration):\n\n{:#?}\n", compilation_configuration);
log::debug!("compilation configuration (this will override dossier compilation configuration):\n\n{:#?}\n", compilation_configuration);

let codex = compilation_configuration.codex();

let loader = Loader::new();

let mut document: Document = loader.load_document_from_path(&codex, compilation_configuration.input_location())?;

log::info!("document loaded in {} ms", compile_start.elapsed().as_millis());
log::info!("document loaded in {} ms", compilation_start.elapsed().as_millis());

compilation_configuration.fill_with_default();

Expand All @@ -519,6 +521,8 @@ impl Compiler {

document.parse(compilation_configuration.format(), Arc::clone(&codex), Arc::new(RwLock::new(parsing_configuration)), Arc::new(None))?;

log::info!("document parsed in {} ms", compilation_start.elapsed().as_millis());

assembler_configuration.set_theme(compilation_configuration.theme().clone().unwrap_or(Theme::default()));
assembler_configuration.set_preview(compilation_configuration.preview());
assembler_configuration.set_watching(compilation_configuration.watching());
Expand All @@ -539,7 +543,7 @@ impl Compiler {

artifact.dump(&dump_configuration)?;

log::info!("end to compile dossier (compile time: {} ms)", compile_start.elapsed().as_millis());
log::info!("end to compile dossier (compile time: {} ms)", compilation_start.elapsed().as_millis());

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compilation_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl CompilationConfiguration {

pub fn fill_with_default(&mut self) {
if self.embed_local_image().is_none() {
self.set_embed_local_image(Some(true));
self.set_embed_local_image(Some(false));
}

if self.embed_remote_image().is_none() {
Expand All @@ -156,7 +156,7 @@ impl CompilationConfiguration {
}

if self.parallelization().is_none() {
self.set_parallelization(Some(true));
self.set_parallelization(Some(false));
}

if self.strict_image_src_check().is_none() {
Expand Down
11 changes: 8 additions & 3 deletions src/compiler/parsing/parsing_rule/html_image_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,15 @@ impl HtmlImageRule {

let id = ResourceReference::of(label.as_str(), Some(document_name)).unwrap();

let mut image: ImageResource = ImageResource::new(PathBuf::from(src.as_str()), Some(parsed_label.parsed_content()), Some(label.as_str().to_string()))
let image = ImageResource::new(PathBuf::from(src.as_str()), Some(parsed_label.parsed_content()), Some(label.as_str().to_string()))
.elaborating_relative_path_as_dossier_assets(parsing_configuration.input_location())
.inferring_mime_type()
.unwrap();
.inferring_mime_type();

if let Err(err) = &image {
log::error!("error occurs during image '{}' loading: {}", src.as_str(), err.to_string());
}

let mut image = image.unwrap();

return Self::build_img_from_parsing_configuration(&mut image, Some(id), vec!["image"], style, &parsing_configuration).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/// NMD version
pub const VERSION: &str = "0.36.0";
pub const VERSION: &str = "0.36.1";


pub const DOSSIER_CONFIGURATION_YAML_FILE_NAME: &str = "nmd.yml";
Expand Down
7 changes: 7 additions & 0 deletions src/resource/image_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ impl ImageResource {

/// Elaborate `src` path if it is relative appending if it doesn't exist dossier `assets` directory
pub fn elaborating_relative_path_as_dossier_assets(mut self, base_location: &PathBuf) -> Self {

let mut base_location: PathBuf = base_location.clone();

if !base_location.is_dir() {
base_location = PathBuf::from(base_location.parent().unwrap());
}

if self.src().is_relative() {

self.set_src(base_location.join(self.src()));
Expand Down

0 comments on commit 5a80621

Please sign in to comment.