Repository navigation
Move options from Element to Handlers - #64
Conversation
WalkthroughThis PR refactors option access patterns throughout the codebase by removing the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/element_handler/anchor.rs (1)
64-75: Centralized link options are correct; consider cachinghandlers.options()locallyReading
link_styleandlink_reference_stylefromhandlers.options()is correct and matches the new design. To avoid calling the virtualoptions()accessor twice and to make it clear both values come from the same snapshot, you could cache it in a local:- let md = match handlers.options().link_style { + let options = handlers.options(); + let md = match options.link_style { LinkStyle::Inlined => self.build_inlined_anchor(&content, link, title, false), LinkStyle::InlinedPreferAutolinks => { self.build_inlined_anchor(&content, link, title, true) } LinkStyle::Referenced => self.build_referenced_anchor( &content, link, title, - &handlers.options().link_reference_style, + &options.link_reference_style, ), };Functionality remains the same; this just tightens up the implementation.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
src/element_handler/anchor.rs(2 hunks)src/element_handler/br.rs(1 hunks)src/element_handler/code.rs(3 hunks)src/element_handler/element_util.rs(2 hunks)src/element_handler/headings.rs(1 hunks)src/element_handler/hr.rs(1 hunks)src/element_handler/html.rs(1 hunks)src/element_handler/li.rs(1 hunks)src/element_handler/list.rs(3 hunks)src/element_handler/mod.rs(3 hunks)src/element_handler/pre.rs(1 hunks)src/element_handler/table.rs(1 hunks)src/lib.rs(0 hunks)
💤 Files with no reviewable changes (1)
- src/lib.rs
🧰 Additional context used
🧬 Code graph analysis (3)
src/element_handler/html.rs (1)
src/node_util.rs (1)
get_parent_node(13-24)
src/element_handler/element_util.rs (2)
src/element_handler/mod.rs (2)
options(313-313)options(350-352)src/lib.rs (1)
options(171-174)
src/element_handler/mod.rs (1)
src/lib.rs (1)
options(171-174)
🔇 Additional comments (15)
src/element_handler/mod.rs (2)
368-378: Usinghandlers.options().translation_modeinblock_handleraligns with new options modelThe switch to
handlers.options().translation_modeinblock_handlerkeeps behavior equivalent while routing configuration consistently through theHandlersabstraction rather than per‑element state. No correctness issues spotted.
302-314:Handlerstrait addition is confirmed a public API breaking change; ensure semver bump and external auditThe
Handlerstrait is indeed publicly exported as part of the crate's API surface (pub mod element_handler;inlib.rs, withpub trait Handlersat line 302). Adding the requiredfn options(&self) -> &Options;method is a source-breaking change for any external crate implementingHandlers—they will fail to compile until they add this method.Within the codebase, only
ElementHandlersimplementsHandlers(at line 316), and it correctly implements the new method. The usage inblock_handleraligns with centralizing option access.Action: Confirm this breaking change is intentional and reflected in a semver major version bump and changelog entry. If not intentional, consider sealing the trait or making it private.
src/element_handler/br.rs (1)
11-14: BR style now sourced fromhandlers.options(); looks correctUsing
handlers.options().br_styleinstead of a per‑element options reference is consistent with the new design and preserves the existing TwoSpaces/Backslash behavior.src/element_handler/hr.rs (1)
10-14: HR style viahandlers.options().hr_styleis consistent and correctThe match on
handlers.options().hr_stylecleanly centralizes configuration without altering the Dashes/Asterisks/Underscores rendering semantics.src/element_handler/table.rs (1)
126-131: Faithful-mode gate now useshandlers.options(); behavior preservedThe condition
if handlers.options().translation_mode == TranslationMode::Faithful && !all_children_translated { // serialize element as HTML }is equivalent to the prior per‑element check but aligned with the global options access pattern. The fallback to raw HTML when any cell is not markdown‑translated remains correct.
src/element_handler/headings.rs (1)
16-24: Heading style selection viahandlers.options().heading_stylelooks goodUsing
handlers.options().heading_styleto choose Setext vs ATX for h1/h2 keeps behavior intact while matching the new centralized options approach. No issues here.src/element_handler/li.rs (1)
21-31: UL list item now respects global bullet options; looks correctUsing
handlers.options().bullet_list_markerand.ul_bullet_spacinginsideul_limatches the move to handler‑level options and preserves the existing bullet/spacing behavior.src/element_handler/code.rs (1)
18-30: Code handler option reads now go throughhandlers.options(); semantics unchangedThe three refactors here—
- Faithful-mode guard in
code_handlerusinghandlers.options().translation_mode,- Fenced vs indented code blocks and fence symbol selection using
handlers.options().code_block_style/.code_block_fence,- Inline code preformatting toggle using
handlers.options().preformatted_code,all correctly move configuration lookup to the
Handlersabstraction without altering behavior. The existing faithful-mode fallbacks and formatting logic remain intact.Also applies to: 52-57, 134-138
src/element_handler/pre.rs (1)
28-31: LGTM! Option access correctly refactored.The changes correctly replace
element.options.translation_modewithhandlers.options().translation_mode, maintaining the same logic for both the Pure mode check and the Faithful mode fallback serialization.src/element_handler/element_util.rs (2)
27-27: LGTM! Consistent refactoring for faithful mode check.The change correctly updates the translation mode check to use
handlers.options()instead ofelement.options, maintaining the same behavior for parent tag validation in faithful mode.
191-191: LGTM! Macro correctly updated for centralized option access.The
serialize_if_faithfulmacro is correctly updated to access translation mode viahandlers.options(). Since this macro is used across multiple handlers, this ensures consistent option access throughout the codebase.src/element_handler/list.rs (3)
14-14: LGTM! Faithful mode check correctly updated.The translation mode check is correctly refactored to use
handlers.options()for the faithful mode validation at the start of the list handler.
53-54: LGTM! Post-processing faithful check correctly updated.The faithful mode check after processing OL content is correctly refactored to use
handlers.options(), maintaining the same serialization fallback behavior.
125-130: LGTM! Options parameter correctly passed to helper function.The refactoring correctly passes
handlers.options()instead ofelement.optionstoadd_ol_li_marker, which expects a reference toOptionsfor computing list numbering and spacing.src/element_handler/html.rs (1)
14-21: LGTM! Translation mode checks correctly refactored.The
markdown_translatablelogic is correctly updated to access translation mode viahandlers.options()for both the Faithful mode check (line 14) and the Pure mode fallback (line 21), maintaining the same conditional behavior for HTML element translation.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.