Skip to content

Commit fb25e5a

Browse files
committed
Add configuration option to disable the default hidelines feature for rust
1 parent 4e41c84 commit fb25e5a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

crates/mdbook-core/src/config.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,25 @@ impl Default for Playground {
605605
}
606606

607607
/// Configuration for tweaking how the HTML renderer handles code blocks.
608-
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
608+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
609609
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
610610
#[non_exhaustive]
611611
pub struct Code {
612+
/// Enable or disable the default line hiding with '#' for rust. Default: `true`.
613+
pub default_hidelines: bool,
612614
/// A prefix string to hide lines per language (one or more chars).
613615
pub hidelines: HashMap<String, String>,
614616
}
615617

618+
impl Default for Code {
619+
fn default() -> Code {
620+
Code {
621+
default_hidelines: true,
622+
hidelines: HashMap::<String, String>::default(),
623+
}
624+
}
625+
}
626+
616627
/// Configuration of the search functionality of the HTML renderer.
617628
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
618629
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]

crates/mdbook-html/src/html/hide_lines.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub(crate) fn hide_lines(
1111
tree: &mut Tree<Node>,
1212
code_id: NodeId,
1313
hidelines: &HashMap<String, String>,
14+
default_hidelines: bool,
1415
) {
1516
let mut node = tree.get_mut(code_id).unwrap();
1617
let el = node.value().as_element().unwrap();
@@ -31,7 +32,7 @@ pub(crate) fn hide_lines(
3132
if let Some(mut child) = node.first_child()
3233
&& let Node::Text(text) = child.value()
3334
{
34-
if language == "rust" {
35+
if language == "rust" && default_hidelines {
3536
let new_nodes = hide_lines_rust(text);
3637
child.detach();
3738
let root = tree.extend_tree(new_nodes);

crates/mdbook-html/src/html/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ where
930930
}
931931

932932
for code_id in code_ids {
933-
hide_lines(&mut self.tree, code_id, &self.options.config.code.hidelines);
933+
hide_lines(&mut self.tree, code_id, &self.options.config.code.hidelines, self.options.config.code.default_hidelines);
934934
}
935935
}
936936

0 commit comments

Comments
 (0)