pi-cjk-markdown-fix

agent
Security Audit
Fail
Health Warn
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 6 GitHub stars
Code Fail
  • exec() — Shell command execution in transform.ts
Permissions Pass
  • Permissions — No dangerous permissions requested

No AI report is available for this listing yet.

SUMMARY

Pi coding agent extension that fixes raw ** / __ / * / _ markers in Chinese, Japanese and Korean replies when full-width punctuation sits inside bold or italic (e.g. **中文。**后文). Display-only: session data and model context stay unchanged. 修复 Pi 中 CJK 加粗/斜体显示原始星号的问题。

README.md

pi-cjk-markdown-fix

pi-cjk-markdown-fix is an extension for the Pi coding agent that fixes bold/italic text showing raw **, __, * or _ markers in Chinese, Japanese and Korean replies — e.g. **没有改动任何设置。**所有内容… — by moving the full-width punctuation outside the closing delimiter at display time only.

在 Pi 终端里,AI 回复的中文加粗/斜体如果把 。!? 等标点放在 ** 里面、后面又紧跟汉字,就会加粗不生效、显示成原始星号。本扩展只在显示层把标点移到强调符号外面,不改会话内容。

Problem / 问题

Some renderers show raw emphasis markers when CJK sentence punctuation is placed inside the closing delimiter and CJK text follows immediately. 某些渲染器在强调标记内包含中文标点、且后面紧接 CJK 字符时,会泄露原始标记。

**没有改动任何设置。**所有内容保持不变。

The extension normalizes the displayed Markdown to the equivalent of: 扩展会将显示用 Markdown 规范化为:

**没有改动任何设置**。所有内容保持不变。

Why it happens / 为什么会这样

CommonMark only lets a closing ** or * end emphasis if it is right-flanking. When the delimiter is preceded by punctuation (such as 。) and followed immediately by a non-whitespace, non-punctuation character (such as a Han character), it is not right-flanking, so the renderer cannot close the emphasis and prints the asterisks as-is. Text in English usually has a space after the punctuation, so it rarely triggers this; CJK text does not use spaces, so it triggers often. See the CommonMark spec. CommonMark 规定闭合强调符必须是 right-flanking:当 ** 前面是标点(如 。)、后面紧跟非空白非标点字符(如汉字)时,它不算 right-flanking,无法闭合,渲染器只能原样输出星号。中文、日文、韩文通常不在标点后加空格,因此更容易触发。

Behavior and scope / 行为与范围

  • Handles **, __, *, _, ***, and ___.
  • Moves only 。!?;:,、… plus supported full-width trailing closers when the delimiter is immediately followed by Han, Hiragana, Katakana, or Hangul text.
  • Runs only on finalized, non-streaming assistant messages.
  • Preserves fenced, inline, and indented code, escaped delimiters, line endings, unsupported punctuation, and unrelated unfinished Markdown.
  • 仅处理已完成、非流式的助手消息;代码区域、转义标记、换行和范围外内容保持不变。

Install / 安装

pi install git:github.com/ythx-101/pi-cjk-markdown-fix

Run /reload in an active Pi session, or restart Pi. 在已运行的 Pi 会话中执行 /reload,或重启 Pi。

Upgrade from a manual copy / 从手动安装升级

Before installing the package, remove or move any existing manual copy of ~/.pi/agent/extensions/cjk-markdown-fix. Loading both copies can register the transformer twice. 安装前请先移除或备份同名手动扩展,避免重复注册。

Temporary or source-checkout load / 临时或源码加载

Try the Git package for one run without changing settings: 不修改设置,临时试用 Git 包:

pi -e git:github.com/ythx-101/pi-cjk-markdown-fix

From a local source checkout: 从本地源码目录加载:

npm install
pi -e ./index.ts

Tests / 测试

Requires Node.js 22.19 or newer. 需要 Node.js 22.19 或更高版本。

npm install
npm test

