What problem does it solve?
Components that receive HTML-rich text and image objects as props often render incorrectly, lose formatting, or lack accessibility semantics when handled as plain strings or naive image tags. This skill documents how to use the FormattedText and Image utilities from drupal-canvas to ensure HTML content is rendered safely and images are responsive, optimized, and accessible.
Core Features & Use Cases
- Safe rich text rendering: Use FormattedText for any prop with contentMediaType: text/html to preserve markup like paragraphs, links, and inline formatting while avoiding incorrect element choices.
- Responsive image handling: Use Image to automatically apply responsive behavior, optimization, and layout stability by leveraging src, alt, width, and height values.
- Practical example: Render a card component that displays a formatted description coming from props and an associated responsive image with proper alt text for accessibility.
Quick Start
Import FormattedText and Image from drupal-canvas and use FormattedText for props with contentMediaType: text/html while using Image with src, alt, width, and height to render responsive images.