mirror of
https://github.com/getzola/zola
synced 2024-12-12 21:32:29 +00:00
Move markdown config to its own section in config.toml
This commit is contained in:
parent
2673466998
commit
94634fe87d
11 changed files with 228 additions and 119 deletions
|
@ -9,6 +9,9 @@
|
|||
- Render emoji in Markdown content if the option is enabled
|
||||
- Enable YouTube privacy mode for the YouTube shortcode
|
||||
- Add language as class to the `<code>` block
|
||||
- Add bibtex to `load_data`
|
||||
- Add a `[markdown]` section to `config.toml` to configure rendering
|
||||
- Add `highlight_code` and `highlight_theme` to a `[markdown]` section in `config.toml`
|
||||
|
||||
## 0.12.2 (2020-09-28)
|
||||
|
||||
|
|
147
Cargo.lock
generated
147
Cargo.lock
generated
|
@ -53,9 +53,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "assert-json-diff"
|
||||
|
@ -175,9 +175,9 @@ checksum = "f861d9ce359f56dbcb6e0c2a1cb84e52ad732cadb57b806adeb3c7668caccbd8"
|
|||
|
||||
[[package]]
|
||||
name = "bytecount"
|
||||
version = "0.6.0"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0017894339f586ccb943b01b9555de56770c11cda818e7e3d8bd93f4ed7f46e"
|
||||
checksum = "c39a773ba75db12126d8d383f1bdbf7eb92ea47ec27dd0557aff1fedf172764c"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
|
@ -209,9 +209,9 @@ checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.62"
|
||||
version = "1.0.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40"
|
||||
checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15"
|
||||
|
||||
[[package]]
|
||||
name = "cedarwood"
|
||||
|
@ -305,6 +305,16 @@ dependencies = [
|
|||
"utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console_error_panic_hook"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_fn"
|
||||
version = "0.4.3"
|
||||
|
@ -752,7 +762,7 @@ dependencies = [
|
|||
"futures-macro",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project 1.0.1",
|
||||
"pin-project 1.0.2",
|
||||
"pin-utils",
|
||||
"proc-macro-hack",
|
||||
"proc-macro-nested",
|
||||
|
@ -962,7 +972,7 @@ dependencies = [
|
|||
"httparse",
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project 1.0.1",
|
||||
"pin-project 1.0.2",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
|
@ -1034,9 +1044,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.23.11"
|
||||
version = "0.23.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4f0a8345b33b082aedec2f4d7d4a926b845cee184cbe78b703413066564431b"
|
||||
checksum = "7ce04077ead78e39ae8610ad26216aed811996b043d47beed5090db674f9e9b5"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder",
|
||||
|
@ -1184,7 +1194,7 @@ checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616"
|
|||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"cfg-if 0.1.10",
|
||||
"ryu",
|
||||
"static_assertions",
|
||||
]
|
||||
|
@ -1482,7 +1492,7 @@ dependencies = [
|
|||
"rand",
|
||||
"regex",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"serde_urlencoded 0.6.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1533,7 +1543,7 @@ checksum = "c9db257f6c7b9c8b3ab67ee6a4b23a290c157d183fef2ac065bf9fce5f1c1299"
|
|||
dependencies = [
|
||||
"nom",
|
||||
"nom-tracable",
|
||||
"nom_locate 2.0.0",
|
||||
"nom_locate 2.1.0",
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
|
@ -1546,7 +1556,7 @@ dependencies = [
|
|||
"nom",
|
||||
"nom-tracable-macros",
|
||||
"nom_locate 1.0.0",
|
||||
"nom_locate 2.0.0",
|
||||
"nom_locate 2.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1572,11 +1582,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "nom_locate"
|
||||
version = "2.0.0"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e4726500a3d0297dd38edc169d919ad997a9931b4645b59ce0231e88536e213"
|
||||
checksum = "a67484adf5711f94f2f28b653bf231bff8e438be33bf5b0f35935a0db4f618a2"
|
||||
dependencies = [
|
||||
"bytecount 0.6.0",
|
||||
"bytecount 0.6.1",
|
||||
"memchr",
|
||||
"nom",
|
||||
]
|
||||
|
@ -1806,11 +1816,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841"
|
||||
checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7"
|
||||
dependencies = [
|
||||
"pin-project-internal 1.0.1",
|
||||
"pin-project-internal 1.0.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1826,9 +1836,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pin-project-internal"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86"
|
||||
checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1841,6 +1851,12 @@ version = "0.1.11"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
|
@ -2116,11 +2132,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.10.8"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e"
|
||||
checksum = "fb15d6255c792356a0f578d8a645c677904dc02e862bebe2ecc18e0c01b9a0ce"
|
||||
dependencies = [
|
||||
"base64 0.12.3",
|
||||
"base64 0.13.0",
|
||||
"bytes 0.5.6",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
|
@ -2136,15 +2152,16 @@ dependencies = [
|
|||
"mime",
|
||||
"mime_guess",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.2.0",
|
||||
"rustls",
|
||||
"serde",
|
||||
"serde_urlencoded",
|
||||
"serde_urlencoded 0.7.0",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-test",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
"winreg",
|
||||
|
@ -2152,9 +2169,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.15"
|
||||
version = "0.16.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "952cd6b98c85bbc30efa1ba5783b8abf12fec8b3287ffa52605b9432313e34e4"
|
||||
checksum = "b72b84d47e8ec5a4f2872e8262b8f8256c5be1c938a7d6d3a867a3ba8f722f74"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
|
@ -2240,6 +2257,12 @@ dependencies = [
|
|||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scoped-tls"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
|
||||
|
||||
[[package]]
|
||||
name = "scoped_threadpool"
|
||||
version = "0.1.9"
|
||||
|
@ -2318,6 +2341,18 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha-1"
|
||||
version = "0.8.2"
|
||||
|
@ -2399,9 +2434,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.4.2"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
|
||||
checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
|
@ -2429,9 +2464,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||
|
||||
[[package]]
|
||||
name = "string_cache"
|
||||
version = "0.8.0"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2940c75beb4e3bf3a494cef919a747a2cb81e52571e212bfbd185074add7208a"
|
||||
checksum = "8ddb1139b5353f96e429e1a5e19fbaf663bddedaa06d1dbd49f82e352601209a"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"new_debug_unreachable",
|
||||
|
@ -2595,9 +2630,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.0"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
||||
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
@ -2644,9 +2679,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.0.1"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b78a366903f506d2ad52ca8dc552102ffdd3e937ba8a227f024dc1d1eae28575"
|
||||
checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
@ -2671,7 +2706,7 @@ dependencies = [
|
|||
"memchr",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.1.11",
|
||||
"slab",
|
||||
"tokio-macros",
|
||||
]
|
||||
|
@ -2709,7 +2744,7 @@ dependencies = [
|
|||
"futures-core",
|
||||
"futures-sink",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.1.11",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
@ -2736,7 +2771,7 @@ checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27"
|
|||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.1.11",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
|
@ -2847,9 +2882,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.14"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7f98e67a4d84f730d343392f9bfff7d21e3fca562b9cb7a43b768350beeddc6"
|
||||
checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
@ -3032,6 +3067,30 @@ version = "0.2.68"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test"
|
||||
version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34d1cdc8b98a557f24733d50a1199c4b0635e465eecba9c45b214544da197f64"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"js-sys",
|
||||
"scoped-tls",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-test-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test-macro"
|
||||
version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8fb9c67be7439ee8ab1b7db502a49c05e51e2835b66796c705134d9b8e1a585"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.45"
|
||||
|
@ -3054,9 +3113,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.19.0"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8eff4b7516a57307f9349c64bf34caa34b940b66fed4b2fb3136cb7386e5739"
|
||||
checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f"
|
||||
dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
|
25
components/config/src/config/markup.rs
Normal file
25
components/config/src/config/markup.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
pub const DEFAULT_HIGHLIGHT_THEME: &str = "base16-ocean-dark";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct Markdown {
|
||||
/// Whether to highlight all code blocks found in markdown files. Defaults to false
|
||||
pub highlight_code: bool,
|
||||
/// Which themes to use for code highlighting. See Readme for supported themes
|
||||
/// Defaults to "base16-ocean-dark"
|
||||
pub highlight_theme: String,
|
||||
/// Whether to render emoji aliases (e.g.: :smile: => 😄) in the markdown files
|
||||
pub render_emoji: bool,
|
||||
}
|
||||
|
||||
impl Default for Markdown {
|
||||
fn default() -> Markdown {
|
||||
Markdown {
|
||||
highlight_code: false,
|
||||
highlight_theme: DEFAULT_HIGHLIGHT_THEME.to_owned(),
|
||||
render_emoji: false,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
pub mod languages;
|
||||
pub mod link_checker;
|
||||
pub mod markup;
|
||||
pub mod search;
|
||||
pub mod slugify;
|
||||
pub mod taxonomies;
|
||||
|
@ -106,8 +107,8 @@ pub struct Config {
|
|||
/// The search config, telling what to include in the search index
|
||||
pub search: search::Search,
|
||||
|
||||
/// Whether to render emoji aliases (e.g.: :smile: => 😄) in the markdown files
|
||||
pub emoji_rendering: bool,
|
||||
/// The config for the Markdown rendering: syntax highlighting and everything
|
||||
pub markdown: markup::Markdown,
|
||||
|
||||
/// All user params set in [extra] in the config
|
||||
pub extra: HashMap<String, Toml>,
|
||||
|
@ -158,6 +159,10 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
if config.highlight_code {
|
||||
println!("`highlight_code` has been moved to a [markdown] section. Top level `highlight_code` and `highlight_theme` will stop working in 0.14.");
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
|
@ -172,6 +177,30 @@ impl Config {
|
|||
Config::parse(&content)
|
||||
}
|
||||
|
||||
/// Temporary, while we have the settings in 2 places
|
||||
/// TODO: remove me in 0.14
|
||||
pub fn highlight_code(&self) -> bool {
|
||||
if !self.highlight_code && !self.markdown.highlight_code {
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.highlight_code {
|
||||
true
|
||||
} else {
|
||||
self.markdown.highlight_code
|
||||
}
|
||||
}
|
||||
|
||||
/// Temporary, while we have the settings in 2 places
|
||||
/// TODO: remove me in 0.14
|
||||
pub fn highlight_theme(&self) -> &str {
|
||||
if self.highlight_theme != markup::DEFAULT_HIGHLIGHT_THEME {
|
||||
&self.highlight_theme
|
||||
} else {
|
||||
&self.markdown.highlight_theme
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempt to load any extra syntax found in the extra syntaxes of the config
|
||||
pub fn load_extra_syntaxes(&mut self, base_path: &Path) -> Result<()> {
|
||||
if self.extra_syntaxes.is_empty() {
|
||||
|
@ -339,8 +368,8 @@ impl Default for Config {
|
|||
link_checker: link_checker::LinkChecker::default(),
|
||||
slugify: slugify::Slugify::default(),
|
||||
search: search::Search::default(),
|
||||
markdown: markup::Markdown::default(),
|
||||
extra: HashMap::new(),
|
||||
emoji_rendering: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn bench_render_content_without_highlighting(b: &mut test::Bencher) {
|
|||
tera.add_raw_template("shortcodes/youtube.html", "{{id}}").unwrap();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = false;
|
||||
config.markdown.highlight_code = false;
|
||||
let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
b.iter(|| render_content(CONTENT, &context).unwrap());
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ fn bench_render_content_no_shortcode(b: &mut test::Bencher) {
|
|||
let tera = Tera::default();
|
||||
let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = false;
|
||||
config.markdown.highlight_code = false;
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
|
||||
|
@ -129,8 +129,8 @@ fn bench_render_content_no_shortcode_with_emoji(b: &mut test::Bencher) {
|
|||
let tera = Tera::default();
|
||||
let content2 = CONTENT.replace(r#"{{ youtube(id="my_youtube_id") }}"#, "");
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = false;
|
||||
config.emoji_rendering = true;
|
||||
config.markdown.highlight_code = false;
|
||||
config.markdown.render_emoji = true;
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let context = RenderContext::new(&tera, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
|
||||
|
|
|
@ -201,14 +201,12 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
|
|||
if let Some(ref mut code_block) = highlighter {
|
||||
let html = code_block.highlight(&text);
|
||||
Event::Html(html.into())
|
||||
} else if context.config.markdown.render_emoji {
|
||||
let processed_text = EMOJI_REPLACER.replace_all(&text);
|
||||
Event::Text(processed_text.to_string().into())
|
||||
} else {
|
||||
if context.config.emoji_rendering {
|
||||
let processed_text = EMOJI_REPLACER.replace_all(&text);
|
||||
Event::Text(processed_text.to_string().into())
|
||||
} else {
|
||||
// Business as usual
|
||||
Event::Text(text)
|
||||
}
|
||||
// Business as usual
|
||||
Event::Text(text)
|
||||
}
|
||||
}
|
||||
Event::Start(Tag::CodeBlock(ref kind)) => {
|
||||
|
@ -217,10 +215,10 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
|
|||
CodeBlockKind::Fenced(fence_info) => {
|
||||
let fence_info = fence::FenceSettings::new(fence_info);
|
||||
language = fence_info.language;
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
if !context.config.highlight_code {
|
||||
if !context.config.highlight_code() {
|
||||
if let Some(lang) = language {
|
||||
let html = format!(r#"<pre><code class="language-{}">"#, lang);
|
||||
return Event::Html(html.into());
|
||||
|
@ -228,7 +226,7 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
|
|||
return Event::Html("<pre><code>".into());
|
||||
}
|
||||
|
||||
let theme = &THEME_SET.themes[&context.config.highlight_theme];
|
||||
let theme = &THEME_SET.themes[context.config.highlight_theme()];
|
||||
match kind {
|
||||
CodeBlockKind::Indented => (),
|
||||
CodeBlockKind::Fenced(fence_info) => {
|
||||
|
@ -258,7 +256,7 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
|
|||
Event::Html(html.into())
|
||||
}
|
||||
Event::End(Tag::CodeBlock(_)) => {
|
||||
if !context.config.highlight_code {
|
||||
if !context.config.highlight_code() {
|
||||
return Event::Html("</code></pre>\n".into());
|
||||
}
|
||||
// reset highlight and close the code block
|
||||
|
|
|
@ -37,7 +37,7 @@ fn hl_lines_simple() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -66,7 +66,7 @@ fn hl_lines_in_middle() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -95,7 +95,7 @@ fn hl_lines_all() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -122,7 +122,7 @@ fn hl_lines_start_from_one() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -150,7 +150,7 @@ fn hl_lines_start_from_zero() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -178,7 +178,7 @@ fn hl_lines_end() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -206,7 +206,7 @@ fn hl_lines_end_out_of_bounds() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -234,7 +234,7 @@ fn hl_lines_overlap() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -261,7 +261,7 @@ fn hl_lines_multiple() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -289,7 +289,7 @@ fn hl_lines_extra_spaces() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -317,7 +317,7 @@ fn hl_lines_int_and_range() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -346,7 +346,7 @@ fn hl_lines_single_line_range() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
@ -375,7 +375,7 @@ fn hl_lines_reverse_range() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(
|
||||
r#"
|
||||
|
|
|
@ -23,7 +23,7 @@ fn doesnt_highlight_code_block_with_highlighting_off() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = false;
|
||||
config.markdown.highlight_code = false;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content("```\n$ gutenberg server\n```", &context).unwrap();
|
||||
assert_eq!(res.body, "<pre><code>$ gutenberg server\n</code></pre>\n");
|
||||
|
@ -34,7 +34,7 @@ fn can_highlight_code_block_no_lang() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content("```\n$ gutenberg server\n$ ping\n```", &context).unwrap();
|
||||
assert_eq!(
|
||||
|
@ -48,7 +48,7 @@ fn can_highlight_code_block_with_lang() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content("```python\nlist.append(1)\n```", &context).unwrap();
|
||||
assert_eq!(
|
||||
|
@ -62,7 +62,7 @@ fn can_higlight_code_block_with_unknown_lang() {
|
|||
let tera_ctx = Tera::default();
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = true;
|
||||
config.markdown.highlight_code = true;
|
||||
let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content("```yolo\nlist.append(1)\n```", &context).unwrap();
|
||||
// defaults to plain text
|
||||
|
@ -87,7 +87,9 @@ Hello
|
|||
)
|
||||
.unwrap();
|
||||
assert!(res.body.contains("<p>Hello</p>\n<div >"));
|
||||
assert!(res.body.contains(r#"<iframe src="https://www.youtube-nocookie.com/embed/ub36ffWAqgQ""#));
|
||||
assert!(res
|
||||
.body
|
||||
.contains(r#"<iframe src="https://www.youtube-nocookie.com/embed/ub36ffWAqgQ""#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -232,10 +234,12 @@ Hello
|
|||
)
|
||||
.unwrap();
|
||||
assert!(res.body.contains("<p>Hello</p>\n<div >"));
|
||||
assert!(res.body.contains(r#"<iframe src="https://www.youtube-nocookie.com/embed/ub36ffWAqgQ""#));
|
||||
assert!(res
|
||||
.body
|
||||
.contains(r#"<iframe src="https://www.youtube-nocookie.com/embed/ub36ffWAqgQ?autoplay=1""#));
|
||||
.contains(r#"<iframe src="https://www.youtube-nocookie.com/embed/ub36ffWAqgQ""#));
|
||||
assert!(res.body.contains(
|
||||
r#"<iframe src="https://www.youtube-nocookie.com/embed/ub36ffWAqgQ?autoplay=1""#
|
||||
));
|
||||
assert!(res.body.contains(r#"<iframe src="https://www.streamable.com/e/c0ic""#));
|
||||
assert!(res.body.contains(r#"//player.vimeo.com/video/210073083""#));
|
||||
}
|
||||
|
@ -244,7 +248,7 @@ Hello
|
|||
fn doesnt_render_ignored_shortcodes() {
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.highlight_code = false;
|
||||
config.markdown.highlight_code = false;
|
||||
let context = RenderContext::new(&ZOLA_TERA, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content(r#"```{{/* youtube(id="w7Ft2ymGmfc") */}}```"#, &context).unwrap();
|
||||
assert_eq!(res.body, "<p><code>{{ youtube(id="w7Ft2ymGmfc") }}</code></p>\n");
|
||||
|
@ -1004,7 +1008,6 @@ fn can_render_commented_out_shortcodes_fine() {
|
|||
assert_eq!(res.body, expected);
|
||||
}
|
||||
|
||||
|
||||
// https://zola.discourse.group/t/zola-12-issue-with-continue-reading/590/7
|
||||
#[test]
|
||||
fn can_render_read_more_after_shortcode() {
|
||||
|
@ -1041,13 +1044,10 @@ Again more text"#;
|
|||
fn can_render_emoji_alias() {
|
||||
let permalinks_ctx = HashMap::new();
|
||||
let mut config = Config::default();
|
||||
config.emoji_rendering = true;
|
||||
config.markdown.render_emoji = true;
|
||||
let context = RenderContext::new(&ZOLA_TERA, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content("Hello, World! :smile:", &context).unwrap();
|
||||
assert_eq!(
|
||||
res.body,
|
||||
"<p>Hello, World! 😄</p>\n"
|
||||
);
|
||||
assert_eq!(res.body, "<p>Hello, World! 😄</p>\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1056,8 +1056,5 @@ fn emoji_aliases_are_ignored_when_disabled_in_config() {
|
|||
let config = Config::default();
|
||||
let context = RenderContext::new(&ZOLA_TERA, &config, "", &permalinks_ctx, InsertAnchor::None);
|
||||
let res = render_content("Hello, World! :smile:", &context).unwrap();
|
||||
assert_eq!(
|
||||
res.body,
|
||||
"<p>Hello, World! :smile:</p>\n"
|
||||
);
|
||||
assert_eq!(res.body, "<p>Hello, World! :smile:</p>\n");
|
||||
}
|
|
@ -261,25 +261,22 @@ fn load_bibtex(bibtex_data: String) -> Result<Value> {
|
|||
let bibtex_model = nom_bibtex::Bibtex::parse(&bibtex_data).map_err(|e| format!("{:?}", e))?;
|
||||
let mut bibtex_map = Map::new();
|
||||
|
||||
let preambles_array = bibtex_model.preambles()
|
||||
.iter()
|
||||
.map(|v| Value::String(v.to_string()))
|
||||
.collect();
|
||||
let preambles_array =
|
||||
bibtex_model.preambles().iter().map(|v| Value::String(v.to_string())).collect();
|
||||
bibtex_map.insert(String::from("preambles"), Value::Array(preambles_array));
|
||||
|
||||
let comments_array = bibtex_model.comments()
|
||||
.iter()
|
||||
.map(|v| Value::String(v.to_string()))
|
||||
.collect();
|
||||
let comments_array =
|
||||
bibtex_model.comments().iter().map(|v| Value::String(v.to_string())).collect();
|
||||
bibtex_map.insert(String::from("comments"), Value::Array(comments_array));
|
||||
|
||||
let mut variables_map = Map::new();
|
||||
for (key,val) in bibtex_model.variables() {
|
||||
for (key, val) in bibtex_model.variables() {
|
||||
variables_map.insert(key.to_string(), Value::String(val.to_string()));
|
||||
}
|
||||
bibtex_map.insert(String::from("variables"), Value::Object(variables_map));
|
||||
|
||||
let bibliographies_array = bibtex_model.bibliographies()
|
||||
let bibliographies_array = bibtex_model
|
||||
.bibliographies()
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let mut m = Map::new();
|
||||
|
@ -300,7 +297,6 @@ fn load_bibtex(bibtex_data: String) -> Result<Value> {
|
|||
to_value(bibtex_value).map_err(|err| err.into())
|
||||
}
|
||||
|
||||
|
||||
/// Parse a CSV string and convert it to a Tera Value
|
||||
///
|
||||
/// An example csv file `example.csv` could be:
|
||||
|
|
|
@ -36,13 +36,6 @@ default_language = "en"
|
|||
# The site theme to use.
|
||||
theme = ""
|
||||
|
||||
# When set to "true", all code blocks are highlighted.
|
||||
highlight_code = false
|
||||
|
||||
# The theme to use for code highlighting.
|
||||
# See below for list of allowed values.
|
||||
highlight_theme = "base16-ocean-dark"
|
||||
|
||||
# When set to "true", a feed is automatically generated.
|
||||
generate_feed = false
|
||||
|
||||
|
@ -61,10 +54,6 @@ generate_feed = false
|
|||
# files are always copied, regardless of this setting.
|
||||
# hard_link_static = false
|
||||
|
||||
# When set to "true", emoji aliases translated to their corresponding
|
||||
# Unicode emoji equivalent in the rendered Markdown files. (e.g.: :smile: => 😄)
|
||||
# emoji_rendering = false
|
||||
|
||||
# The taxonomies to be rendered for the site and their configuration.
|
||||
# Example:
|
||||
# taxonomies = [
|
||||
|
@ -106,6 +95,18 @@ extra_syntaxes = []
|
|||
# You can override the default output directory `public` by setting an another value.
|
||||
# output_dir = "docs"
|
||||
|
||||
[markdown]
|
||||
# When set to "true", all code blocks are highlighted.
|
||||
highlight_code = false
|
||||
|
||||
# The theme to use for code highlighting.
|
||||
# See below for list of allowed values.
|
||||
highlight_theme = "base16-ocean-dark"
|
||||
|
||||
# When set to "true", emoji aliases translated to their corresponding
|
||||
# Unicode emoji equivalent in the rendered Markdown files. (e.g.: :smile: => 😄)
|
||||
render_emoji = false
|
||||
|
||||
# Configuration of the link checker.
|
||||
[link_checker]
|
||||
# Skip link checking for external URLs that start with these prefixes
|
||||
|
|
|
@ -15,13 +15,14 @@ base_url = "%BASE_URL%"
|
|||
# Whether to automatically compile all Sass files in the sass directory
|
||||
compile_sass = %COMPILE_SASS%
|
||||
|
||||
# Whether to build a search index to be used later on by a JavaScript library
|
||||
build_search_index = %SEARCH%
|
||||
|
||||
[markdown]
|
||||
# Whether to do syntax highlighting
|
||||
# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola
|
||||
highlight_code = %HIGHLIGHT%
|
||||
|
||||
# Whether to build a search index to be used later on by a JavaScript library
|
||||
build_search_index = %SEARCH%
|
||||
|
||||
[extra]
|
||||
# Put all your custom variables here
|
||||
"#;
|
||||
|
|
Loading…
Reference in a new issue