一款高性能的Markdown解析器和渲染器,适用于Angular、React、Svelte、Vue、HTML和ANSI。
概览
用一个JavaScript库(支持HTML、ANSI、Vue、React、Svelte和Angular),以及插件和流媒体,随时解析和渲染Markdown。 Comark 支持 CommonMark 和 GFM,然后在构建时、运行时或流中解析它们成紧凑、可序列化的文档。在渲染器间使用同一份文档,或在需要更丰富内容时扩展语法,加入可读的组件和属性。 - : parseMarkdown(markdown)是一个纯函数,返回一个紧凑、可序列化的Markdown文档。数据库、CMS或LLM的内容一旦保存即即是上线。无需重建,无需重新部署。(Comark vs MDX)- : 自动关闭完成未终止语法(**一个解析器,每个渲染器**仍仅是Markdown**插件生态系统**解耦解析与渲染**Fast**:基于markdown-exit构建,是markdown-it的TypeScript重写,支持完全TypeScript。 组件和属性语法基于五年MDC生产环境的使用经验。阅读《Why Comark》以了解完整故事。
概述(AI 翻译)
Comark 是一款开源的 Markdown 解析器和渲染器,包含组件、属性和插件。它将 AI 输出流向 React、Vue、Svelte、Angular、HTML 和终端。
Comark 支持 CommonMark 和 GFM,然后在构建时、运行时或流中解析它们成紧凑、可序列化的文档。在渲染器间使用同一份文档,或在需要更丰富内容时扩展语法,加入可读的组件和属性。
为什么是科马克
- 运行时解析:
parseMarkdown(markdown)是一个纯函数,返回一个紧凑、可序列化的 Markdown 文档。数据库、CMS 或大型语言模型中的内容一旦保存即为上线。无需重建,无需重新部署。(Comark 与 MDX) - 内置流媒体:自动关闭完成未终止语法(
**bold,代码开放,组件半开),因此AI输出在每一帧都能正确渲染。 - 每个渲染器都用一个解析器:同一源代码渲染成HTML、ANSI、Vue、React、Svelte和Angular。你的内容会超越你的框架。
- 仍然只是Markdown:CommonMark + GFM(有一些差异)、前置件,以及原生元素上的
{.class}属性。组件是可选的语法,不是新语言。
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
comark
Comark is an open-source Markdown parser and renderer with components, attributes and plugins. It streams AI output to React, Vue, Svelte, Angular, HTML and the terminal.
Comark supports CommonMark and GFM, then parses them into a compact, serializable document at build time, runtime, or during a stream. Use the same document across renderers, or extend the syntax with readable components and attributes when you need richer content.
# Regular Markdown
With a custom component:
::alert{type="warning"}
This is **Markdown** inside your own component.
::
Why Comark
- Runtime parsing:
parseMarkdown(markdown)is a pure function returning a compact, serializable Markdown document. Content from a database, CMS, or LLM is live the moment it is saved. No rebuild, no redeploy. (Comark vs MDX) - Streaming built in: auto-close completes unterminated syntax (
**bold, open code fences, half-open components) so AI output renders correctly at every frame. - One parser, every renderer: the same source renders to HTML, ANSI, Vue, React, Svelte, and Angular. Your content outlasts your framework.
- Still just Markdown: CommonMark + GFM (with a few differences), frontmatter, and
{.class}attributes on native elements. Components are opt-in syntax, not a new language. - Plugin ecosystem: Shiki highlighting, KaTeX math, Mermaid diagrams, TOC, alerts, footnotes and more, plus compatibility with existing markdown-it plugins.
- Decoupled parse & render: parse once on the server, send the serializable document (
['tag', props, ...children]) to the client, render without re-parsing. - Fast: built on markdown-exit, a TypeScript rewrite of markdown-it, with full TypeScript support.
The component and attribute syntax builds on five years of production use in MDC. Read Why Comark for the full story.
Quick Start
推荐工具
换一个关键词,或者移除筛选条件。
安装
npx skillfish add comarkdown/comark