Handlers¶
Handlers turn an item given to add_content into HTML. See
Adding a content type to write one.
- class respysive.handlers.base.BaseHandler(content_instance)[source]¶
Bases:
ABCAbstract base class for content handlers.
All content handlers must inherit from this class and implement the abstract methods for content detection and processing.
- abstractmethod can_handle(content)[source]¶
Check if this handler can process the given content.
- Parameters:
content (
Any) – Content to check- Return type:
bool- Returns:
bool – True if this handler can process the content
- abstractmethod handle(content, shared_data_id=None, forced=False, **kwargs)[source]¶
Process the content and return HTML string.
- Parameters:
content (
Any) – Content to processshared_data_id (
str|None) – Optional shared data ID for Plotly chartsforced (
bool) – Whether content type detection was forcedkwargs – Additional styling and configuration options
- Return type:
str- Returns:
str – HTML string
- abstract property priority: int¶
Handler priority for content routing.
- Returns:
int – Priority value (lower number = higher priority)
- class respysive.handlers.ContentDetector[source]¶
Bases:
objectRoute content to the appropriate handler based on type detection.
Maintains a priority-sorted list of handlers. When processing content, each handler is tried in priority order until one matches. A content type can also be forced explicitly.
- register_handler(handler_class, content_instance)[source]¶
Register a new content handler.
- Parameters:
handler_class (
type[BaseHandler]) – Handler class to registercontent_instance – Content instance to pass to handler
- Return type:
None
- detect_and_handle(content, shared_data_id=None, content_type=None, **kwargs)[source]¶
Detect content type and delegate to appropriate handler.
- Parameters:
content (
Any) – Content to processshared_data_id (
str|None) – Optional shared data ID for Plotly chartscontent_type (
str|None) – Optional content type to force (‘plotly’, ‘matplotlib’, ‘maplibre’, ‘altair’, ‘image’, ‘video’, ‘latex’, ‘text’, ‘json’)kwargs – Additional styling and configuration options
- Return type:
str- Returns:
str – Processed HTML string
- get_handlers()[source]¶
Get list of registered handlers.
- Return type:
list[BaseHandler]- Returns:
List[BaseHandler] – List of handlers sorted by priority
Built-in handlers¶
- class respysive.handlers.PlotlyHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for Plotly charts and figures.
Accepts Plotly Figure objects, JSON strings, or dictionaries containing a
datalist and an optionallayoutdict. Delegates rendering to Content.add_plotly.Priority: 20.
- class respysive.handlers.AltairHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for Altair and Vega-Lite chart specifications.
Detects content containing a Vega-Lite schema URL and renders it using the vega-embed library.
Priority: 30.
- class respysive.handlers.MatplotlibHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for Matplotlib Figure objects.
Converts figures to inline SVG (or PNG) using the Content.add_fig method.
Priority: 10.
- class respysive.handlers.MappyngHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for mappyng
MapandInteractiveMapobjects.mappyng (https://github.com/fbxyz/mappyng) is an SVG-native cartographic library. Two object types are supported:
mappyng.interactive.InteractiveMap: produced byMap.to_interactive(...); embeds tooltips/hover JS in the SVG. Rendered via_repr_html_().mappyng.map.Map: static map. Rendered by callingto_string()to fetch the raw SVG.
Priority is set just above
HtmlReprHandlerso that mappyng objects are routed here explicitly rather than through the generic_repr_html_fallback.
- class respysive.handlers.MapLibreHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for MapLibre GL JS interactive maps.
Renders maps inside base64-encoded iframes to avoid RequireJS conflicts with Reveal.js. Supports markers, lines, circles, choropleth layers, legends, and OpenStreetMap tiles.
Priority: 8.
- class respysive.handlers.CustomJsonHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for custom library configurations loaded via CDN.
Processes dictionaries with
libraryandconfigkeys, generates container divs, loads CSS/JS from CDN, and runs initialization scripts.Priority: 5.
- class respysive.handlers.HtmlReprHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for objects with a _repr_html_() method.
Detects any object following the Jupyter _repr_html_ protocol (e.g. mappyng InteractiveMap, IPython.display.HTML, etc.) and embeds the returned HTML directly.
Priority: 8 (before MatplotlibHandler to catch InteractiveMap before it falls through to the matplotlib Figure check).
- class respysive.handlers.ImageHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for image files (local paths and URLs).
Detects image content by file extension. Supported formats: JPEG, PNG, GIF, TIFF, APNG, BMP, SVG, AVIF, WebP (incl. animated).
Priority: 40.
- class respysive.handlers.VideoHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for video files (local paths and URLs).
Detects video content by file extension. Supported formats: MP4, WebM, OGG/OGV, MOV, M4V. The video binary is embedded inline as a base64 data URI (see the size trade-off note on
respysive.content.Content.add_video()).Priority: 40 (same as the image handler). Video and image extensions do not overlap, so animated WebP files are still routed to the image handler.
- class respysive.handlers.LatexHandler(content_instance)[source]¶
Bases:
BaseHandlerHandler for text containing LaTeX math expressions or Markdown syntax.
Detects content with
$,$$,#,*,_, or[markers and processes them through the Markdown/LaTeX pipeline. Already-processed content (with MathJax delimiters) is skipped.Priority: 50.
- class respysive.handlers.TextHandler(content_instance)[source]¶
Bases:
BaseHandlerFallback handler for plain text and pre-processed HTML content.
Handles any content that no other handler matched. Detects whether the input already contains HTML or LaTeX markup and renders accordingly.
Priority: 100 (lowest — acts as fallback).