Description
CodeSnippet is an opinionated UI component with hardcoded inline styles, a fragile line-counting mechanism, and a specific visual layout. It does not belong in a low-level DOM library.
Problems:
- Hardcodes inline CSS (floats, borders, colors)
- Line number counting has bugs (accumulates on repeated
setCode() calls, off-by-one for empty input)
- No syntax highlighting — just plain text with numbers
- Any real project uses highlight.js, Prism, or Shiki instead
- Couples presentation decisions to infrastructure
Replacement (3 lines):
$pre = new HTMLNode('pre');
$code = $pre->addChild('code', ['class' => 'language-php']);
$code->text($sourceCode);
Proposed Change
- Mark
CodeSnippet class with @deprecated annotation
- Mark
HTMLNode::codeSnippet() shortcut method as @deprecated
- Remove both in next major version
Acceptance Criteria
@deprecated tag added to class and shortcut method
- No functional changes (still works for existing users)
- PHPDoc points to
<pre><code> pattern as replacement
Description
CodeSnippetis an opinionated UI component with hardcoded inline styles, a fragile line-counting mechanism, and a specific visual layout. It does not belong in a low-level DOM library.Problems:
setCode()calls, off-by-one for empty input)Replacement (3 lines):
Proposed Change
CodeSnippetclass with@deprecatedannotationHTMLNode::codeSnippet()shortcut method as@deprecatedAcceptance Criteria
@deprecatedtag added to class and shortcut method<pre><code>pattern as replacement