fix(#1184): preserve button text in web read; remove button from STRIPPED_TAGS#1186
Open
SokandeSujal wants to merge 1 commit intojackwener:mainfrom
Open
fix(#1184): preserve button text in web read; remove button from STRIPPED_TAGS#1186SokandeSujal wants to merge 1 commit intojackwener:mainfrom
SokandeSujal wants to merge 1 commit intojackwener:mainfrom
Conversation
…from STRIPPED_TAGS
opencli web read was silently dropping all <button> elements because
'button' was unconditionally listed in STRIPPED_TAGS, which is passed
to TurndownService.remove() before HTML→Markdown conversion.
On many real-world pages (exam archives, dashboards, e-commerce) buttons
carry meaningful labels such as 'Download All' that agents and humans
need to see. The old behaviour also made web read inconsistent with
opencli browser state, which does surface button text.
Fix:
- Remove 'button' from STRIPPED_TAGS.
- Add a dedicated 'buttonElement' Turndown rule that preserves the
trimmed textContent of every <button> as inline Markdown text.
- Icon-only / purely decorative buttons whose trimmed text is empty are
silently dropped, keeping output clean.
- Buttons inside <form> are unaffected: the parent <form> is still in
STRIPPED_TAGS, so the entire form subtree is removed before Turndown
ever visits its children.
Tests:
- Updated the existing form-stripping test to use a more specific marker
('click-in-form') so it clearly tests the form-strips-children path.
- Added 'preserves standalone button text content as inline Markdown'
covering the reported Download All / Copy scenario.
- Added 'drops icon-only buttons that have no visible text' for the
empty-button edge case.
Fixes jackwener#1184
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
Fixes #1184
opencli web readwas silently stripping all<button>elements because'button'was listed in theSTRIPPED_TAGSarray, which is fed toTurndownService.remove()before HTML?Markdown conversion. On many real-world pages (exam archives, dashboards, e-commerce sites) buttons carry meaningful labels such as Download All that both humans and AI agents need to see in the output. This also madeweb readinconsistent withopencli browser state, which does surface button text.Root Cause
src/download/article-download.tslines 95-100:s const STRIPPED_TAGS = [ 'script', 'style', 'noscript', 'canvas', 'form', 'button', 'dialog', // ? unconditionally removes ALL buttons 'header', 'footer', 'nav', 'aside', ];sChanges
src/download/article-download.ts'button'fromSTRIPPED_TAGSbuttonElementTurndown rule that:textContentof every<button>as inline Markdown text<form>are unaffected - the parent<form>is still stripped, so children are never visitedsrc/download/article-download.test.tsclick-in-form) to make the assertion unambiguousDownload Allscenario from the issueTesting
All new and existing tests in
src/download/article-download.test.tscover the fix. The test environment on this machine runs Node 20 which cannot loadundici(requires Node ? 22); this is a pre-existing environment limitation unrelated to this change - confirmed identical error onmainbefore any changes.