Skip to content

Fix renderer content loss in non-HTML renderers (markdown/plain/ansi)#246

Merged
dereuromark merged 1 commit into
masterfrom
fix/renderer-content-loss
Jun 16, 2026
Merged

Fix renderer content loss in non-HTML renderers (markdown/plain/ansi)#246
dereuromark merged 1 commit into
masterfrom
fix/renderer-content-loss

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

Problem

The non-HTML renderers (markdown / plain / ansi) silently dropped content that the HTML renderer rendered correctly:

  • EscapedText (e.g. an escaped literal such as a backslash-star) vanished in all three renderers. The node is not a Text subclass, so it fell through to renderChildren() and produced nothing.
  • MarkdownRenderer had no Figure / Caption arms, so a captioned image glued the caption directly onto the image (e.g. i.png)Cap), and no Abbreviation arm, so the abbreviation title was lost entirely.
  • A Div title attribute (set via Djot's attribute syntax, e.g. a quoted admonition title) was dropped in all three non-HTML renderers' renderDiv.

Fix

  • Add an explicit EscapedText arm in each renderer. Markdown keeps the leading backslash so the literal stays literal when re-parsed as Markdown; plain/ansi emit the raw content.
  • Add renderFigure (caption on its own block, with a blank line before the caption so it is not swallowed as a lazy continuation), renderCaption, and renderAbbreviation (inline abbr HTML, mirroring how subscript/superscript already fall back to inline HTML) to MarkdownRenderer.
  • Preserve a Div's title attribute as a leading bold/plain line in all three renderers, guarded on a non-empty title so it is a no-op when no title is present.

Ported from carve-php commit 217b72f. The two libraries share renderer architecture; the namespaces and node APIs differ (Carve\ vs Djot\). The Div-title test uses Djot's native attribute syntax title="..." (which genuinely populates the Div title attribute) rather than carve's admonition-specific syntax.

Tests

Added tests/TestCase/Renderer/RendererContentLossTest.php covering escaped text, abbreviation title, figure/caption separation, and Div title preservation across the affected renderers. Each assertion fails on the unpatched renderers and passes with the fix.

Content vanished in the markdown / plain / ansi renderers (HTML was fine):

- EscapedText (e.g. an escaped literal like a backslash-star) was dropped in
  all three: the node is not a Text subclass, so it fell through to
  renderChildren() and produced nothing. Added an explicit arm in each
  renderer. Markdown keeps the leading backslash so the literal stays literal
  when re-parsed; plain/ansi emit the raw content.
- MarkdownRenderer had no Figure / Caption arms, so a captioned image glued
  the caption to the image; and no Abbreviation arm, so the title was lost.
  Added renderFigure (caption on its own block), renderCaption, and
  renderAbbreviation (inline abbr HTML, mirroring how sub/sup fall back to
  inline HTML).
- A Div's title attribute (Djot attribute syntax title="...") was dropped in
  all three non-HTML renderers' renderDiv. Preserve it as a leading bold/plain
  line.

Ported from carve-php commit 217b72f.
@dereuromark dereuromark added the bug Something isn't working label Jun 16, 2026
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.10%. Comparing base (306e362) to head (391805c).

Files with missing lines Patch % Lines
src/Renderer/AnsiRenderer.php 83.33% 1 Missing ⚠️
src/Renderer/MarkdownRenderer.php 95.45% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #246      +/-   ##
============================================
+ Coverage     92.06%   92.10%   +0.04%     
- Complexity     3571     3590      +19     
============================================
  Files           107      107              
  Lines         10118    10152      +34     
============================================
+ Hits           9315     9351      +36     
+ Misses          803      801       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark dereuromark merged commit 39c56cc into master Jun 16, 2026
6 checks passed
@dereuromark dereuromark deleted the fix/renderer-content-loss branch June 16, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant