Skip to content

Commit

Permalink
Remove fn parse() from public API and replace with pub fn do_parse() …
Browse files Browse the repository at this point in the history
…method on Config

The parse function is an odd one in the current API, other functions
can be separated cleanly into functions that are convenient and functions
that need to be configured. The parse function does not advertise what
configuration it uses, and will silently drop css information, as it parses
with config::plain() as default configuration. This can lead to the following
misuse of the public API

let render_tree = parse(html)?;
customcfg.render_to_string(render_tree, 80)?;
  • Loading branch information
sftse committed Dec 16, 2024
1 parent e9786ac commit 0ec601f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,8 +2370,9 @@ pub mod config {
wrap_links: self.wrap_links,
}
}
/// Parse with context.
pub(crate) fn do_parse<R: io::Read>(&self, input: R) -> Result<RenderTree> {

/// Reads and parses HTML from `input` and prepares a render tree.
pub fn do_parse<R: io::Read>(&self, input: R) -> Result<RenderTree> {
let doc = self.parse_html(input)?;
self.dom_to_render_tree(&doc)
}
Expand Down Expand Up @@ -2660,11 +2661,6 @@ impl<D: TextDecorator> RenderedText<D> {
}
}

/// Reads and parses HTML from `input` and prepares a render tree.
pub fn parse(input: impl io::Read) -> Result<RenderTree> {
config::plain().do_parse(input)
}

/// Reads HTML from `input`, decorates it using `decorator`, and
/// returns a `String` with text wrapped to `width` columns.
pub fn from_read_with_decorator<R, D>(input: R, width: usize, decorator: D) -> Result<String>
Expand Down

0 comments on commit 0ec601f

Please sign in to comment.