pub struct HtmlDocument {
text: String,
base: HtmlBase,
}Expand description
HTML document backed by the hand-rolled XmlParser.
Node offsets are exact byte positions in the source string, making this suitable for EPUB spine chapters and standalone HTML files where reading positions are persisted to disk as absolute byte offsets.
Fields§
§text: StringThe raw source text, retained so that Document::save can write it
back to disk unchanged.
base: HtmlBaseShared rendering state.
Implementations§
Source§impl HtmlDocument
impl HtmlDocument
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<HtmlDocument, Error>
pub fn new<P: AsRef<Path>>(path: P) -> Result<HtmlDocument, Error>
Opens the file at path, parses it with XmlParser, and returns a
ready-to-render document.
Sourcepub fn new_from_memory(text: &str) -> HtmlDocument
pub fn new_from_memory(text: &str) -> HtmlDocument
Parses an in-memory HTML string and returns a ready-to-render document.
The document has no parent directory, so relative resource references (images, linked stylesheets) will not be resolved.
Sourcepub fn update(&mut self, text: &str)
pub fn update(&mut self, text: &str)
Replaces the document content with a freshly parsed version of text
and clears the page cache.
Sourcepub fn set_margin(&mut self, margin: &Edge)
pub fn set_margin(&mut self, margin: &Edge)
Overrides the page margin. Clears the page cache.
Sourcepub fn set_font_size(&mut self, font_size: f32)
pub fn set_font_size(&mut self, font_size: f32)
Overrides the base font size in points. Clears the page cache.
Sourcepub fn set_viewer_stylesheet<P: AsRef<Path>>(&mut self, path: P)
pub fn set_viewer_stylesheet<P: AsRef<Path>>(&mut self, path: P)
Overrides the viewer stylesheet path. Clears the page cache.
Sourcepub fn set_user_stylesheet<P: AsRef<Path>>(&mut self, path: P)
pub fn set_user_stylesheet<P: AsRef<Path>>(&mut self, path: P)
Overrides the user stylesheet path. Clears the page cache.
Sourcepub fn categories(&self) -> Option<String>
pub fn categories(&self) -> Option<String>
Always returns None; category metadata is not embedded in HTML files.
Sourcepub fn description(&self) -> Option<String>
pub fn description(&self) -> Option<String>
Returns the content of <meta name="description"> if present.
Trait Implementations§
Source§impl Document for HtmlDocument
impl Document for HtmlDocument
fn dims(&self, _index: usize) -> Option<(f32, f32)>
fn pages_count(&self) -> usize
fn toc(&mut self) -> Option<Vec<TocEntry>>
fn chapter<'a>( &mut self, _offset: usize, _toc: &'a [TocEntry], ) -> Option<(&'a TocEntry, f32)>
fn chapter_relative<'a>( &mut self, _offset: usize, _dir: CycleDir, _toc: &'a [TocEntry], ) -> Option<&'a TocEntry>
fn resolve_location(&mut self, loc: Location) -> Option<usize>
fn words(&mut self, loc: Location) -> Option<(Vec<BoundedText>, usize)>
fn lines(&mut self, _loc: Location) -> Option<(Vec<BoundedText>, usize)>
fn images(&mut self, loc: Location) -> Option<(Vec<Boundary>, usize)>
fn links(&mut self, loc: Location) -> Option<(Vec<BoundedText>, usize)>
fn pixmap( &mut self, loc: Location, scale: f32, samples: usize, ) -> Option<(Pixmap, usize)>
fn layout(&mut self, width: u32, height: u32, font_size: f32, dpi: u16)
fn set_text_align(&mut self, text_align: TextAlign)
fn set_font_family(&mut self, family_name: &str, search_path: &str)
fn set_margin_width(&mut self, width: i32)
fn set_line_height(&mut self, line_height: f32)
fn set_hyphen_penalty(&mut self, hyphen_penalty: i32)
fn set_stretch_tolerance(&mut self, stretch_tolerance: f32)
fn set_ignore_document_css(&mut self, ignore: bool)
fn title(&self) -> Option<String>
fn metadata(&self, key: &str) -> Option<String>
fn save(&self, path: &str) -> Result<(), Error>
fn is_reflowable(&self) -> bool
fn has_synthetic_page_numbers(&self) -> bool
fn preview_pixmap( &mut self, width: f32, height: f32, samples: usize, ) -> Option<Pixmap>
impl Send for HtmlDocument
impl Sync for HtmlDocument
Auto Trait Implementations§
impl Freeze for HtmlDocument
impl RefUnwindSafe for HtmlDocument
impl Unpin for HtmlDocument
impl UnsafeUnpin for HtmlDocument
impl UnwindSafe for HtmlDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more