Add option to disable section label in html (#533)
This commit is contained in:
parent
fd8f3bb415
commit
e825357848
|
@ -84,6 +84,9 @@ The following configuration options are available:
|
||||||
removing the current behaviour, you can specify a set of javascript files
|
removing the current behaviour, you can specify a set of javascript files
|
||||||
that will be loaded alongside the default one.
|
that will be loaded alongside the default one.
|
||||||
- **playpen:** A subtable for configuring various playpen settings.
|
- **playpen:** A subtable for configuring various playpen settings.
|
||||||
|
- **no-section-label**: mdBook by defaults adds section label in table of
|
||||||
|
contents column. For example, "1.", "2.1". Set this option to true to
|
||||||
|
disable those labels. Defaults to `false`.
|
||||||
|
|
||||||
**book.toml**
|
**book.toml**
|
||||||
```toml
|
```toml
|
||||||
|
|
|
@ -326,6 +326,7 @@ pub struct HtmlConfig {
|
||||||
/// This config item *should not be edited* by the end user.
|
/// This config item *should not be edited* by the end user.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub livereload_url: Option<String>,
|
pub livereload_url: Option<String>,
|
||||||
|
pub no_section_label: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration for tweaking how the the HTML renderer handles the playpen.
|
/// Configuration for tweaking how the the HTML renderer handles the playpen.
|
||||||
|
|
|
@ -239,8 +239,8 @@ impl HtmlHandlebars {
|
||||||
json!(utils::fs::path_to_root(Path::new("print.md"))));
|
json!(utils::fs::path_to_root(Path::new("print.md"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_hbs_helpers(&self, handlebars: &mut Handlebars) {
|
fn register_hbs_helpers(&self, handlebars: &mut Handlebars, html_config: &HtmlConfig) {
|
||||||
handlebars.register_helper("toc", Box::new(helpers::toc::RenderToc));
|
handlebars.register_helper("toc", Box::new(helpers::toc::RenderToc {no_section_label: html_config.no_section_label}));
|
||||||
handlebars.register_helper("previous", Box::new(helpers::navigation::previous));
|
handlebars.register_helper("previous", Box::new(helpers::navigation::previous));
|
||||||
handlebars.register_helper("next", Box::new(helpers::navigation::next));
|
handlebars.register_helper("next", Box::new(helpers::navigation::next));
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ impl Renderer for HtmlHandlebars {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
debug!("[*]: Register handlebars helpers");
|
debug!("[*]: Register handlebars helpers");
|
||||||
self.register_hbs_helpers(&mut handlebars);
|
self.register_hbs_helpers(&mut handlebars, &html_config);
|
||||||
|
|
||||||
let mut data = make_data(&ctx.root, &book, &ctx.config, &html_config)?;
|
let mut data = make_data(&ctx.root, &book, &ctx.config, &html_config)?;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@ use pulldown_cmark::{html, Event, Parser, Tag};
|
||||||
|
|
||||||
// Handlebars helper to construct TOC
|
// Handlebars helper to construct TOC
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct RenderToc;
|
pub struct RenderToc {
|
||||||
|
pub no_section_label: bool
|
||||||
|
}
|
||||||
|
|
||||||
impl HelperDef for RenderToc {
|
impl HelperDef for RenderToc {
|
||||||
fn call(&self, _h: &Helper, _: &Handlebars, rc: &mut RenderContext) -> Result<(), RenderError> {
|
fn call(&self, _h: &Helper, _: &Handlebars, rc: &mut RenderContext) -> Result<(), RenderError> {
|
||||||
|
@ -91,12 +93,14 @@ impl HelperDef for RenderToc {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !self.no_section_label {
|
||||||
// Section does not necessarily exist
|
// Section does not necessarily exist
|
||||||
if let Some(section) = item.get("section") {
|
if let Some(section) = item.get("section") {
|
||||||
rc.writer.write_all(b"<strong>")?;
|
rc.writer.write_all(b"<strong>")?;
|
||||||
rc.writer.write_all(section.as_bytes())?;
|
rc.writer.write_all(section.as_bytes())?;
|
||||||
rc.writer.write_all(b"</strong> ")?;
|
rc.writer.write_all(b"</strong> ")?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(name) = item.get("name") {
|
if let Some(name) = item.get("name") {
|
||||||
// Render only inline code blocks
|
// Render only inline code blocks
|
||||||
|
|
Loading…
Reference in New Issue