feat(预览): 支持 MDX 独立文档渲染与交互预览 - #2
Merged
Merged
Conversation
原因: 预览工作台此前缺乏对 .mdx 文件的独立渲染能力,直接回退至纯代码视图。 内容: - 后端新增 PreviewMimeMDX 常量与 MIME 推断,支持 MDX 入口文件自动解析 - 共享组件库新增 mdx 模块,支持 YAML frontmatter 解析、头部卡片与目录大纲 - 控制台前端扩展 PreviewKind,完成文件查看器分发、Pages 展示与 Q&A 内联适配
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Preview(预览)模块此前缺乏对
.mdx文件的独立感知与渲染能力,当上传或浏览.mdx文件时会直接回退至纯代码视图。本 PR 为 Preview 模块赋予独立支持 MDX 文档的渲染与交互大纲能力,使其与 HTML、LPW、TSX 等同为一等公民预览格式。主要变更
1. 后端服务层(Go)
PreviewMimeMDX = "text/mdx; charset=utf-8"常量。inferMimeType中将.mdx文件精准推断为PreviewMimeMDX。FindPreviewEntry、FindPreviewEntryFromPreviewFiles与FindPreviewEntryFromPageFiles:index.mdx,其次选取readme.mdx/overview.mdx,最后回退首个.mdx。LPW > HTML > TSX > MDX > Markdown。isMdxEntryFile辅助判定,保障历史行 MIME 漂移兜底与常量一致性。navigateShim拦截正则中追加.mdx扩展名。ServePreviewPath中统一调用logic.FindPreviewEntry处理默认重定向。preview_handlers.go的可评审入口提示文案。2. 共享组件库(
@lumina/components)components/src/mdx/建立独立模块并在components/package.json导出"./mdx"。frontmatter.ts):---\n起始的 YAML Frontmatter。title、description、icon、tags、date/last_updated以及自定义属性字典,正文与元数据安全分离。mdx-header.tsx):display-title)与导言描述。mdx-viewer.tsx):PreviewMdxViewer(全页模式)与PreviewMdxInlineViewer(内联卡片模式)。proseArticle),支持 GFM、扩展围栏块(:::callout、:::card、:::steps、:::step)、Mermaid 架构图懒加载与 KaTeX 数学公式渲染。TableOfContents,在宽屏右侧保持 sticky 目录大纲,移动端提供悬浮折叠大纲。3. 控制台前端应用(
web/)PreviewKind联合类型扩充'mdx',previewLanguageFromFilename映射为'markdown'。file-viewer.tsx中分发mdx到<PreviewMdxViewer />,并保持「源码模式」无缝切换。showcase-shell.tsx的isRenderable中加入mdx,支持 MDX 文档晋升快照并在 Pages 页面中直接渲染。preview-frame.tsx中增加内联 MDX 渲染分支(<PreviewMdxInlineViewer />)。验证情况
make fmt与make vet静态检查通过。go test -count=1 ./internal/logic ./internal/handler ./internal/mcp全部通过。go test -short -race ./...竞态安全测试全部通过。@lumina/components:55 个测试文件,287 个测试用例全部通过;tsc --noEmit与 ESLint 通过。web:34 个测试文件,156 个测试用例全部通过;修改文件 ESLint 通过;生产构建顺利完成。web-wiki:10 个测试文件,80 个测试用例全部通过。