@duskmoon-dev/el-markdown-input

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

A form-associated custom element providing a full-featured markdown editor.

原始使用文档
文档目录11 节
  1. Features
  2. Installation
  3. Preview dependencies
  4. Basic Usage
  5. Attributes
  6. Public API
  7. Events
  8. CSS Custom Properties
  9. File Upload
  10. Autocomplete
  11. Phoenix LiveView

@duskmoon-dev/el-markdown-input

A form-associated custom element providing a full-featured markdown editor.

Features

  • Write / Preview tabs — switch between editing and rendered output
  • Rich preview — highlighted YAML front matter, inline color chips, and soft line breaks
  • Syntax highlighting — backdrop technique with Prism.js (lazy CDN load)
  • File upload — drag-and-drop, clipboard paste, or file picker with progress
  • Autocomplete — @mention and #reference with keyboard navigation
  • Status bar — live word / character count with optional max-words cap
  • Form participation — native <form> submission via ElementInternals
  • LiveView hook — first-class Phoenix LiveView integration

Installation

bun add @duskmoon-dev/el-markdown-input

Preview dependencies

The published package includes the remark/rehype math adapters and a separate, lazy-loaded Mermaid bundle with patched KaTeX. Consumers do not need dependency overrides or a separate Mermaid installation. Bundling these adapters avoids their upstream KaTeX 0.16 dependency ranges.

In browsers, the first Mermaid diagram loads this package's version-pinned dist/esm/mermaid.js asset from jsDelivr. This requires network access and permission for https://cdn.jsdelivr.net in your Content Security Policy. To self-host, copy that asset from the installed package to your HTTPS server and set mermaid-src to its URL. The asset is self-contained, including its patched KaTeX runtime. Native Node/Bun consumers load the package-local bundle instead. Neither path loads Mermaid until a preview contains a Mermaid diagram.

The default math stylesheet also uses jsDelivr and matches KaTeX 0.18.2; katex-css-url can provide a custom HTTPS stylesheet.

Basic Usage

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

<form method="post">
  <el-dm-markdown-input name="body" placeholder="Write markdown…"></el-dm-markdown-input>
  <button type="submit">Save</button>
</form>

Attributes

AttributeTypeDefaultDescription
namestring""Form field name
valuestring""Initial markdown content
placeholderstring"Write markdown…"Textarea placeholder
disabledbooleanfalseDisables editing
upload-urlstring—POST endpoint returning { url: string }
max-wordsnumber—Soft word cap in status bar
darkbooleanfalseDark Prism theme + dark CSS variable defaults

Public API

el.getValue(): string
el.setValue(str: string): void
el.insertText(str: string): void
el.setSuggestions(list: Suggestion[]): void

Events

EventDetailWhen
change{ value: string }On every input
upload-start{ file: File }File accepted for upload
upload-done{ file: File, url: string, markdown: string }Upload completed
upload-error{ file: File, error: string }Upload failed
mention-query{ trigger: "@", query, resolve }User typed @word
reference-query{ trigger: "#", query, resolve }User typed #word

CSS Custom Properties

PropertyDefault (light)Purpose
--md-bordervar(--color-outline)Editor border
--md-border-focusvar(--color-primary)Focus ring colour
--md-bgvar(--color-surface)Editor background
--md-bg-toolbarvar(--color-surface-variant)Toolbar background
--md-textvar(--color-on-surface)Primary text colour
--md-text-mutedvar(--color-on-surface-variant)Muted text colour
--md-accentvar(--color-primary)Tab active indicator
--md-radius6pxBorder radius
--md-upload-barvar(--color-primary)Upload progress bar

File Upload

<el-dm-markdown-input upload-url="/api/uploads"></el-dm-markdown-input>

The endpoint must accept POST multipart/form-data with field file and respond with:

{ "url": "https://cdn.example.com/file.png" }

Autocomplete

el.addEventListener('mention-query', async (e) => {
  const users = await fetchUsers(e.detail.query);
  e.detail.resolve(users.map(u => ({
    id: u.handle,
    label: u.name,
    subtitle: u.email
  })));
});

Phoenix LiveView

// app.js
import { MarkdownInputHook, register } from '@duskmoon-dev/el-markdown-input';
register();

let liveSocket = new LiveSocket('/live', Socket, {
  hooks: { MarkdownInput: MarkdownInputHook }
});
<el-dm-markdown-input
  id="body-input"
  name="body"
  data-value={@content}
  phx-hook="MarkdownInput"
/>

版本与发布记录

@duskmoon-dev/el-markdown-input 共发布 46 个版本,首次发布于 2026/03/10;过去 12 个月发布了 46 个版本。最新版本附带 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-input 的常见问题

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

A form-associated custom element providing a full-featured markdown editor.

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

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

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

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

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

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

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

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

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

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

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

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