mirror of
https://github.com/lise-henry/crowbook
synced 2024-09-26 00:30:52 +02:00
Add html.highlight.theme, tex.highlight.theme and epub.highlight.theme options
This commit is contained in:
parent
78ab7a886b
commit
3730f275a7
@ -51,6 +51,7 @@ import:path # {import_config}
|
||||
|
||||
# {html_opt}
|
||||
html.icon:path # {html_icon}
|
||||
html.highlight.theme:str # {html_theme}
|
||||
html.header:str # {html_header}
|
||||
html.footer:str # {html_footer}
|
||||
html.css:tpl # {html_css}
|
||||
@ -74,6 +75,7 @@ html.dir.template:tpl # {html_dir_template}
|
||||
|
||||
# {epub_opt}
|
||||
epub.version:int:2 # {epub_ver}
|
||||
epub.highlight.theme:str # {epub_theme}
|
||||
epub.css:tpl # {epub_css}
|
||||
epub.css.add:str # {epub_css_add}
|
||||
epub.chapter.xhtml:tpl # {chapter_xhtml}
|
||||
@ -81,6 +83,7 @@ epub.toc.extras:bool:true # {epub_toc}
|
||||
epub.escape_nb_spaces:bool:true # {nb_spaces}
|
||||
|
||||
# {tex_opt}
|
||||
tex.highlight.theme:str # {tex_theme}
|
||||
tex.links_as_footnotes:bool:true # {tex_links}
|
||||
tex.command:str:xelatex # {tex_command}
|
||||
tex.template:tpl # {tex_tmpl}
|
||||
@ -286,6 +289,10 @@ html.crowbook_link:alias # {removed}
|
||||
prf_fuzzy_t = lformat!("Max threshold of differences to consider two strings a repetition"),
|
||||
prf_ignore = lformat!("Ignore proper nouns for repetitions"),
|
||||
prf_threshold = lformat!("Threshold to detect a repetition"),
|
||||
|
||||
tex_theme = lformat!("If set, set theme for syntax highlighting for LaTeX/PDF output (syntect only)"),
|
||||
html_theme = lformat!("If set, set theme for syntax highlighting for HTML output (syntect only)"),
|
||||
epub_theme = lformat!("If set, set theme for syntax highlighting for EPUB output (syntect only)"),
|
||||
|
||||
renamed = lformat!("Renamed"),
|
||||
removed = lformat!("Removed"),
|
||||
|
@ -56,7 +56,10 @@ pub struct EpubRenderer<'a> {
|
||||
impl<'a> EpubRenderer<'a> {
|
||||
/// Creates a new Epub renderer
|
||||
pub fn new(book: &'a Book) -> EpubRenderer<'a> {
|
||||
let mut html = HtmlRenderer::new(book);
|
||||
let mut html = HtmlRenderer::new(book,
|
||||
book.options
|
||||
.get_str("epub.highlight.theme")
|
||||
.unwrap_or_else(|_| book.options.get_str("rendering.highlight.theme").unwrap()));
|
||||
html.handler.set_images_mapping(true);
|
||||
html.handler.set_base64(false);
|
||||
EpubRenderer {
|
||||
|
@ -108,9 +108,9 @@ pub struct HtmlRenderer<'a> {
|
||||
}
|
||||
|
||||
impl<'a> HtmlRenderer<'a> {
|
||||
fn get_highlight(book: &Book) -> (Highlight, Option<Syntax>) {
|
||||
fn get_highlight(book: &Book, theme: &str) -> (Highlight, Option<Syntax>) {
|
||||
match book.options.get_str("rendering.highlight").unwrap() {
|
||||
"syntect" => (Highlight::Syntect, Some(Syntax::new(book))),
|
||||
"syntect" => (Highlight::Syntect, Some(Syntax::new(book, theme))),
|
||||
"none" => (Highlight::None, None),
|
||||
"highlight.js" => (Highlight::Js, None),
|
||||
value => {
|
||||
@ -122,8 +122,8 @@ impl<'a> HtmlRenderer<'a> {
|
||||
}
|
||||
|
||||
/// Creates a new HTML renderer
|
||||
pub fn new(book: &'a Book) -> HtmlRenderer<'a> {
|
||||
let (highlight, syntax) = Self::get_highlight(book);
|
||||
pub fn new(book: &'a Book, theme: &str) -> HtmlRenderer<'a> {
|
||||
let (highlight, syntax) = Self::get_highlight(book, theme);
|
||||
|
||||
let mut html = HtmlRenderer {
|
||||
book: book,
|
||||
|
@ -47,7 +47,10 @@ pub struct HtmlDirRenderer<'a> {
|
||||
impl<'a> HtmlDirRenderer<'a> {
|
||||
/// Creates a new HtmlDirRenderer
|
||||
pub fn new(book: &'a Book) -> HtmlDirRenderer<'a> {
|
||||
let mut html = HtmlRenderer::new(book);
|
||||
let mut html = HtmlRenderer::new(book,
|
||||
book.options
|
||||
.get_str("epub.highlight.theme")
|
||||
.unwrap_or_else(|_| book.options.get_str("rendering.highlight.theme").unwrap()));
|
||||
html.handler.set_images_mapping(true);
|
||||
html.handler.set_base64(false);
|
||||
HtmlDirRenderer { html: html }
|
||||
|
@ -41,7 +41,10 @@ pub struct HtmlSingleRenderer<'a> {
|
||||
impl<'a> HtmlSingleRenderer<'a> {
|
||||
/// Creates a new HtmlSingleRenderer
|
||||
pub fn new(book: &'a Book) -> HtmlSingleRenderer<'a> {
|
||||
let mut html = HtmlRenderer::new(book);
|
||||
let mut html = HtmlRenderer::new(book,
|
||||
book.options
|
||||
.get_str("html.highlight.theme")
|
||||
.unwrap_or_else(|_| book.options.get_str("rendering.highlight.theme").unwrap()));
|
||||
html.handler.set_images_mapping(true);
|
||||
html.handler.set_base64(true);
|
||||
HtmlSingleRenderer { html: html }
|
||||
|
@ -57,7 +57,10 @@ impl<'a> LatexRenderer<'a> {
|
||||
let mut handler = ResourceHandler::new(&book.logger);
|
||||
handler.set_images_mapping(true);
|
||||
let syntax = if book.options.get_str("rendering.highlight").unwrap() == "syntect" {
|
||||
Some(Syntax::new(book))
|
||||
Some(Syntax::new(book,
|
||||
book.options
|
||||
.get_str("tex.highlight.theme")
|
||||
.unwrap_or_else(|_| book.options.get_str("rendering.highlight.theme").unwrap())))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -37,9 +37,8 @@ pub struct Syntax {}
|
||||
#[cfg(feature="syntect")]
|
||||
impl Syntax {
|
||||
/// Creates a new Syntax wrapper
|
||||
pub fn new(book: &Book) -> Syntax {
|
||||
pub fn new(book: &Book, theme_name: &str) -> Syntax {
|
||||
let mut theme_set = syntect::highlighting::ThemeSet::load_defaults();
|
||||
let theme_name = book.options.get_str("rendering.highlight.theme").unwrap();
|
||||
let theme = match theme_set.themes.remove(theme_name) {
|
||||
Some(theme) => theme,
|
||||
None => {
|
||||
@ -113,7 +112,7 @@ impl Syntax {
|
||||
|
||||
#[cfg(not(feature="syntect"))]
|
||||
impl Syntax {
|
||||
pub fn new(book: &Book) -> Syntax {
|
||||
pub fn new(book: &Book, _: &str) -> Syntax {
|
||||
book.logger.error(lformat!("crowbook was compiled without syntect support, syntax highlighting will be disabled"));
|
||||
Syntax {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user