yuanflow-cli 0.1.32 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuanflow-cli",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "YuanFlow 自媒体 API CLI 与 Skill 安装器。",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -140,14 +140,64 @@ def build_theme_gallery(markdown: str, title: str, *, limit: int = 20) -> dict[s
140
140
  }
141
141
 
142
142
 
143
+ def _inline_style(styles: dict[str, Any], key: str, fallback: dict[str, str]) -> str:
144
+ configured = styles.get(key)
145
+ return _style(configured if isinstance(configured, dict) else fallback)
146
+
147
+
148
+ def _render_inline(text: str, styles: dict[str, Any]) -> str:
149
+ pattern = re.compile(
150
+ r"(`([^`]+)`|\*\*([^*\n]+)\*\*|__([^_\n]+)__|\*([^*\n]+)\*|_([^_\n]+)_|\[([^\]]+)\]\(([^)]+)\))"
151
+ )
152
+ output: list[str] = []
153
+ last = 0
154
+ for match in pattern.finditer(text):
155
+ output.append(html.escape(text[last : match.start()]))
156
+ code_text = match.group(2)
157
+ strong_text = match.group(3) or match.group(4)
158
+ emphasis_text = match.group(5) or match.group(6)
159
+ link_text = match.group(7)
160
+ link_href = match.group(8)
161
+ if code_text is not None:
162
+ style = _inline_style(
163
+ styles,
164
+ "inline_code",
165
+ {
166
+ "font_family": "Menlo,Consolas,monospace",
167
+ "background_color": "rgba(15,23,42,0.08)",
168
+ "border_radius": "4px",
169
+ "padding": "1px 4px",
170
+ },
171
+ )
172
+ output.append(f'<code style="{style}">{html.escape(code_text)}</code>')
173
+ elif strong_text is not None:
174
+ style = _inline_style(styles, "strong", {"font_weight": "700"})
175
+ output.append(f'<strong style="{style}">{html.escape(strong_text)}</strong>')
176
+ elif emphasis_text is not None:
177
+ style = _inline_style(styles, "em", {"font_style": "italic"})
178
+ output.append(f'<em style="{style}">{html.escape(emphasis_text)}</em>')
179
+ elif link_text is not None and link_href is not None:
180
+ style = _inline_style(
181
+ styles,
182
+ "a",
183
+ {"color": "#2563eb", "text_decoration": "underline"},
184
+ )
185
+ output.append(
186
+ f'<a href="{html.escape(link_href)}" style="{style}">{html.escape(link_text)}</a>'
187
+ )
188
+ last = match.end()
189
+ output.append(html.escape(text[last:]))
190
+ return "".join(output)
191
+
192
+
143
193
  def _paragraph(text: str, styles: dict[str, Any]) -> str:
144
- return f'<p style="{_style(styles.get("p", {}))}">{html.escape(text)}</p>'
194
+ return f'<p style="{_style(styles.get("p", {}))}">{_render_inline(text, styles)}</p>'
145
195
 
146
196
 
147
197
  def _render_list(items: list[str], ordered: bool, styles: dict[str, Any]) -> str:
148
198
  tag = "ol" if ordered else "ul"
149
199
  li_style = _style(styles.get("li", styles.get("p", {})))
150
- rendered = "".join(f'<li style="{li_style}">{html.escape(item)}</li>' for item in items)
200
+ rendered = "".join(f'<li style="{li_style}">{_render_inline(item, styles)}</li>' for item in items)
151
201
  return f'<{tag} style="{_style(styles.get(tag, {}))}">{rendered}</{tag}>'
152
202
 
153
203