1
0
Fork 0
mirror of https://github.com/lise-henry/crowbook synced 2024-06-09 01:06:05 +02:00

Add rendering.roman_numerals option

This commit is contained in:
Elisabeth Henry 2016-12-21 13:03:13 +01:00
parent 340732ae47
commit cd160dd386
5 changed files with 17 additions and 3 deletions

View File

@ -55,6 +55,7 @@ crowbook-intl-runtime = "0.1"
caribon = { version = "0.7", optional = true }
clap = { version = "2", optional = true }
url = { version = "1", optional = true }
numerals = "0.1"
[dependencies.hyper]
version = "0.9"

View File

@ -33,6 +33,7 @@ rendering.num_depth: 2
rendering.initials: false
rendering.inline_toc: false
rendering.chapter_template: "{{{number}}}\\. {{{chapter_title}}}"
rendering.roman_numerals: true
# Html options
html.icon: crowbook.svg

View File

@ -19,7 +19,6 @@ use error::{Error, Result, Source};
use cleaner::{Cleaner, CleanerParams, French, Off, Default};
use bookoptions::BookOptions;
use parser::Parser;
use token::Token;
use epub::{Epub};
use html_single::{HtmlSingle, ProofHtmlSingle};
use html_dir::{HtmlDir, ProofHtmlDir};
@ -58,7 +57,7 @@ use crossbeam;
use mustache;
use mustache::{MapBuilder, Template};
use yaml_rust::{YamlLoader, Yaml};
use numerals::roman::Roman;
/// A Book.
///
@ -911,8 +910,18 @@ impl Book {
if !title.is_empty() {
data = data.insert_bool("has_chapter_title", true);
}
let number = if self.options.get_bool("rendering.roman_numerals").unwrap() == true {
if n <= 0 {
return Err(Error::render(Source::empty(),
lformat!("can not use roman numerals with zero or negative chapter numbers ({n})",
n = n)));
}
format!("{:X}", Roman::from(n as i16))
} else {
format!("{}", n)
};
data = data.insert_str("chapter_title", title)
.insert_str("number", format!("{}", n));
.insert_str("number", number);
let data = data.build();
let mut res: Vec<u8> = vec![];

View File

@ -38,6 +38,7 @@ rendering.inline_toc:bool:false # {inline_t
rendering.inline_toc.name:str:\"{{{{{{loc_toc}}}}}}\" # {toc_name}
rendering.num_depth:int:1 # {num_depth}
rendering.chapter_template:str:\"{{{{{{number}}}}}}\\\\. {{{{{{chapter_title}}}}}}\" # {chapter_template}
rendering.roman_numerals:bool:false # {roman_numerals}
# {special_ops}
import_config:path # {import_config}
@ -195,6 +196,7 @@ html.crowbook_link:alias # {removed}
toc_name = lformat!("Name of the table of contents if it is displayed in document"),
num_depth = lformat!("The maximum heading levels that should be numbered (0: no numbering, 1: only chapters, ..., 6: all)"),
chapter_template = lformat!("Naming scheme of chapters"),
roman_numerals = lformat!("If set to true, display chapter number with roman numeral"),
import_config = lformat!("Import another book configuration file"),

View File

@ -116,6 +116,7 @@ extern crate crossbeam;
extern crate crowbook_text_processing;
extern crate crowbook_intl_runtime;
extern crate term;
extern crate numerals;
#[macro_use]
extern crate lazy_static;