Relationship with teal_card
The teal_card class is a central component in the teal.reporter ecosystem. It is an S3 list
where each element represents a piece of report content (text, plots, tables, code chunks, etc.).
The toHTML method for teal_card objects:
Iterates through each element in the teal_card list
Calls toHTML() recursively on each element based on its class
Wraps all converted elements in a bslib::card() container
This hierarchical conversion allows complex report structures to be rendered as styled HTML
with proper formatting for each content type.
Content Type Conversions
Text and Markdown: Character strings are converted to HTML using CommonMark markdown syntax.
Supports headers, lists, code blocks, emphasis, and other markdown features.
Code Chunks: Created with code_chunk(), these are rendered as collapsible Bootstrap
accordions with syntax highlighting. The accordion includes the programming language indicator
and an icon.
Plots: Plot objects (ggplot, recordedplot, trellis, grob) are converted to PNG
images with base64-encoded data URIs, making them self-contained in the HTML output.
Tables: Table objects are converted to styled HTML tables, typically via flextable
for consistent formatting.
Viewer Integration
All HTML output is wrapped with htmltools::browsable(), which enables:
Automatic render in IDE Viewer when displayed interactively
Proper HTML dependency injection (Bootstrap CSS/JavaScript, Font Awesome icons, etc.)
Standalone HTML files with all required resources
You can override the browsable behavior with:
print(toHTML(x), browse = FALSE) # Print markup to console instead