All tests should pass (# fail 0). 所有测试应通过(# fail 0)。

The unit suite checks transformation boundaries and the render suite uses the locally installed Pi TUI development dependency. 单元测试覆盖转换边界,渲染测试使用本地安装的 Pi TUI 开发依赖。

Compatibility and limitations / 兼容性与限制

The package declares Pi's coding-agent API as a peer dependency. Renderer regression tests are pinned to @earendil-works/pi-tui 0.84.2; other renderer versions are not claimed as verified. This is a targeted repair, not a general Markdown parser: ASCII punctuation, non-CJK followers, links, and arbitrary malformed Markdown are outside its repair scope. Lines starting with four spaces or a tab are always skipped as indented code, so a nested list item or paragraph continuation indented that far may not be repaired (the result is left unchanged, never altered). 包声明 Pi coding-agent API 为对等依赖;渲染回归测试固定为 Pi TUI 0.84.2。它不是通用 Markdown 解析器,ASCII 标点、非 CJK 后继字符、链接及任意错误 Markdown 不在修复范围内。以四个空格或 Tab 开头的行一律按缩进代码跳过,因此缩进到这种程度的嵌套列表项或段落续行可能不会被修复(保持原样,不会被改坏)。

FAQ / 常见问题

Why is bold not rendering for **加粗。**后文 in Pi (raw asterisks shown)? / 为什么 Pi 里 **加粗。**后文 加粗不生效、显示星号?

See Why it happens. 见上文“为什么会这样”。

Does it change my session history or what the model sees? / 会改会话历史或模型看到的内容吗?

No. It only returns Markdown for display. 不会,只返回用于显示的 Markdown。

Why do I still see ** while the answer is streaming? / 流式输出时为什么还能看到 **?

Only finalized, non-streaming assistant messages are processed, so the fix applies once the message is complete. 只处理已完成的非流式助手消息,消息结束后才会修复。

Does it work for Japanese and Korean? / 支持日语和韩语吗?

Followers can be Hiragana, Katakana, or Hangul as well as Han. Only the listed full-width punctuation is moved; ASCII punctuation such as . and , is out of scope. 后继字符支持平假名、片假名、谚文和汉字;但只移动列出的全角标点,ASCII 的 .、, 等不在范围内。

Does it touch code blocks or my own messages? / 会动代码块或我自己的消息吗?

No. Fenced, inline, and indented code are preserved, and only assistant messages are processed (not user messages or assistant thinking). 不会:围栏、行内、缩进代码原样保留;只处理助手消息,不处理用户消息和 thinking。

Can I use it in VS Code, GitHub, or a website? / 能用在 VS Code、GitHub 或网页里吗?

No, this is a Pi extension. For your own markdown-it or remark pipeline, see the table below. 不能,这是 Pi 扩展;自建渲染管线请看下表。

I already copied it into ~/.pi/agent/extensions/ manually. / 我已手动复制到扩展目录怎么办?

Remove the manual copy before pi install, otherwise the transformer may be registered twice. See Upgrade from a manual copy. 先删除手动副本再 pi install,否则可能重复注册。

When to use / 适用场景与同类方案

Option / 方案 Suited for / 适合 Notes / 说明
This extension / 本扩展 Reading CJK AI replies in the Pi terminal / 在 Pi 终端里阅读中日韩回复 Display only; model output and session unchanged / 只改显示,不改模型输出与会话
Ask the model to put punctuation outside ** / 在提示词里要求模型把标点放到 ** 外 Any tool / 任何工具 The model may not comply / 模型不一定遵守
markdown-it-cjk-friendly, remark-cjk-friendly Your own markdown-it / remark pipeline / 自建的 markdown-it / remark 渲染管线 Change parsing rules; not applicable to the Pi terminal / 修改解析规则,不适用于 Pi 终端
Edit the text by hand / 手动改原文 One-off documents / 一次性文档 Not practical for ongoing chats / 不适合持续对话

Uninstall and rollback / 卸载与回滚

pi remove git:github.com/ythx-101/pi-cjk-markdown-fix

Then run /reload or restart Pi. To roll back to a previous manual copy, restore it only after removing the package, then reload. 随后执行 /reload 或重启;如需恢复旧手动版本,请先卸载包,再恢复备份并重新加载。

Security / 安全

At runtime, the extension performs no file, network, subprocess, timer, or settings operations. It only returns normalized display Markdown and does not edit session data or model context. 扩展运行时不执行文件、网络、子进程、定时器或设置操作;它只返回规范化后的显示文本,不修改会话数据或模型上下文。

License / 许可证

MIT

Reviews (0)

No results found