Skip to content

docs(specs): markdown viewer raw-HTML <img> support (rendering + sizing) (GH13721) - #13656

Closed
fbartho wants to merge 6 commits into
warpdotdev:masterfrom
fbartho:fbartho/gh13652-markdown-img-sizing-spec
Closed

fbartho wants to merge 6 commits into
warpdotdev:masterfrom
fbartho:fbartho/gh13652-markdown-img-sizing-spec

Conversation

@fbartho

@fbartho fbartho commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Spec (product.md + tech.md, per CONTRIBUTING's spec-first workflow for feature requests) for teaching the Markdown viewer to recognize a block-level raw-HTML <img> tag and honor its width / height / align attributes.

Closes #13721 — the focused <img>-sizing issue split out of #13652 per maintainer guidance there. The other raw-HTML tags are tracked in their own sibling issues (#13725, #13726, #13732, #13733, #13734, #13735, #13736).

Why

Markdown image syntax gives authors no sizing control, and the viewer's default layout ignores an image's intrinsic dimensions — so locally generated SVG charts embedded in Markdown notes render at a small fixed size with no author-side remedy. The HTML width attribute is the only sizing signal an author can express; today it is silently dropped.

Highlights

  • <img> on its own line renders through the existing Markdown-image pipeline (markdown_parser → BufferBlockItem::Image → RenderableImage), following the field-threading precedent from specs/GH849/.
  • Sizing: absolute px (width="640"/"640px") and percentage (width="90%"), clamped to pane width; aspect ratio preserved when one dimension is given; align="left|center|right".
  • Sanitized by construction: only src/alt/title/width/height/align are read; onerror, onload, style, and all other attributes are ignored; no script execution or navigation. Malformed tags fall back to today's literal-text rendering — never a panic or a blank box.
  • No behavior change for documents without raw <img> tags; no change to default sizing when no attributes are present.

Process note

#13652 was closed in favor of per-feature issues; this spec now targets #13721 and the files moved to specs/GH13721/. Keeping this draft open and updated while #13721 awaits triage / ready-to-spec — happy to adjust if you'd rather sequence it differently.

Warp's Markdown viewer drops raw-HTML `<img>` tags, so there is no way to
size embedded images (the issue's motivating case: locally-generated SVG
dashboards embedded in notes). The Markdown-image renderer also draws every
image at a hardcoded default size, ignoring both intrinsic dimensions and any
author sizing signal.

This adds the product + tech spec for a scoped first slice of warpdotdev#13652:
recognize a block-level `<img>` tag and honor its width/height/align, threaded
through the existing FormattedImage -> BufferBlockItem::Image -> ImageBlockConfig
render path (mirroring the field-threading precedent in specs/GH849). The
broader raw-HTML subset (tables, details, anchors, kbd, picture, …) is left as
follow-ups under the same issue.
Issue warpdotdev#13652 (bulk raw-HTML-subset request) was closed and split into
focused per-tag issues. Move the spec to specs/GH13721/ and update
issue references to point at warpdotdev#13721, the focused <img> sizing issue.
@cla-bot cla-bot Bot added the cla-signed label Jul 14, 2026
@fbartho fbartho changed the title docs(specs): markdown viewer raw-HTML <img> sizing (GH13652) docs(specs): markdown viewer raw-HTML <img> sizing (GH13721) Jul 14, 2026
fbartho added a commit to fbartho/warp that referenced this pull request Jul 17, 2026
…v#13721 dependency (GH13736)

Applies adversarial-review fixes: re-anchors stale line references against
master (1dcbfdf); threads the candidate list through the BufferBlockItem
buffer layer that sits between the parser and the render model, so themed
picture blocks survive edit/copy/serialize round-trips; adds a TUI-surface
subsection documenting image_fallback() behavior and scoping live re-selection
out for the TUI; reframes live re-selection sequencing to state plainly that
no crates/editor subscriber to os_appearance_changed exists today, correcting
the prior draft's reliance on pending_mermaid_asset as a false precedent (it's
an async per-block asset swap, not an app-wide event fan-out) and promoting
the static-selection-first / live-swap-later split from a risk-mitigation
fallback to the primary sequencing plan; notes FormattedImage lacks
width/height/align fields until warpdotdev#13721 lands them; and adds a prominent
dependency note clarifying warpdotdev#13721 is itself an unmerged draft (PR warpdotdev#13656) so
only the fallback/sizing sections are at rebase risk, not the novel
source/media parsing, candidate-list model, or theme resolution work.
@fbartho fbartho changed the title docs(specs): markdown viewer raw-HTML <img> sizing (GH13721) docs(specs): markdown viewer raw-HTML <img> support (rendering + sizing) (GH13721) Jul 18, 2026
@fbartho
fbartho marked this pull request as ready for review July 18, 2026 21:13
@warp-for-oss

warp-for-oss Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm starting a first review of this spec-only pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This spec PR adds product and technical specs for rendering block-level raw-HTML <img> tags through the Markdown image pipeline, including width/height parsing, alignment, serialization, and validation coverage.

