
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@zjlab-frontier/markdown
Advanced tools
Markdown component with support for Mermaid, KaTeX, and code highlighting
@zjlab-frontier/markdown 使用说明文档包名:
@zjlab-frontier/markdown
适用框架:React(支持 React 16.8+、17.x、18.x)
功能亮点:支持 Mermaid 图表、LaTeX 数学公式(KaTeX)、代码高亮、GitHub 风格 Markdown(GFM)、自动换行、代码复制、长代码折叠、媒体自动识别 等。
npm install @zjlab-frontier/markdown
⚠️ 注意:本组件为 React 组件,需确保项目中已安装 React(版本 ≥16.8)。
import ZJMarkdown from '@zjlab-frontier/markdown';
function App() {
const markdownContent = `
# 欢迎使用 ZJLab Markdown
这是一个支持 **Mermaid**、**LaTeX** 和 **代码高亮** 的 React Markdown 组件。
- ✅ 表格
- ✅ 任务列表
- ✅ 数学公式:$E = mc^2$
- ✅ 代码块(带复制按钮)
- ✅ 自动识别音视频链接
`;
return <ZJMarkdown content={markdownContent} />;
}
用来快速测试、布局、调试的组件,自带全面的 Markdown 测试内容
import { TestZJMarkdown } from '@zjlab-frontier/markdown';
<TestZJMarkdown />
通过 remark-gfm 插件,完整支持:
~~text~~- [x] donehttps://example.com)✅ 示例:
| 语法 | 描述 |
|------|------|
| `**bold**` | 加粗 |
- [x] 支持 GFM
- [ ] 其他功能
支持两种语法:
$...$ 或 \(...\)$$...$$ 或 \[...\]⚠️ 注意:组件内部会自动将
\(...\)和\[...\]转换为$...$和$$...$$,确保 KaTeX 正确渲染。
✅ 示例:
爱因斯坦质能方程:$E = mc^2$
高斯积分:
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$
📌 样式说明:已自动引入
katex/dist/katex.min.css,无需手动引入。
在代码块中标注语言为 mermaid 即可自动渲染图表:
✅ 示例:
```mermaid
graph TD
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
B -->|No| D[Cancel]
```
🔒 安全机制:
- 若 Mermaid 渲染失败(如语法错误),组件将 静默失败(不显示原始代码,避免泄露敏感内容)。
- 图表容器带有
no-dark类,防止深色主题干扰 Mermaid 默认配色。
🖱️ 交互:点击图表可触发
viewSvgInNewWindow()(当前为预留功能,实际未启用弹窗,但保留点击事件扩展点)。
language-xxx class)text, md, latex 等)"", "md", "markdown", "text", "txt", "plaintext", "tex", "latex"
.copy-code-button 类,可通过 CSS 自定义图标。组件会自动将特定后缀的链接转换为 <audio> 或 <video> 元素:
<audio controls>):.aac, .mp3, .opus, .wav<video controls>):.3gp, .3g2, .webm, .ogv, .mpeg, .mp4, .avi✅ 示例:
听一段音乐:https://example.com/song.mp3
看一个视频:https://example.com/demo.mp4
组件对输入内容进行 双重安全处理:
<, >, /, = → 对应 HTML 实体`...` 和块级 ...)$...$, $$...$$)✅ 保证公式和代码内容不被破坏,同时防止 XSS 攻击。
<p> 标签自动添加 dir="auto",支持多语言自动排版。\n)自动转为 <br>(通过 remark-breaks)。组件根元素自动应用:
<div class="markdown-body">...</div>
.markdown-body采用 GitHub 风格样式(基于github-markdown-css理念定制)。
通过 props 控制:
<ZJMarkdown
content={content}
fontSize={18} // 默认 16
fontFamily="'Inter', sans-serif"
/>
可通过 CSS 覆盖以下关键类:
| 类名 | 用途 |
|---|---|
.markdown-body | 整体容器 |
.mermaid | Mermaid 图表容器 |
.copy-code-button | 代码复制按钮 |
.show-hide-button | 代码折叠按钮 |
.no-dark | 防止深色主题干扰 Mermaid |
ZJMarkdown Props| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
content | string | 必需 | Markdown 源字符串 |
fontSize | number | 16 | 字体大小(单位:px) |
fontFamily | string | "inherit" | 字体族 |
onContextMenu | React.MouseEventHandler | - | 右键菜单事件 |
onDoubleClickCapture | React.MouseEventHandler | - | 双击捕获事件 |
其他 div 原生属性 | - | - | 如 className, style 等(透传至根 div) |
⚠️ 注意:
content中的 HTML 标签会被 安全过滤,仅保留必要结构。
Mermaid 渲染异步性:
KaTeX 公式转义:
\(...\) 和 $...$,建议统一使用 $...$。<, > 等符号,或使用 \lt, \gt 替代。代码折叠逻辑:
overflow-y: hidden。性能优化:
React.memo,仅当 content 变化时重渲染。MIT License
本组件基于以下优秀开源库构建:
✅ 本说明文档完整覆盖
@zjlab-frontier/markdown@1.0.6所有功能,无省略,可直接用于团队协作或用户文档。
FAQs
Framework-agnostic Markdown component with support for Mermaid, KaTeX, and code highlighting. Core library is React-free; React adapter available optionally.
The npm package @zjlab-frontier/markdown receives a total of 16 weekly downloads. As such, @zjlab-frontier/markdown popularity was classified as not popular.
We found that @zjlab-frontier/markdown demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.