Implement caption element for Slipstream#217
Merged
jverkoey merged 3 commits intoNov 4, 2025
Merged
Conversation
Add the Caption element to represent table captions in HTML. The Caption element follows the W3CElement protocol pattern used by other table elements and provides a SwiftUI-like interface for adding captions to tables. The implementation includes: - Caption.swift: Main element implementation using W3CElement protocol - CaptionTests.swift: Comprehensive tests covering empty blocks, text content, and attributes
Add a convenience initializer to Caption that accepts a String directly,
following the same pattern as H1 and other heading elements. This makes
the API more ergonomic for simple use cases.
Usage:
Caption("Products and Prices")
Instead of:
Caption { DOMString("Products and Prices") }
Updated documentation example to prefer the convenience initializer and
added test coverage for the new string literal initialization.
Caption, like other table elements (TableBody, TableHeader, etc.), renders with newlines and indentation. Updated test expectations to match this behavior: - withText(): expects multi-line output with newline before/after content - withStringLiteral(): expects multi-line output with newline before/after content This aligns with the rendering behavior of other W3CElement table components.
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.
Add the Caption element to represent table captions in HTML. The Caption element follows the W3CElement protocol pattern used by other table elements and provides a SwiftUI-like interface for adding captions to tables.
The implementation includes: