Repository navigation
Add: provide an an interface to the DOM tree, in addition to a string of HTML. - #74
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/lib.rs (2)
105-121: Consider re-exportingNode(and related types) for API usability.The new public method returns
Rc<Node>, butNodeis not re-exported from this crate. Users wanting to manipulate the DOM tree before conversion would need to addmarkup5ever_rcdomas a direct dependency to accessNode,NodeData, etc.Consider adding a
pub usestatement to re-export the necessary types:pub use markup5ever_rcdom::Node;Additionally, the doc comment could be expanded to guide users on DOM manipulation and mention the dependency requirement if re-exporting is not desired.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib.rs` around lines 105 - 121, The public method html_to_tree returns Rc<Node> but Node (and related types like NodeData) are not re-exported, forcing consumers to depend on markup5ever_rcdom; add a public re-export (e.g., pub use markup5ever_rcdom::{Node, NodeData};) near the crate API surface so callers can use Node directly, and update the html_to_tree doc comment to note the returned type and how to manipulate the DOM (or, if you choose not to re-export, document the external dependency requirement instead).
123-142:tree_to_markdownis infallible but returnsResult.This method always returns
Ok(content)— there are no fallible operations. ReturningResultwhen failure is impossible can mislead callers into adding unnecessary error handling.However, keeping
Resultfor API consistency withconvert(and allowing for future fallible changes) is a reasonable trade-off. If this is intentional, consider adding a brief doc comment noting that theResultis for API consistency.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib.rs` around lines 123 - 142, The function tree_to_markdown currently returns std::io::Result<String> but never fails; either change its signature to return String (and update all callers / the convert API that expect Result) or, if you want to keep Result for API consistency with convert/future fallible behavior, add a brief doc comment to the tree_to_markdown method explaining that it currently always returns Ok but uses Result for consistency and potential future fallibility so callers need not expect real errors; update the function signature or add the doc comment near pub fn tree_to_markdown(&self, tree: &Rc<Node>) to reflect the chosen approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/lib.rs`:
- Around line 105-121: The public method html_to_tree returns Rc<Node> but Node
(and related types like NodeData) are not re-exported, forcing consumers to
depend on markup5ever_rcdom; add a public re-export (e.g., pub use
markup5ever_rcdom::{Node, NodeData};) near the crate API surface so callers can
use Node directly, and update the html_to_tree doc comment to note the returned
type and how to manipulate the DOM (or, if you choose not to re-export, document
the external dependency requirement instead).
- Around line 123-142: The function tree_to_markdown currently returns
std::io::Result<String> but never fails; either change its signature to return
String (and update all callers / the convert API that expect Result) or, if you
want to keep Result for API consistency with convert/future fallible behavior,
add a brief doc comment to the tree_to_markdown method explaining that it
currently always returns Ok but uses Result for consistency and potential future
fallibility so callers need not expect real errors; update the function
signature or add the doc comment near pub fn tree_to_markdown(&self, tree:
&Rc<Node>) to reflect the chosen approach.
Re-export `markup5ever_rcdom::RcDom`.
|
Thanks! |
This provides the
tree_to_markdown(&html_tree)function, which converts from a DOM tree to markdown just asconvert(&html_str)converts from HTML to markdown. It also provides thelet tree = html_to_tree(&html_str)utility to convert between HTML and a DOM tree. This allows library users to modify the DOM tree after parsing but before before transforming it to Markdown. Without this, users needs to manipulate the HTML must parse, transform the DOM, render to a string, then pass the string toconvert, which again parses the HTML.Summary by CodeRabbit