递归统计 block 列表中的 Chart.js 图表数量
(blocks)
| 64 | chapters = document_ir.get('chapters', []) |
| 65 | |
| 66 | def count_charts(blocks): |
| 67 | """递归统计 block 列表中的 Chart.js 图表数量""" |
| 68 | count = 0 |
| 69 | for block in blocks: |
| 70 | if isinstance(block, dict): |
| 71 | if block.get('type') == 'widget' and block.get('widgetType', '').startswith('chart.js'): |
| 72 | count += 1 |
| 73 | # 递归处理嵌套blocks |
| 74 | nested = block.get('blocks') |
| 75 | if isinstance(nested, list): |
| 76 | count += count_charts(nested) |
| 77 | return count |
| 78 | |
| 79 | for chapter in chapters: |
| 80 | blocks = chapter.get('blocks', []) |