Showing
1 changed file
with
22 additions
and
4 deletions
| @@ -1602,10 +1602,28 @@ class HTMLRenderer: | @@ -1602,10 +1602,28 @@ class HTMLRenderer: | ||
| 1602 | 1602 | ||
| 1603 | def _build_css(self, tokens: Dict[str, Any]) -> str: | 1603 | def _build_css(self, tokens: Dict[str, Any]) -> str: |
| 1604 | """根据主题token拼接整页CSS,包括响应式与打印样式""" | 1604 | """根据主题token拼接整页CSS,包括响应式与打印样式""" |
| 1605 | - colors = tokens.get("colors") or {} | ||
| 1606 | - typography = tokens.get("typography") or {} | ||
| 1607 | - fonts = tokens.get("fonts") or typography.get("fontFamily") or {} | ||
| 1608 | - spacing = tokens.get("spacing") or {} | 1605 | + # 安全获取各个配置项,确保都是字典类型 |
| 1606 | + colors_raw = tokens.get("colors") | ||
| 1607 | + colors = colors_raw if isinstance(colors_raw, dict) else {} | ||
| 1608 | + | ||
| 1609 | + typography_raw = tokens.get("typography") | ||
| 1610 | + typography = typography_raw if isinstance(typography_raw, dict) else {} | ||
| 1611 | + | ||
| 1612 | + # 安全获取fonts,确保是字典类型 | ||
| 1613 | + fonts_raw = tokens.get("fonts") or typography.get("fonts") | ||
| 1614 | + if isinstance(fonts_raw, dict): | ||
| 1615 | + fonts = fonts_raw | ||
| 1616 | + else: | ||
| 1617 | + # 如果fonts是字符串或None,构造一个字典 | ||
| 1618 | + font_family = typography.get("fontFamily") | ||
| 1619 | + if isinstance(font_family, str): | ||
| 1620 | + fonts = {"body": font_family, "heading": font_family} | ||
| 1621 | + else: | ||
| 1622 | + fonts = {} | ||
| 1623 | + | ||
| 1624 | + spacing_raw = tokens.get("spacing") | ||
| 1625 | + spacing = spacing_raw if isinstance(spacing_raw, dict) else {} | ||
| 1626 | + | ||
| 1609 | primary_palette = self._resolve_color_family( | 1627 | primary_palette = self._resolve_color_family( |
| 1610 | colors.get("primary"), | 1628 | colors.get("primary"), |
| 1611 | {"main": "#1a365d", "light": "#2d3748", "dark": "#0f1a2d"}, | 1629 | {"main": "#1a365d", "light": "#2d3748", "dark": "#0f1a2d"}, |
-
Please register or login to post a comment