feat: remove nodes from html by default and allow data-llm to choose whether to remove nodes forcibly or not#4
Merged
Conversation
…whether to remove nodes forcibly or not
d05e445 to
f152aaa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors HTML element stripping from rigid boolean flags to a flexible array-based approach with attribute-level override controls using
data-llmannotations.Motivation
The previous implementation required hardcoded boolean parameters for each element type we wanted to strip (nav, aside, script), which didn't scale well and made the API inflexible. Users had no way to selectively keep specific instances of elements that would otherwise be stripped, and adding new element types required API changes.
Changes
Convert()now acceptselementsToStrip []*C.charinstead of separatestripNav,stripAside,stripScriptboolean parametersStripConfigstruct to useElementsToStrip []stringinstead of individual boolean fieldsdata-llm="keep"attribute to preserve elements that would normally be strippeddata-llm="drop"attribute to remove elements that would normally be keptheaderandfooterelements (nav, aside, script, style are no longer stripped by default)scripts/run-ffi-tests.sh)Features
Flexible Element Stripping
Pass any HTML element names you want stripped as an array instead of predefined flags.
Attribute-Based Overrides
data-llm="keep": Preserves an element even if its tag is in the strip listdata-llm="drop": Removes an element even if its tag is NOT in the strip listSimplified Defaults
Only
headerandfooterare stripped by default. All other elements (nav, aside, script, style) require explicit inclusion in the strip list.Usage
Go:
HTML with overrides:
Python FFI:
Testing
Added comprehensive test coverage:
TestProcessHTMLWithElementsToStrip- Verifies custom element strippingTestProcessHTMLWithDataLLMKeep- Verifies keep attribute behaviorTestProcessHTMLWithDataLLMDrop- Verifies drop attribute behavior