""" Wizard widget system for embedding dynamic content in wizard steps. Widgets are inserted into markdown content using special syntax: {{ widget:recently_added_media }} {{ widget:recently_added_media limit=6 }} {{ widget:button url="https://example.com" text="Click Here" }} Cards use delimiter syntax: ||| # Card Title This is the card content with **markdown** support. ||| """ import logging import re from typing import Any import markdown from flask import render_template_string from app.services.media.service import get_media_client class WizardWidget: """Base class for wizard widgets.""" def __init__(self, name: str, template: str): self.name = name self.template = template def render(self, server_type: str, _context: dict | None = None, **kwargs) -> str: """Render the widget with given parameters.""" try: data = self.get_data(server_type, **kwargs) html_content = render_template_string(self.template, **data) # Wrap in markdown HTML block to ensure it's treated as raw HTML return f'\n\n
\n\n' except Exception: # Fail gracefully in wizard context return f'\n\n