Commit old unknown probably broken changes

Signed-off-by: trivernis <trivernis@protonmail.com>
feature/epub-rendering
trivernis 4 years ago
parent 77617f275f
commit 5554b6151c
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -89,6 +89,7 @@ pub struct Header {
pub(crate) size: u8, pub(crate) size: u8,
pub(crate) line: Line, pub(crate) line: Line,
pub(crate) anchor: String, pub(crate) anchor: String,
pub(crate) plain: String,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -508,11 +509,12 @@ impl Section {
} }
impl Header { impl Header {
pub fn new(content: Line, anchor: String) -> Self { pub fn new(content: Line, anchor: String, plain: String) -> Self {
Self { Self {
size: 0, size: 0,
anchor, anchor,
line: content, line: content,
plain,
} }
} }

@ -1,4 +1,5 @@
use epub_builder::{EpubBuilder, EpubContent, ReferenceType, Result, ZipLibrary}; use epub_builder::{EpubBuilder, EpubContent, ReferenceType, Result, ZipLibrary};
use htmlescape::{encode_attribute, encode_minimal};
use std::cmp::max; use std::cmp::max;
use std::collections::HashMap; use std::collections::HashMap;
use std::io; use std::io;
@ -18,13 +19,13 @@ impl Default for Buffer {
impl Read for Buffer { impl Read for Buffer {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let length = buf.len(); let written = buf.write(&self.inner[self.position..])?;
let available = self.inner.len();
let writable = max(length, available);
buf.copy_from_slice(&self.inner[0..writable]);
self.inner = self.inner[writable..self.inner.len()].to_vec();
Ok(writable) self.inner.reverse();
self.inner.truncate(self.inner.len() - written);
self.inner.reverse();
Ok(written)
} }
} }
@ -103,6 +104,14 @@ impl EpubWriter {
.append(&mut content.as_bytes().to_vec()); .append(&mut content.as_bytes().to_vec());
} }
pub fn escaped_content(&mut self, content: String) {
self.content(encode_minimal(content.as_str()));
}
pub fn escaped_attribute_content(&mut self, content: String) {
self.content(encode_attribute(content.as_str()));
}
/// Finishes writing the epub /// Finishes writing the epub
pub fn finish(&mut self) -> Result<()> { pub fn finish(&mut self) -> Result<()> {
self.builder.generate(&mut self.inner)?; self.builder.generate(&mut self.inner)?;

@ -2,7 +2,4 @@ use crate::format::epub::epub_writer::EpubWriter;
use std::io; use std::io;
pub mod epub_writer; pub mod epub_writer;
pub mod to_epub;
pub trait ToEpub {
fn to_epub(&self, writer: &EpubWriter) -> io::Result<()>;
}

@ -50,12 +50,15 @@ impl ParseLine for Parser {
let start_index = self.ctm.get_index(); let start_index = self.ctm.get_index();
let line = self.parse_line()?; let line = self.parse_line()?;
let mut anchor = String::new(); let mut anchor = String::new();
self.ctm.get_text()[start_index..self.ctm.get_index()] self.ctm.get_text()[start_index..self.ctm.get_index()]
.iter() .iter()
.for_each(|e| anchor.push(*e)); .for_each(|e| anchor.push(*e));
let plain = anchor.clone();
anchor.retain(|c| !c.is_whitespace()); anchor.retain(|c| !c.is_whitespace());
log::trace!("Line::Header"); log::trace!("Line::Header");
Ok(Header::new(line, anchor)) Ok(Header::new(line, anchor, plain))
} }
/// parses a single list item defined with - /// parses a single list item defined with -

Loading…
Cancel
Save