""" Rooting Future - Content Formatter v1.0 Converts markdown content to styled HTML for webapp viewer """ import re import markdown from typing import Dict, Any import logging logger = logging.getLogger(__name__) class ContentFormatter: """Formatta contenuti piano strategico per webapp""" @staticmethod def format_section_content(content: str) -> str: """ Converte markdown in HTML formattato con: - Headers con anchor links - Bullet points stilizzati - Callout boxes per info importanti - Code blocks con syntax highlighting - Keyword badges """ if not content: return '

Sezione non disponibile

' # Strip whitespace content = content.strip() if len(content) < 20: return '

Sezione non disponibile

' try: # Convert markdown to HTML with extensions html = markdown.markdown( content, extensions=[ 'extra', # Tables, fenced code, etc. 'codehilite', # Syntax highlighting 'toc', # Table of contents 'tables', # GitHub-style tables 'nl2br', # Newline to
] ) # Add custom styling enhancements html = ContentFormatter._enhance_html(html) logger.debug(f"[FORMATTER] Formatted content: {len(content)} chars -> {len(html)} chars HTML") return html except Exception as e: logger.error(f"[FORMATTER] Error formatting content: {e}") # Fallback: wrap in paragraph tags return f'

{content}

' @staticmethod def _enhance_html(html: str) -> str: """Aggiunge classi CSS custom per styling avanzato""" # 1. Highlight priority headers (### PRIORITÀ, ### OBIETTIVI, etc.) html = re.sub( r'

(PRIORITÀ|OBIETTIVI|QUICK WINS|TOP \d+|MACRO \d+|STRATEGIA|PILASTRI|AZIONI)(.*?)

', r'

\1\2

', html, flags=re.IGNORECASE ) # 2. Style all bullet lists html = html.replace('