Skip to content

Commit 09c3e54

Browse files
committed
Move take_lines functions to mdbook-driver and make private
These functions are only used by the links preprocessor. I'm moving these functions to put them closer to the code that they are associated with, and to reduce the public API surface.
1 parent 9fae3c8 commit 09c3e54

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ use tracing::error;
66

77
pub mod fs;
88
mod html;
9-
mod string;
109
mod toml_ext;
1110

1211
pub(crate) use self::toml_ext::TomlExt;
1312

1413
pub use self::html::{escape_html, escape_html_attribute};
15-
pub use self::string::{
16-
take_anchored_lines, take_lines, take_rustdoc_include_anchored_lines,
17-
take_rustdoc_include_lines,
18-
};
1914

2015
/// Defines a `static` with a [`regex::Regex`].
2116
#[macro_export]

crates/mdbook-driver/src/builtin_preprocessors/links.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
use anyhow::{Context, Result};
2-
use mdbook_core::book::{Book, BookItem};
3-
use mdbook_core::static_regex;
4-
use mdbook_core::utils::{
1+
use self::take_lines::{
52
take_anchored_lines, take_lines, take_rustdoc_include_anchored_lines,
63
take_rustdoc_include_lines,
74
};
5+
use anyhow::{Context, Result};
6+
use mdbook_core::book::{Book, BookItem};
7+
use mdbook_core::static_regex;
88
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
99
use regex::{CaptureMatches, Captures};
1010
use std::fs;
1111
use std::ops::{Bound, Range, RangeBounds, RangeFrom, RangeFull, RangeTo};
1212
use std::path::{Path, PathBuf};
1313
use tracing::{error, warn};
1414

15+
mod take_lines;
16+
1517
const ESCAPE_CHAR: char = '\\';
1618
const MAX_LINK_NESTED_DEPTH: usize = 10;
1719

crates/mdbook-core/src/utils/string.rs renamed to crates/mdbook-driver/src/builtin_preprocessors/links/take_lines.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::static_regex;
1+
use mdbook_core::static_regex;
22
use std::ops::Bound::{Excluded, Included, Unbounded};
33
use std::ops::RangeBounds;
44

55
/// Take a range of lines from a string.
6-
pub fn take_lines<R: RangeBounds<usize>>(s: &str, range: R) -> String {
6+
pub(super) fn take_lines<R: RangeBounds<usize>>(s: &str, range: R) -> String {
77
let start = match range.start_bound() {
88
Excluded(&n) => n + 1,
99
Included(&n) => n,
@@ -28,7 +28,7 @@ static_regex!(ANCHOR_END, r"ANCHOR_END:\s*(?P<anchor_name>[\w_-]+)");
2828

2929
/// Take anchored lines from a string.
3030
/// Lines containing anchor are ignored.
31-
pub fn take_anchored_lines(s: &str, anchor: &str) -> String {
31+
pub(super) fn take_anchored_lines(s: &str, anchor: &str) -> String {
3232
let mut retained = Vec::<&str>::new();
3333
let mut anchor_found = false;
3434

@@ -60,7 +60,7 @@ pub fn take_anchored_lines(s: &str, anchor: &str) -> String {
6060
/// For any lines not in the range, include them but use `#` at the beginning. This will hide the
6161
/// lines from initial display but include them when expanding the code snippet or testing with
6262
/// rustdoc.
63-
pub fn take_rustdoc_include_lines<R: RangeBounds<usize>>(s: &str, range: R) -> String {
63+
pub(super) fn take_rustdoc_include_lines<R: RangeBounds<usize>>(s: &str, range: R) -> String {
6464
let mut output = String::with_capacity(s.len());
6565

6666
for (index, line) in s.lines().enumerate() {
@@ -78,7 +78,7 @@ pub fn take_rustdoc_include_lines<R: RangeBounds<usize>>(s: &str, range: R) -> S
7878
/// For any lines not between the anchors, include them but use `#` at the beginning. This will
7979
/// hide the lines from initial display but include them when expanding the code snippet or testing
8080
/// with rustdoc.
81-
pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String {
81+
pub(super) fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String {
8282
let mut output = String::with_capacity(s.len());
8383
let mut within_anchored_section = false;
8484

0 commit comments

Comments
 (0)