#!/usr/bin/env python3 """ Tab2内容生成器 - 段落结构 """ import html as html_module import re from typing import Dict, Any, List def extract_image_numbers(text: str) -> List[int]: """ 从文本中提取图片编号 Args: text: 包含图片编号的文本(如"图1"、"图片1"、"图2"或列表) Returns: 图片编号列表(从1开始) """ if not text: return [] # 使用正则表达式提取所有"图X"或"图片X"格式的编号 matches = re.findall(r'图片?(\d+)', str(text)) return [int(num) for num in matches] def render_images(text: str, images: List[str]) -> str: """ 根据文本中的图片编号渲染图片HTML Args: text: 包含图片编号的文本 images: 原始图片URL列表 Returns: 图片HTML字符串 """ image_numbers = extract_image_numbers(text) if not image_numbers or not images: return "" html = '\n' return html def render_paragraph_tree(paragraphs: List[Dict[str, Any]], level: int = 0, images: List[str] = None) -> str: """ 递归渲染段落树(支持展开/收起) Args: paragraphs: 段落列表 level: 层级深度 images: 原始图片URL列表 Returns: HTML字符串 """ if not paragraphs: return "" if images is None: images = [] html = f'\n' return html def generate_tab2_content(data: Dict[str, Any]) -> str: """生成Tab2内容:段落""" html = '\n' return html