pub struct Html5Document {
pub(super) base: HtmlBase,
}Expand description
HTML document backed by the html5ever spec-compliant parser.
Handles HTML entities, void elements (<br>, <img>), and implicitly-
closed block tags correctly per the HTML5 spec. Node offsets are synthetic
(not byte positions in the source), so this type is not suitable for
persisting reading positions to disk. Use it for ephemeral rendering such
as the dictionary view.
For documents where offset accuracy matters (EPUB spine chapters, standalone
HTML files) use HtmlDocument instead.
Fields§
§base: HtmlBaseShared rendering state (tree, engine, page cache, stylesheets).
Implementations§
Source§impl Html5Document
impl Html5Document
Sourcepub fn new_from_memory(text: &str) -> Html5Document
pub fn new_from_memory(text: &str) -> Html5Document
Parses an in-memory HTML string using html5ever and returns a ready-to-render document.
Defaults to the dictionary viewer and user stylesheets; call
set_viewer_stylesheet and
set_user_stylesheet to override them.
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_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.
Trait Implementations§
Source§impl Document for Html5Document
impl Document for Html5Document
Source§fn dims(&self, _index: usize) -> Option<(f32, f32)>
fn dims(&self, _index: usize) -> Option<(f32, f32)>
Returns the current page dimensions in pixels as (width, height).
Source§fn pages_count(&self) -> usize
fn pages_count(&self) -> usize
Returns the byte length of the source content as a proxy for page count.
Source§fn toc(&mut self) -> Option<Vec<TocEntry>>
fn toc(&mut self) -> Option<Vec<TocEntry>>
Always returns None; the dictionary has no table of contents.
Source§fn chapter<'a>(
&mut self,
_offset: usize,
_toc: &'a [TocEntry],
) -> Option<(&'a TocEntry, f32)>
fn chapter<'a>( &mut self, _offset: usize, _toc: &'a [TocEntry], ) -> Option<(&'a TocEntry, f32)>
Always returns None; chapter metadata is not applicable.
Source§fn chapter_relative<'a>(
&mut self,
_offset: usize,
_dir: CycleDir,
_toc: &'a [TocEntry],
) -> Option<&'a TocEntry>
fn chapter_relative<'a>( &mut self, _offset: usize, _dir: CycleDir, _toc: &'a [TocEntry], ) -> Option<&'a TocEntry>
Always returns None; chapter-relative navigation is not applicable.
Source§fn lines(&mut self, _loc: Location) -> Option<(Vec<BoundedText>, usize)>
fn lines(&mut self, _loc: Location) -> Option<(Vec<BoundedText>, usize)>
Always returns None; line-level layout is not exposed.
Source§fn title(&self) -> Option<String>
fn title(&self) -> Option<String>
Always returns None; the dictionary does not expose a title.
Always returns None; the dictionary does not expose an author.
Source§fn save(&self, _path: &str) -> Result<(), Error>
fn save(&self, _path: &str) -> Result<(), Error>
No-op; Html5Document is always constructed from memory and has no
file path to save to.
fn resolve_location(&mut self, loc: Location) -> Option<usize>
fn words(&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 metadata(&self, key: &str) -> Option<String>
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 Html5Document
impl Sync for Html5Document
Auto Trait Implementations§
impl Freeze for Html5Document
impl RefUnwindSafe for Html5Document
impl Unpin for Html5Document
impl UnsafeUnpin for Html5Document
impl UnwindSafe for Html5Document
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