Concerns

  • The parser, sanitization, serialization, and regression-test coverage are mostly specified, and I found no separate security blocker. spec_context.md contains no approved implementation spec to compare against.
  • The layout plan does not yet resolve the core width-only/height-only aspect-ratio behavior promised by the product spec because it relies on an unspecified cap while acknowledging intrinsic image dimensions are unavailable at layout time.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread specs/GH13721/tech.md Resolved
Replace the unspecified 'generous cap' placeholder for width-only/
height-only image sizing with the concrete, already-shipped mechanism:
mermaid_diagram_size (edit.rs's sibling in mermaid_diagram.rs) already
derives ImageBlockConfig height/width from AssetCache's decoded
intrinsic size during layout, falling back to a plain default only
while the asset is still loading. <img> sizing adopts this pattern
verbatim instead of relying on contain()'s runtime scaling, which
never updates ImageBlockConfig or document-flow height.
@fbartho

fbartho commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

@warp-for-oss

warp-for-oss Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this spec-only pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This spec defines product and technical requirements for rendering block-level raw-HTML <img> tags in the Markdown viewer, including size attributes, alignment, sanitization, serialization, and validation coverage.

Concerns

  • The tech spec's single-dimension sizing plan relies on Image::contain() with a guessed cap for the unspecified dimension, but that does not guarantee the specified dimension will be honored without knowing the image's intrinsic aspect ratio or relayouting after decode.
  • The alignment plan does not specify how render/layout will carry both the available content width and the actual displayed image bounds, which are needed to implement left/center/right alignment without conflicting with the current image element's internal contain-centering behavior.

Verdict

Found: 0 critical, 2 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread specs/GH13721/tech.md Resolved
Comment thread specs/GH13721/tech.md Resolved
…ecify alignment mechanism

Finding 1: the Context section still framed Image::contain() as the
aspect-ratio-preservation mechanism, directly contradicting §4's
Mermaid-precedent fix (which explicitly says contain()/
layout_using_paint_bounds() 'looks like a shortcut but is not'). Clarify
that contain() only fit-scales within whatever box ImageBlockConfig
already is, and point to §4 as the single source of truth for how that
box becomes aspect-ratio-correct.

Finding 2: the alignment plan named only an ImageBlockConfig.align field
without specifying how layout carries available content width and
displayed image bounds, or how alignment interacts with contain()'s
internal centering. Ground the mechanism in the actual code:
RenderableImage::layout() constrains the primitive to exactly
config.width/height (SizeConstraint with size = config dims), so once
those are aspect-ratio-correct, contain() has zero internal slack to
center within. Positioned::image() today resolves its x-origin via the
generic bounds::content_origin (spacing.left_offset() only, no
per-instance offset) -- that's the gap align must close, one level up
from the primitive, with the same slack-splitting arithmetic as the
align-blocks spec (GH13735).
@fbartho

fbartho commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

Invariant 6 stated aspect-ratio derivation as 'the renderer already
scales by the smaller of the width/height ratios inside its layout box'
-- the same generic contain()-fit claim that f17165e already refuted
in the tech spec's §4 (contain() only fit-scales within a box that is
already the right shape; it does not derive that shape). f17165e
only touched tech.md, so this product.md claim was never swept. Point
invariant 6 at the tech spec's actual mechanism (AssetCache intrinsic-
size derivation, Mermaid precedent) instead of restating the disproven
generic-contain-fit explanation.
@warp-for-oss

warp-for-oss Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this spec-only pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds product and technical specs for rendering block-level raw-HTML <img> tags in the Markdown viewer, including width/height sizing, alignment, sanitization, serialization, and validation coverage.

Concerns

  • The proposed single-dimension sizing algorithm does not guarantee the requested width or height because contain() may still be constrained by the unspecified dimension's fallback cap.
  • Percentage dimensions need explicit clamping to the available bounds so oversized percentages cannot overflow the pane or contradict the stated clamped sizing behavior.

Verdict

Found: 0 critical, 2 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread specs/GH13721/tech.md Resolved
Comment thread specs/GH13721/tech.md Resolved
Round-3 Oz review found two residual gaps in the img sizing mechanism:
round-2's Mermaid-precedent fix derives the missing axis from intrinsic
size once decoded, but pre-decode the derived axis still fell back to a
plain default box rendered through contain(), which fit-scales by the
smaller width/height ratio and can shrink the specified axis below its
requested value for that one transient frame. Fix: render the
pre-decode fallback frame with stretch() instead of contain() so the
specified axis is never touched by fit-scaling in any load state, only
the derived axis is ever a guess.

Separately, percent width/height had no clamp at all (200% could
exceed the pane) while pixel sizing was already clamped, an
inconsistency between the two paths. Unify both into one
clamp_to_bound() rule shared by pixel and percent, both width and
height, with percentages clamped to [0, 100] before the multiply and
the result floored at 1px so a zero/negative percent can't yield a
blank image box.

Sibling sweep: added percentage-height clamping (the width fix's mirror
case), width-only vs height-only intrinsic-ratio derivation symmetry,
and a zero/near-zero available_width guard against a divide-by-zero or
clamp() panic in a pathologically narrow or nested container.
@fbartho

fbartho commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #13971 (same spec branch, fresh review budget — all prior review feedback is addressed in the branch head; markers on the threads here cite the commits).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown viewer: support <img> sizing attributes (width/height/align)

1 participant