Skip to content

Commit fc76a47

Browse files
committed
Finish move of utils to mdbook-core
This updates everything for the move of utils to mdbook-core. There will be followup commits that will be moving and refactoring these utils. This simply moves them over unchanged (except visibility).
1 parent a224bfd commit fc76a47

31 files changed

+84
-56
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ rust-version = "1.85.0" # Keep in sync with installation.md and .github/workflow
2222

2323
[workspace.dependencies]
2424
anyhow = "1.0.98"
25+
log = "0.4.27"
2526
mdbook-core = { path = "crates/mdbook-core" }
27+
pulldown-cmark = { version = "0.10.3", default-features = false, features = ["html"] } # Do not update, part of the public api.
28+
regex = "1.11.1"
29+
tempfile = "3.20.0"
30+
toml = "0.5.11" # Do not update, see https://github.com/rust-lang/mdBook/issues/2037
2631

2732
[package]
2833
name = "mdbook"
@@ -50,18 +55,18 @@ clap_complete = "4.3.2"
5055
env_logger = "0.11.1"
5156
handlebars = "6.0"
5257
hex = "0.4.3"
53-
log = "0.4.17"
58+
log.workspace = true
5459
mdbook-core.workspace = true
5560
memchr = "2.5.0"
5661
opener = "0.8.1"
57-
pulldown-cmark = { version = "0.10.0", default-features = false, features = ["html"] } # Do not update, part of the public api.
58-
regex = "1.8.1"
62+
pulldown-cmark.workspace = true
63+
regex.workspace = true
5964
serde = { version = "1.0.163", features = ["derive"] }
6065
serde_json = "1.0.96"
6166
sha2 = "0.10.8"
6267
shlex = "1.3.0"
63-
tempfile = "3.4.0"
64-
toml = "0.5.11" # Do not update, see https://github.com/rust-lang/mdBook/issues/2037
68+
tempfile.workspace = true
69+
toml.workspace = true
6570
topological-sort = "0.2.2"
6671

6772
# Watch feature

crates/mdbook-core/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ rust-version.workspace = true
99

1010
[dependencies]
1111
anyhow.workspace = true
12+
log.workspace = true
13+
pulldown-cmark.workspace = true
14+
regex.workspace = true
15+
toml.workspace = true
16+
17+
[dev-dependencies]
18+
tempfile.workspace = true
1219

1320
[lints]
1421
workspace = true

crates/mdbook-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION");
1010
pub mod errors {
1111
pub use anyhow::{Error, Result};
1212
}
13+
pub mod utils;

crates/mdbook-core/src/utils/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn write_file<P: AsRef<Path>>(build_dir: &Path, filename: P, content: &[u8])
2929
///
3030
/// ```rust
3131
/// # use std::path::Path;
32-
/// # use mdbook::utils::fs::path_to_root;
32+
/// # use mdbook_core::utils::fs::path_to_root;
3333
/// let path = Path::new("some/relative/path");
3434
/// assert_eq!(path_to_root(path), "../../");
3535
/// ```

crates/mdbook-core/src/utils/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::sync::LazyLock;
1212

1313
pub mod fs;
1414
mod string;
15-
pub(crate) mod toml_ext;
15+
pub mod toml_ext;
1616

1717
pub use self::string::{
1818
take_anchored_lines, take_lines, take_rustdoc_include_anchored_lines,
@@ -424,7 +424,8 @@ pub fn log_backtrace(e: &Error) {
424424
}
425425
}
426426

427-
pub(crate) fn special_escape(mut s: &str) -> String {
427+
/// Escape characters to make it safe for an HTML string.
428+
pub fn special_escape(mut s: &str) -> String {
428429
let mut escaped = String::with_capacity(s.len());
429430
let needs_escape: &[char] = &['<', '>', '\'', '"', '\\', '&'];
430431
while let Some(next) = s.find(needs_escape) {
@@ -444,7 +445,8 @@ pub(crate) fn special_escape(mut s: &str) -> String {
444445
escaped
445446
}
446447

447-
pub(crate) fn bracket_escape(mut s: &str) -> String {
448+
/// Escape `<` and `>` for HTML.
449+
pub fn bracket_escape(mut s: &str) -> String {
448450
let mut escaped = String::with_capacity(s.len());
449451
let needs_escape: &[char] = &['<', '>'];
450452
while let Some(next) = s.find(needs_escape) {

crates/mdbook-core/src/utils/toml_ext.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
//! Helper for working with toml types.
2+
13
use toml::value::{Table, Value};
24

3-
pub(crate) trait TomlExt {
5+
/// Helper for working with toml types.
6+
pub trait TomlExt {
7+
/// Read a dotted key.
48
fn read(&self, key: &str) -> Option<&Value>;
9+
/// Read a dotted key for a mutable value.
510
fn read_mut(&mut self, key: &str) -> Option<&mut Value>;
11+
/// Insert with a dotted key.
612
fn insert(&mut self, key: &str, value: Value);
13+
/// Delete a dotted key value.
714
fn delete(&mut self, key: &str) -> Option<Value>;
815
}
916

src/book/book.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::path::{Path, PathBuf};
66

77
use super::summary::{Link, SectionNumber, Summary, SummaryItem, parse_summary};
88
use crate::config::BuildConfig;
9-
use crate::utils::bracket_escape;
109
use anyhow::{Context, Result};
1110
use log::debug;
11+
use mdbook_core::utils::bracket_escape;
1212
use serde::{Deserialize, Serialize};
1313

1414
/// Load a book into memory from its `src/` directory.

src/book/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::path::PathBuf;
55
use super::MDBook;
66
use crate::config::Config;
77
use crate::theme;
8-
use crate::utils::fs::write_file;
98
use anyhow::{Context, Result};
109
use log::{debug, error, info, trace};
10+
use mdbook_core::utils::fs::write_file;
1111

1212
/// A helper for setting up a new book and its directory structure.
1313
#[derive(Debug, Clone, PartialEq)]

src/book/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::preprocess::{
2727
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
2828
};
2929
use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer};
30-
use crate::utils;
30+
use mdbook_core::utils;
3131

3232
use crate::config::{Config, RustEdition};
3333

0 commit comments

Comments
 (0)