Skip to content

dql/html: TextOf with a nodeFilter and support pre tag - #2673

Merged
xushiwei merged 3 commits into
goplus:mainfrom
xushiwei:q
Mar 17, 2026
Merged

xushiwei merged 3 commits into
goplus:mainfrom
xushiwei:q

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the HTML text extraction capabilities by introducing a flexible filtering mechanism and improving the handling of preformatted text. The changes allow for more precise control over which parts of the HTML document contribute to the extracted text and ensure that content within <pre> tags retains its original formatting, which is crucial for code snippets or other preformatted content.

Highlights

  • Node Filtering: Introduced a nodeFilter interface, allowing for selective inclusion or exclusion of HTML nodes during text extraction.
  • Verbatim Text Extraction: Implemented special handling for <pre> tags to ensure their content is extracted verbatim, preserving all whitespace and line breaks.
  • Generic Text Processing: Refactored the internal textOf function and textPrinter struct to be generic, accepting a nodeFilter type parameter for flexible customization.
  • New Public API: Added a new public TextOf function to the NodeSet type, providing access to the enhanced text extraction capabilities with node filtering and verbatim options.
  • Test Coverage: Updated existing test cases and added a new comprehensive test case to validate the correct verbatim extraction of content within <pre> tags.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • dql/html/html_test.go
    • Renamed the TestText function to TestTextOf.
    • Added a new test case named codeBody to specifically verify the verbatim text extraction from HTML content containing <pre> tags.
    • Updated the call to textOf to use the new generic signature textOf[noFilter](doc, false).
  • dql/html/text.go
    • Defined a new nodeFilter interface and a noFilter struct that implements it, providing a default pass-through filter.
    • Modified the textOf function and textPrinter struct to be generic, accepting a nodeFilter type parameter.
    • Introduced a printVerbatim method to textPrinter for appending text without collapsing whitespace.
    • Updated the printNode method to accept outer and verbatim boolean parameters, applying the nodeFilter and conditionally using printVerbatim for text nodes, especially within <pre> tags.
    • Adjusted the NodeSet.Text__1 method to call the updated textOf function with noFilter and false for the outer parameter.
    • Added a new public generic function TextOf[F nodeFilter](p NodeSet, outer bool) to NodeSet, allowing external callers to utilize the new filtering and verbatim text extraction features.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors the textOf function to be generic, allowing for node filtering during text extraction. It also adds support for preserving whitespace within <pre> tags. The changes look good and the new test cases cover the new functionality. However, I've found a critical issue with the generic filter implementation that could lead to a panic. I've left a detailed comment with a suggestion to address it by using a more conventional interface-based approach.

Comment thread dql/html/text.go
Comment thread dql/html/text.go Outdated
Comment thread dql/html/text.go
Comment thread dql/html/text.go Outdated
Comment thread dql/html/html_test.go
@fennoai

fennoai Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

The <pre> verbatim support and generics-based node filtering are well-implemented. The core text extraction logic is clean and performant — no security or performance concerns.

Main feedback: (1) The nodeFilter interface is unexported but constrains the exported TextOf — consider aligning visibility. (2) The filter instance in printNode should be a textPrinter field to avoid nil-panic risk with pointer types and enable stateful filters. (3) Test coverage for outer=true, the exported TextOf, and a non-trivial filter would strengthen confidence in the new code paths.

@codecov

codecov Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.11%. Comparing base (a6ad7dc) to head (f7af8cd).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2673   +/-   ##
=======================================
  Coverage   94.11%   94.11%           
=======================================
  Files          32       32           
  Lines        9969     9969           
=======================================
  Hits         9382     9382           
  Misses        419      419           
  Partials      168      168           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xushiwei
xushiwei merged commit 4bee9ee into goplus:main Mar 17, 2026
20 checks passed
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