Skip to content

Autoresearch r2 - #76

Merged
letmutex merged 5 commits into
mainfrom
autoresearch-r2
Jul 16, 2026
Merged

letmutex merged 5 commits into
mainfrom
autoresearch-r2

Conversation

@letmutex

@letmutex letmutex commented Jul 16, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Improved pure translation mode handling for spans and unsupported elements while preserving normalized content.
    • Preserved preformatted content when converting nested elements and delegated subtrees.
    • Improved rendering of links containing parentheses.
    • Fixed whitespace handling in ordered and unordered list items.
  • Tests
    • Added coverage for preformatted content preservation and delegated element handling.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The DOM walker adds Pure-mode early returns for eligible spans and unregistered elements, with math-span detection and normalized child content. Preformatted subtree behavior is tested, while anchor escaping and list-item trimming reduce intermediate allocations.

Pure-mode content handling

Layer / File(s) Summary
Pure-mode element traversal
src/dom_walker.rs
Pure-mode spans and unregistered tags walk children directly, trim applicable newlines, and append normalized content; math spans use explicit class detection.
Preformatted context propagation
src/element_handler/mod.rs, tests/basic_tests.rs
is_inside_pre becomes crate-visible, and tests verify nested and delegated subtrees inside <pre>.
Handler content and allocation updates
src/element_handler/anchor.rs, src/element_handler/li.rs
Anchor escaping accepts owned destinations and returns unchanged strings when possible; list-item leading whitespace is removed with drain.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DOM
  participant walk_node
  participant walk_children
  participant ContentBuffer
  DOM->>walk_node: visit element
  walk_node->>walk_children: traverse Pure-mode children
  walk_children-->>walk_node: child content
  walk_node->>ContentBuffer: append normalized content
Loading

Possibly related PRs

  • letmutex/htmd#59: Refactors the same DOM walker and handler invocation flow.
  • letmutex/htmd#60: Changes DOM walker handler-result and child-content processing.
  • letmutex/htmd#69: Adds related span math detection and document-whitespace handling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is too generic and does not describe the actual code changes in the pull request. Rename it to a concise, specific summary of the main change, such as the new translation-mode and preformatted-context handling.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch autoresearch-r2

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/dom_walker.rs (1)

148-156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make math span detection more robust.

The current check strictly requires exactly one attribute (class) and an exact string match. This is brittle and might skip valid math spans that happen to include additional attributes (such as id or aria-hidden) or reordered classes, causing them to be processed as normal spans.

Consider relaxing the check to search for the required classes across all attributes.

♻️ Proposed refactor
 fn is_math_span(attrs: &[html5ever::Attribute]) -> bool {
-    attrs.len() == 1
-        && attrs[0].name.local.as_ref() == "class"
-        && matches!(
-            attrs[0].value.as_ref(),
-            "math math-inline" | "math math-display"
-        )
+    attrs.iter().any(|attr| {
+        attr.name.local.as_ref() == "class" && {
+            let val = attr.value.as_ref();
+            val.contains("math-inline") || val.contains("math-display")
+        }
+    })
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/dom_walker.rs` around lines 148 - 156, Update is_math_span to inspect all
attributes for a class attribute containing both “math” and either “math-inline”
or “math-display”, regardless of attribute count or class ordering. Preserve
false for elements without the required class tokens.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/dom_walker.rs`:
- Around line 148-156: Update is_math_span to inspect all attributes for a class
attribute containing both “math” and either “math-inline” or “math-display”,
regardless of attribute count or class ordering. Preserve false for elements
without the required class tokens.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d54a9f38-36dd-4f0d-b1c6-4b4b45e25082

📥 Commits

Reviewing files that changed from the base of the PR and between a36f2d3 and b2c1243.

⛔ Files ignored due to path filters (1)
  • benches/results.tsv is excluded by !**/*.tsv
📒 Files selected for processing (5)
  • src/dom_walker.rs
  • src/element_handler/anchor.rs
  • src/element_handler/li.rs
  • src/element_handler/mod.rs
  • tests/basic_tests.rs

@letmutex
letmutex merged commit 44cb9b3 into main Jul 16, 2026
1 check passed
@letmutex
letmutex deleted the autoresearch-r2 branch July 16, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant