@duskmoon-dev/el-markdown

中文文档
1.10.3发布于 2026/11/11TypeScriptESM + CJS构建来源已验证近 30 天下载 2914

A markdown renderer component using remark/rehype with syntax highlighting, mermaid diagram support, and streaming mode for LLM output.

原始使用文档
文档目录25 节
  1. Installation
  2. Usage
  3. Auto-Register (Recommended)
  4. Manual Registration
  5. From URL
  6. With Mermaid Diagrams
  7. Features
  8. Themes
  9. Attributes
  10. Properties
  11. Methods
  12. CSS Parts
  13. Events
  14. CSS Custom Properties
  15. Supported Markdown Features
  16. Examples
  17. Task List
  18. Table
  19. Loading Remote Content
  20. Streaming Mode
  21. Basic Streaming
  22. Using Content Property
  23. Listening to Stream Events
  24. Syntax Auto-Recovery
  25. License

@duskmoon-dev/el-markdown

A markdown renderer component using remark/rehype with syntax highlighting, mermaid diagram support, and streaming mode for LLM output.

Installation

bun add @duskmoon-dev/el-markdown

For mermaid diagram support (optional):

bun add mermaid

Usage

The simplest way to use the component - just import and it's ready:

<!-- Via CDN -->
<script type="module" src="https://esm.sh/@duskmoon-dev/el-markdown/register"></script>

<!-- Now use the element -->
<el-dm-markdown> # Hello World This is **markdown** content. </el-dm-markdown>

Or with a bundler:

import '@duskmoon-dev/el-markdown/register';

Manual Registration

<script type="module">
  import { register } from '@duskmoon-dev/el-markdown';
  register();
</script>

<el-dm-markdown> # Hello World </el-dm-markdown>

From URL

<el-dm-markdown src="/docs/readme.md"></el-dm-markdown>

With Mermaid Diagrams

<el-dm-markdown>
  # Flowchart Example ```mermaid graph TD A[Start] --> B{Is it?} B -->|Yes| C[OK] B -->|No|
  D[End]</el-dm-markdown
>
```

Features

  • GitHub Flavored Markdown: Tables, task lists, strikethrough, autolinks
  • Soft Line Breaks: Single newlines render as line breaks by default
  • Color Chips: Supported HEX, RGB, and HSL values in inline code show a color preview
  • Front Matter: Leading YAML front matter renders as a highlighted YAML code block
  • Syntax Highlighting: Powered by highlight.js via rehype-highlight
  • Mermaid Diagrams: Optional support for flowcharts, sequence diagrams, etc.
  • Multiple Themes: GitHub, Atom One Dark, Atom One Light
  • Auto Theme: Respects prefers-color-scheme media query
  • Indentation Removal: Automatically removes common indentation from inline content
  • Streaming Mode: Real-time rendering for LLM output with automatic syntax error recovery

Themes

ThemeDescription
autoFollows system preference (default)
githubGitHub-style light theme
atom-one-darkAtom One Dark theme
atom-one-lightAtom One Light theme
<el-dm-markdown theme="atom-one-dark"> ```js const dark = true;</el-dm-markdown>
```

Attributes

AttributeTypeDefaultDescription
srcstringURL to fetch markdown from
themestringautoCode syntax highlighting theme
debugbooleanfalseEnable debug logging
no-mermaidbooleanfalseDisable mermaid rendering
streamingbooleanfalseRead-only, reflects streaming state

Properties

PropertyTypeDescription
contentstringGet/set markdown content directly

Methods

MethodDescription
startStreaming()Begin streaming mode, clear buffer, show cursor
appendContent(chunk)Append a chunk of content during streaming
setContent(content)Replace content (works in streaming & normal)
endStreaming()End streaming, perform final clean render

CSS Parts

PartDescription
containerThe outer container
contentThe rendered markdown content

Events

EventDetailDescription
dm-rendered{ html: string }Fired after markdown is rendered
dm-error{ error: string }Fired when an error occurs
dm-stream-chunk{ content: string, chunk: string }Fired when a chunk is appended
dm-stream-end{ content: string }Fired when streaming ends

CSS Custom Properties

PropertyDescription
--dm-markdown-font-familyFont family for content
--dm-markdown-code-font-familyFont family for code
--dm-markdown-line-heightLine height

Supported Markdown Features

  • Headings (h1-h6)
  • Paragraphs
  • Bold, italic, strikethrough
  • Links and images
  • Ordered and unordered lists
  • Task lists (GFM)
  • Blockquotes
  • Code (inline and blocks)
  • Syntax highlighting
  • Tables (GFM)
  • Horizontal rules
  • Mermaid diagrams (optional)
  • Color chips for inline HEX, RGB, and HSL values
  • YAML front matter

Examples

Task List

<el-dm-markdown> ## Todo - [x] Complete task - [ ] Pending task - [ ] Another task </el-dm-markdown>

Table

<el-dm-markdown>
  | Feature | Status | |---------|--------| | Tables | Supported | | Strikethrough | ~~Yes~~ |
</el-dm-markdown>

Loading Remote Content

<el-dm-markdown src="https://raw.githubusercontent.com/user/repo/main/README.md"></el-dm-markdown>

Streaming Mode

Streaming mode is designed for rendering LLM output in real-time. It automatically handles incomplete markdown syntax during streaming and shows a blinking cursor.

Basic Streaming

const md = document.querySelector('el-dm-markdown');

// Start streaming mode
md.startStreaming();

// Append chunks as they arrive from LLM
for await (const chunk of llmStream) {
  md.appendContent(chunk);
}

// End streaming (performs final clean render)
md.endStreaming();

Using Content Property

const md = document.querySelector('el-dm-markdown');

md.streaming = true; // Or call startStreaming()
let content = '';

for await (const chunk of llmStream) {
  content += chunk;
  md.content = content;
}

md.streaming = false; // Or call endStreaming()

Listening to Stream Events

const md = document.querySelector('el-dm-markdown');

md.addEventListener('dm-stream-chunk', (e) => {
  console.log('Received chunk:', e.detail.chunk);
  console.log('Total content:', e.detail.content);
});

md.addEventListener('dm-stream-end', (e) => {
  console.log('Streaming complete:', e.detail.content);
});

Syntax Auto-Recovery

During streaming, incomplete markdown syntax is automatically fixed:

Incomplete PatternAuto-Fix Action
``` unclosedCloses code block
` unclosedCloses inline code
**text unclosedCloses bold
*text unclosedCloses italic
~~text unclosedCloses strikethrough
[text](urlCloses link
![alt](urlCloses image

This ensures the markdown renders correctly even with partial content.

License

MIT

版本与发布记录

@duskmoon-dev/el-markdown 共发布 54 个版本,首次发布于 2026/01/04;过去 12 个月发布了 54 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.10.3latest2026/11/112 天前
1.10.22026/10/2222 天前
1.10.12026/10/1627 天前
1.10.02026/10/1628 天前
1.9.32026/10/131 个月前
1.9.22026/10/131 个月前

关于 @duskmoon-dev/el-markdown 的常见问题

@duskmoon-dev/el-markdown 是什么?

A markdown renderer component using remark/rehype with syntax highlighting, mermaid diagram support, and streaming mode for LLM output.

如何安装 @duskmoon-dev/el-markdown?

在项目目录运行 npm install @duskmoon-dev/el-markdown,或使用 pnpm add / yarn add / bun add。

@duskmoon-dev/el-markdown 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@duskmoon-dev/el-markdown 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@duskmoon-dev/el-markdown 可以商用吗?

@duskmoon-dev/el-markdown 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@duskmoon-dev/el-markdown 的下载量有多少?

根据 npm 官方下载统计,@duskmoon-dev/el-markdown 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,914 次,日均约 97 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@duskmoon-dev/el-markdown 还在维护吗?

最新版本 1.10.3 发布于 2026/11/11(2 天前);至今共发布 54 个版本,其中过去 12 个月发布了 54 个;首次发布于 2026/01/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。