11 Commits

Author SHA1 Message Date
xfy
77a22bbfb1 feat(editor): tiptap 代码块 mermaid 实时预览
mermaid 代码块( ```mermaid )在富文本编辑器里此前只是普通源码,作者看不到
渲染效果。现在像数学公式、脚注一样在编辑器内直接预览:源码下方加预览区,
debounce 500ms 后渲染成 SVG,跟随站点 light/dark 主题切换,与前台文章页
渲染视觉完全一致。

一致性保证(核心):
- 同一份 mermaid 运行时:编辑器与前台都加载 /mermaid/mermaid.js(11.16.0)
- 同一套主题变量:经 @yggdrasil/shared 单一真相源(上一提交下沉)
- 同一份渲染配置:theme:'base' + securityLevel:'strict' + flowchart.curve:'basis'
- 同一主题切换机制:监听 THEME_CHANGE_EVENT(与 codemirror-editor 同范式)

实现:
- mermaid.ts:加载 bundle + renderMermaid(source, theme) 封装,与前台同逻辑
- code-block-view.ts:mermaid 块构造时建预览区;源码变化 debounce 重渲染;
  renderToken 防竞态(快速改动只保留最新);主题事件重渲染;language 切入/切出
  mermaid 时创建/移除预览区;destroy 清理 timer+监听+token
- 渲染失败显示错误态(accent 色左边框),源码仍可编辑修正
- 样式对齐前台 pre[data-mermaid-rendered]:flex 居中、SVG 等比缩放、Latte/Mocha 双主题
- 测试 mock mermaid 运行时,覆盖预览区生命周期、debounce、竞态、主题、错误、清理

服务端 markdown.rs / Dioxus.toml / Rust-JS 桥零改动。
2026-07-23 15:13:07 +08:00
xfy
5dceb39544 feat(editor): 数学公式节点带 KaTeX 预览,根治编辑器序列化破坏 LaTeX
问题:经 Tiptap 编辑器保存的数学公式,矩阵/分段函数等服务端 KaTeX 渲染失败。
根因:@tiptap/markdown 的 MarkdownManager.encodeTextForMarkdown 对所有非代码
文本节点做 escapeMarkdownSyntax + encodeHtmlEntities,把 LaTeX 的 \→\\、
_→\_、&→&。编辑器内公式走普通文本路径,经 getMarkdown() 序列化后存库即损坏。

解法:把公式建模成 atom Node(InlineMath/DisplayMath),LaTeX 存 attrs.latex
而非子文本;声明 markdownTokenizer/parseMarkdown/renderMarkdown 顶层 spec 字段,
序列化时 renderMarkdown 直接拼 $...$/$$...$$,绕过 encodeTextForMarkdown
转义路径(MarkdownManager 有 handler 的非文本节点不走 escape)。

NodeView 内用客户端 katex.renderToString 渲染预览(类 Notion/Typora),双击编辑
LaTeX 源码。KaTeX CSS 已由 Dioxus.toml 全局注入,无需额外接线。

- 新增 katex ^0.16.22 依赖(workspace 已 hoisted)
- 11 个回归测试覆盖矩阵/分段函数/round-trip 序列化往返
2026-07-17 17:33:37 +08:00
xfy
1584e01425 chore(deps): update all cargo and pnpm dependencies to latest versions 2026-07-09 18:12:54 +08:00
xfy
e79e0d9ee2 feat(editor): 新增 lowlight 实例与 extractLang 语言提取
common 集(~35 种语言)注册到 lowlight;extractLang 从完整 info string
(如 'python runnable {...}')提取首 token,使 runnable 块按正确语言高亮。
2026-07-06 15:45:42 +08:00
xfy
79ceb307ad chore(workspace): 建立 pnpm workspace 与共享 tsconfig
将 libs/ 下 4 个独立 pnpm 项目整合为 workspace:

- 新增根 package.json/pnpm-workspace.yaml,4 份重复的 devDeps
  (happy-dom/typescript/vite/vitest,版本零分歧)上提到根,各 lib 只留运行时依赖
- 新增 libs/tsconfig.base.json,4 份逐字节相同的 tsconfig.json 改为 extends
- per-lib pnpm-lock.yaml 合并为根 lockfile;冗余的 libs/{lightbox,yggdrasil-core}/.gitignore 删除
  (根 .gitignore 的 **/**/node_modules 已覆盖)

收益:依赖共享安装(node_modules 去重)、构建/测试可用 pnpm -r 统一调度,
单库仍可 pnpm --filter @yggdrasil/<name> 独立操作。构建与测试均验证通过(90 个 vitest 用例全绿)。
2026-07-02 17:50:52 +08:00
xfy
21c0359f5e build(tiptap): upgrade to vite 8/vitest 4/typescript 6/tiptap 3.27, migrate to rolldownOptions 2026-06-24 10:03:47 +08:00
xfy
939e0de171 build(tiptap): run tsc --noEmit before vite build 2026-06-23 18:45:17 +08:00
xfy
073f6936e3 build(tiptap): add tsconfig + typecheck script 2026-06-23 18:32:26 +08:00
xfy
3d7dd5b5a5 deps(editor): add @tiptap/extension-file-handler 2026-06-05 15:17:39 +08:00
xfy
a8704e199f feat(editor): add slash command, table, task list, image and link extensions
- Add @tiptap/suggestion-based slash command menu with 12 commands
- Add TableKit for table support (3x3 with header)
- Add Image extension with base64 support
- Add Link extension with autolink and paste detection
- Add TaskList/TaskItem extensions for checklists
- Upgrade all tiptap packages from 3.23.6 to 3.25.0
- Add CSS styles for all new features including dark theme
2026-06-05 10:20:47 +08:00
xfy
f6d60520eb 集成 Tiptap Markdown 编辑器到文章撰写页面
- 新增 libs/tiptap-editor/ 打包子项目(Tiptap Core + StarterKit + Markdown)
- 构建产物输出到 public/tiptap/
- 替换原有的 textarea + pulldown_cmark 预览为 WYSIWYG 编辑器
- Makefile 新增 build-editor target
- Dioxus.toml 引入 editor.js 和 editor.css

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 17:46:04 +08:00