Files
MetonaEditor/CONTRIBUTING.md
T
thzxx 5919dd9f66 feat: v0.2.5 — 内置语法高亮 + exportPDF + benchmark + CI 并行
- 新增 src/highlight.ts 零依赖轻量高亮器:13 种语言,先转义后
  着色保证安全,输出 me-hl-* 类,MeEditor.highlight 即插即用
- exportTool 新增 editor.exportPDF()(隐藏 iframe + window.print),
  exportHTML/exportPDF 共用 HTML 构建逻辑
- imagePaste 支持 maxSizeKB 限制,超限 toast 警告
- npm run bench 性能基准:parseMarkdown 1MB ≈ 51ms
- CI 测试拆分为 parser/core/rest 三个并行 job + 跨版本 verify job
- docs.html/README 补齐新 API、事件、高亮文档;取消跟踪 dist 产物;
  版本 0.2.4 → 0.2.5,测试 725 → 768
2026-08-09 08:59:55 +08:00

148 lines
3.6 KiB
Markdown

# Contributing to MetonaEditor
Thanks for your interest in contributing! This document outlines the development workflow and conventions.
## Prerequisites
- Node.js >= 16.0.0
- npm >= 8.0.0
## Setup
```bash
git clone https://git.metona.cn/MetonaTeam/MetonaEditor.git
cd MetonaEditor
npm install
```
## Development
```bash
# Start dev server with hot reload (port 3001)
npm run dev
# Run tests in watch mode
npm run test:watch
# Type check
npm run typecheck
# Lint
npm run lint
npm run lint:fix
# Format
npm run format
```
## Project Structure
```
src/
├── index.ts # Entry point, global API
├── core.ts # MarkdownEditor class
├── parser.ts # Markdown parser (tokenizer + renderer)
├── plugins.ts # Plugin system & 6 presets
├── themes.ts # Theme system
├── i18n.ts # Internationalization
├── styles.ts # CSS-in-JS injection
├── constants.ts # Types, defaults, configs
├── utils.ts # Utility functions
├── animations.ts # Animation metadata
├── icons.ts # Toolbar SVG icons
└── locales.ts # Translation data
tests/
├── parser.test.ts
├── core.test.ts
├── plugins.test.ts
├── themes.test.ts
├── i18n.test.ts
├── utils.test.ts
├── animations.test.ts
├── index.test.ts
└── styles.test.ts
site/
├── index.html # Landing page
├── demo.html # Full-featured demo
└── docs.html # API documentation
```
## Code Conventions
### TypeScript
- **Strict mode** is enabled — all code must pass `tsc --noEmit`.
- Export types explicitly. Avoid `any` where possible.
- Use `interface` for object shapes, `type` for unions/primitives.
### Style
- Run `npm run format` before committing (uses Prettier).
- Follow existing comment patterns: JSDoc `/** */` for public APIs, `//` for inline notes.
- Keep functions focused and under ~60 lines where practical.
### Testing
- **Every new feature must include tests.**
- Test files mirror source structure: `src/foo.ts``tests/foo.test.ts`.
- Use descriptive test names: `('does X when Y')`.
- Run the full suite before submitting: `npm test`.
### Commits
- Use conventional commit messages:
- `feat: add reference link resolution`
- `fix: autoSave plugin state conflict`
- `docs: update API reference`
- `test: add index.ts global API tests`
- `chore: optimize rollup dev build`
## Building
```bash
# Production build (all formats)
npm run build
# Output in dist/
# ├── metona-editor.js UMD
# ├── metona-editor.min.js UMD minified
# ├── metona-editor.mjs ES Module
# ├── metona-editor.cjs CommonJS
# └── metona-editor.d.ts TypeScript declarations
```
## Plugin Development
Plugins follow a simple convention:
```typescript
const myPlugin = {
name: 'myPlugin',
version: '1.0.0',
description: 'Description of my plugin',
depends: [], // optional: plugin names this depends on
priority: 50, // optional: for topological sort ordering
install(editor, options?) {
// Called when plugin is installed
// Use editor.on() to subscribe to events
// Return a Promise for async initialization
},
destroy(editor) {
// Called when plugin is uninstalled
// Clean up event listeners, timers, DOM nodes
},
};
```
## Releasing
1. Update version in `package.json` and `src/index.ts` (`VERSION` constant).
2. Update `CHANGELOG.md`.
3. Run full test suite: `npm test`.
4. Build: `npm run build`.
5. Publish: `npm publish`.
## Questions?
Open an issue at [git.metona.cn/MetonaTeam/MetonaEditor/issues](https://git.metona.cn/MetonaTeam/MetonaEditor/issues).