Migrate desktop reader parsing from Readability to Defuddle on HtmlUnit 5#1216
Merged
Conversation
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.
What
Replaces the desktop reader-mode content extractor. The old pipeline ran a customized Mozilla Readability fork plus Turndown inside HtmlUnit 4. This swaps it for Defuddle (the same library already used on Android and iOS), running on HtmlUnit 5, using Defuddle's native markdown converter.
Why
core-jsJS-engine updates that make running the modern Defuddle bundle feasible.How
4.21.0→5.1.0(gradle/libs.versions.toml).defuddle-full-es5.js— the Defuddle full build (it includes the markdown converter; the core build used on mobile does not) transpiled to ES5 with Babel, because HtmlUnit's Rhino-based engine can't parse the original ES2020 bundle (e.g.classsyntax). Regenerated from the same Defuddle version as the mobiledefuddle.jsbundle.defuddle-content-parser.js— wraps Defuddle withmarkdown: trueand the desktop-specific handling: banner-image removal, image dedup, relative→absolute URL resolution, and<iframe>stripping (HtmlUnit'sDOMParserNPEs on frames in a detached document).defuddle-content-parser.js:getComputedStyle/getBoundingClientRectreturn safe stubs — HtmlUnit throws uncatchable Java exceptions on these for elements in aDOMParser-created document (no enclosingWebWindow), and CSS is disabled in theWebClientanyway.querySelector/querySelectorAllrewrite the:scopepseudo-class (unsupported by HtmlUnit's CSS engine) and degrade any other unsupported selector to an empty result instead of throwing. Without this, a single:scopeselector aborted all of Defuddle's clutter removal and it fell back to returning the raw, junk-filled document — this was the root cause of the messy desktop output during development.DesktopFeedItemParserWorker.ktslimmed to mobile parity: only placeholder-image cleanup remains in Kotlin; the rest moved into the JS parser. Adds a debug-level log of the parsed title + content snippet.readability-es5.js,reader-content-parser.js,turndown-es5.js.Tests
DefuddleHtmlUnitTest— regression test running the full JS pipeline inside HtmlUnit, asserting markdown output (link conversion, no leftover HTML/script bodies).DefuddleDebugHarness— a manual diagnostic (no-ops without a local fixture) that prints Defuddle's debug log + resulting markdown for a given article; used to find the:scopefailure and handy for future Defuddle version bumps../gradlew detekt allTestspasses.Reviewer notes
defuddle.jsis updated.