fix(report): draw North Indian charts from fences after skipHtml dropped SVG

Longform report pages kept the D1/D9/Moon and varga headings but skipHtml
stripped the engine's inline SVG. Emit a jyotish-chart JSON fence beside
each SVG and render a diamond chart on the reader without relaxing HTML
sanitization. BUG-607.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-09-09 15:11:00 +08:00
co-authored by Cursor
parent d5972ef44a
commit 2fdcb14fd6
23 changed files with 2628 additions and 124 deletions
+20 -2
View File
@@ -7,6 +7,7 @@
支持:D1(本命)/D9(Navamsa)/D10(Dasamsa)等分盘
"""
import re
from typing import Dict, List, Optional
SIGNS = ['Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo',
@@ -55,6 +56,21 @@ GRID_OFFSET_X = 50
GRID_OFFSET_Y = 50
SVG_WIDTH = GRID_OFFSET_X * 2 + CELL_SIZE * 4
SVG_HEIGHT = GRID_OFFSET_Y * 2 + CELL_SIZE * 4 + 60
_D_ID_RE = re.compile(r"\b(D\d{1,3})\b")
def _center_caption(title: str) -> tuple[str, str]:
"""Keep D1 as ``Rasi Chart / (D1)``; other titles follow the heading id."""
moon = bool(re.search(r"Moon", title, re.I))
match = _D_ID_RE.search(title or "")
chart_id = match.group(1) if match else None
if chart_id == "D1" and not moon:
return "Rasi Chart", "(D1)"
if moon:
return "Chart", "(Moon)"
if chart_id:
return "Chart", f"({chart_id})"
return "Chart", ""
def render_south_indian_chart(planets: Dict, asc_sign: str, title: str = "D1 — Rashi Chart") -> str:
@@ -117,8 +133,10 @@ def render_south_indian_chart(planets: Dict, asc_sign: str, title: str = "D1 —
# 中心区域(传统上写星盘信息)
cx = GRID_OFFSET_X + 1.5 * CELL_SIZE
cy = GRID_OFFSET_Y + 1.5 * CELL_SIZE
lines.append(f'<text x="{cx}" y="{cy-5}" text-anchor="middle" font-size="10" fill="#999">Rasi Chart</text>')
lines.append(f'<text x="{cx}" y="{cy+12}" text-anchor="middle" font-size="10" fill="#999">(D1)</text>')
caption, chart_id = _center_caption(title)
lines.append(f'<text x="{cx}" y="{cy-5}" text-anchor="middle" font-size="10" fill="#999">{caption}</text>')
if chart_id:
lines.append(f'<text x="{cx}" y="{cy+12}" text-anchor="middle" font-size="10" fill="#999">{chart_id}</text>')
lines.append('</svg>')
return '\n'.join(lines)