Skip to content

Commit

Permalink
Merge pull request #55 from mdzk-rs/issue-54
Browse files Browse the repository at this point in the history
Issue 54
  • Loading branch information
kmaasrud authored Nov 14, 2021
2 parents ab5d7e8 + 5d26367 commit 4405758
Show file tree
Hide file tree
Showing 17 changed files with 767 additions and 251 deletions.
47 changes: 5 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,30 @@ include = [
[workspace]
members = [
"preprocessors/mdbook-backlinks",
"preprocessors/mdbook-wikilinks",
"preprocessors/mdbook-frontmatter",
"preprocessors/mdbook-readme",
]

[dependencies]
anyhow = "1.0.44"
chrono = "0.4.19"
futures-util = "0.3.17"
gray_matter = "0.2.1"
handlebars = "4.1.3"
ignore = "0.4"
lazy-regex = "2.2.1"
mdbook = { version = "0.4.12", default-features = false }
notify = "4.0.17"
pulldown-cmark = { version = "0.8.0", default-features = false }
pathdiff = "0.2.0"
pest = "2.1"
pest_derive = "2.1"
pulldown-cmark = { version = "0.8.0", default-features = false, features = ["simd"] }
regex = "1.5.4"
serde = "1.0.130"
serde_json = "1.0.68"
structopt = "0.3.23"
toml = "0.5.8"

# Preprocessors
mdbook-backlinks = { path = "preprocessors/mdbook-backlinks", version = "0.2.7" }
mdbook-frontmatter = { path = "preprocessors/mdbook-frontmatter", version = "0.0.4" }
mdbook-readme = { path = "preprocessors/mdbook-readme", version = "0.0.4" }
mdbook-wikilinks = { path = "preprocessors/mdbook-wikilinks", version = "0.4.0" }

# Feature: Search
ammonia = "3.1.2"
Expand Down
2 changes: 1 addition & 1 deletion preprocessors/mdbook-wikilinks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ let link = "[[link_in_code]]".to_owned();
}

#[test]
fn escapel_special_chars() {
fn test_escape_special_chars() {
assert_eq!(
escape_special_chars("w3ir∂ førmättÎñg"),
"w3ir%E2%88%82%20f%C3%B8rm%C3%A4tt%C3%8E%C3%B1g"
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{utils, Config, BUILD_DIR, CONFIG_FILE, DEFAULT_ZK_TITLE, SRC_DIR};

use anyhow::{Result, Context};
use anyhow::{Context, Result};
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
Expand Down Expand Up @@ -45,13 +45,16 @@ pub fn init(dir: Option<PathBuf>) -> Result<()> {
.write_all(&config_bytes)
.context("Unable to write to the configuration file.")?;

success!(r#"Your mdzk is now initialized!
success!(
r#"Your mdzk is now initialized!
To start using mdzk, write some notes in {:?} or move your existing notes there.
You can then run `mdzk serve` to start a webserver with live updating.
If you need more help, you can always run `mdzk help` or view the documentation
online at https://mdzk.app/docs."#, config.mdzk.src);
online at https://mdzk.app/docs."#,
config.mdzk.src
);

Ok(())
}
4 changes: 2 additions & 2 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use crate::renderer::HtmlMdzk;
use crate::{cmd::watch, load_zk};
use anyhow::{anyhow, Result};
use futures_util::sink::SinkExt;
use futures_util::StreamExt;
use mdbook::{
Expand Down Expand Up @@ -55,7 +55,7 @@ pub fn serve(dir: Option<PathBuf>, port: i32, bind: String, renderer: String) ->
});

let serving_url = format!("http://{}", address);
info!("Serving your mdzk on: {}.", serving_url);
success!("Serving your mdzk on: {}.", serving_url);

/* if open_browser {
open(serving_url);
Expand Down
23 changes: 19 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ impl Config {
.read_to_string(&mut buffer)
.context("Couldn't read the configuration file")?;

let mut conf = Config::from_str(&buffer)
.with_context(|| format!("Unable to load the configuration file {:?}", path.as_ref()))?;
let mut conf = Config::from_str(&buffer).with_context(|| {
format!("Unable to load the configuration file {:?}", path.as_ref())
})?;

if conf.rest.get_mut("book").is_some() {
warn!("Found a '[book]' section on your 'mdzk.toml' file. You might want to replace it with '[mdzk]' ;-)")
Expand Down Expand Up @@ -68,18 +69,24 @@ impl FromStr for Config {

/// Load an mdzk configuration from some string.
fn from_str(src: &str) -> Result<Self> {
toml::from_str(src)
.with_context(|| format!("Invalid TOML:\n\n{}\n", src))
toml::from_str(src).with_context(|| format!("Invalid TOML:\n\n{}\n", src))
}
}

impl From<Config> for mdbook::Config {
fn from(conf: Config) -> Self {
let mut config = mdbook::Config::default();

// Explicitly set some values in the book config
config
.set("mdzk.backlinks-header", conf.mdzk.backlinks_header.clone())
.ok();
config
.set("mdzk.front-matter", conf.build.front_matter)
.ok();
config.set("mdzk.math", conf.build.math).ok();
config.set("mdzk.readme", conf.build.readme).ok();
config.set("mdzk.wikilinks", conf.build.wikilinks).ok();

config.book = conf.mdzk.into();
config.build = conf.build.into();
Expand Down Expand Up @@ -216,6 +223,10 @@ pub struct BuildConfig {
pub build_dir: PathBuf,
pub create_missing: bool,
pub disable_default_preprocessors: bool,
pub front_matter: bool,
pub math: bool,
pub readme: bool,
pub wikilinks: bool,
pub preprocessors: Vec<String>,
}

Expand All @@ -225,6 +236,10 @@ impl Default for BuildConfig {
build_dir: PathBuf::from(BUILD_DIR),
create_missing: true,
disable_default_preprocessors: false,
front_matter: true,
math: true,
readme: true,
wikilinks: true,
preprocessors: vec![],
}
}
Expand Down
168 changes: 0 additions & 168 deletions src/katex.rs

This file was deleted.

Loading

0 comments on commit 4405758

Please sign in to comment.