|
|
@ -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)?;
|
|
|
|