Skip to content

Handle comments and CDATA in HTML formatted text - #2129

Open
FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-html-dom-node-types
Open

FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-html-dom-node-types

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 9, 2026

Copy link
Copy Markdown

Summary

HTML treats every DOM node other than a text node as an element. Valid comments, processing instructions, and CDATA therefore raise AttributeError when their nonexistent attributes are read. For example, HTML('<b>Result: <!-- note --><![CDATA[x < 3]]></b>') cannot be printed.

Handle CDATA as text and process attributes/styles only for element nodes. Comments and processing instructions contribute no visible text. Existing nested element styling is preserved.

Ten regressions cover comments at the root and inside styled elements, processing instructions, literal markup in CDATA, mixed node types, restoration of surrounding styles, and actual print_formatted_text output. All ten fail with the original implementation and pass with this change.

Validation

On Linux with Python 3.12.14:

  • Pristine full suite: 156 passed, no skips or warnings.
  • Final full suite under coverage: 166 passed, no skips or warnings.
  • Ruff lint and format, standalone typos, strict mypy for Windows/Linux/macOS: passed.
  • All 12 repository pre-commit hooks passed on tracked files. The new regression file was also checked explicitly; applicable hooks passed (shebang/TOML hooks had no applicable files, and the repository excludes tests from its typos hook).
  • Wheel and sdist builds passed; both contain the exact tested implementation.
  • git diff --check passed.

The build reports setuptools' existing deprecated license-classifier warning. Other Python versions and native operating systems were not run locally; the mypy platform checks are static checks. Hosted CI is not claimed as passed.

AI assistance was used to prepare the implementation and regression tests.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 9, 2026 21:26
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