1
0
mirror of https://github.com/lise-henry/crowbook synced 2024-09-26 17:10:47 +02:00

Add epub.escape_nb_spaces option

This commit is contained in:
Elisabeth Henry 2016-12-30 17:48:58 +01:00
parent c0b2fd7e6a
commit 2e71354893
3 changed files with 43 additions and 2 deletions

View File

@ -77,6 +77,7 @@ epub.css:tpl # {epub_css}
epub.css.add:str # {epub_css_add}
epub.chapter.xhtml:tpl # {chapter_xhtml}
epub.toc.extras:bool:true # {epub_toc}
epub.escape_nb_spaces:bool:false # {nb_spaces}
# {tex_opt}
tex.links_as_footnotes:bool:true # {tex_links}

View File

@ -31,6 +31,7 @@ use book_renderer::BookRenderer;
use chrono;
use uuid;
use mustache::Template;
use crowbook_text_processing::escape;
use std::io::{Read, Write};
use std::convert::{AsRef, AsMut};
@ -552,6 +553,43 @@ impl<'a> EpubRenderer<'a> {
AsMut<HtmlRenderer<'a>>+AsRef<HtmlRenderer<'a>> + Renderer
{
match *token {
Token::Str(ref text) => {
let html: &mut HtmlRenderer = this.as_mut();
let content = if html.verbatim {
escape::html(text.as_ref())
} else {
escape::html(html.book.clean(text.as_ref(), false))
};
let mut content = if html.first_letter {
html.first_letter = false;
if html.book.options.get_bool("rendering.initials").unwrap() {
// Use initial
let mut chars = content.chars();
let initial = chars.next()
.ok_or(Error::parser(&html.book.source,
lformat!("empty str token, could not find \
initial")))?;
let mut new_content = if initial.is_alphanumeric() {
format!("<span class = \"initial\">{}</span>", initial)
} else {
format!("{}", initial)
};
for c in chars {
new_content.push(c);
}
Cow::Owned(new_content)
} else {
content
}
} else {
content
};
if html.book.options.get_bool("epub.escape_nb_spaces").unwrap() {
content = escape::nb_spaces(content);
}
Ok(content.into_owned())
},
Token::Header(1, ref vec) => {
{
let epub: &mut EpubRenderer = this.as_mut();

View File

@ -40,9 +40,11 @@ use caribon::Parser as Caribon;
/// Used by EpubRenderer, HtmlSingleRenderer, HtmlDirRenderer
pub struct HtmlRenderer<'a> {
table_head: bool,
verbatim: bool,
#[doc(hidden)]
pub verbatim: bool,
current_par: u32,
first_letter: bool,
#[doc(hidden)]
pub first_letter: bool,
first_paragraph: bool,
footnotes: Vec<(String, String)>,
filename: String,