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
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
> TypeScript 重构 · 零运行时依赖 · 轻量级桌面端 Markdown Editor 库
|
||||
|
||||
[](https://git.metona.cn/MetonaTeam/-/packages/npm/@metona-team%2Fmetona-editor)
|
||||
[](https://git.metona.cn/MetonaTeam/-/packages/npm/@metona-team%2Fmetona-editor)
|
||||
[](./LICENSE)
|
||||
[](./tests)
|
||||
[](./tests)
|
||||
[](./tests)
|
||||
[](./tsconfig.json)
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
- **主题系统** — light / dark / warm / auto,CSS 变量可定制,实例级隔离,主题继承,外部跟随
|
||||
- **国际化** — zh-CN / en-US / ja / ko 完整翻译,实例级语言隔离,远程加载翻译包
|
||||
- **编辑体验** — 行号装订线、智能 Enter、括号自动闭合、拖放文件、大纲面板、Zen 专注模式、右键上下文菜单
|
||||
- **安全** — HTML 转义,XSS 协议过滤(javascript / vbscript / file / data),sanitize 钩子
|
||||
- **内置语法高亮** — 零依赖轻量高亮器,js/ts/python/bash/css/html 等 13 种语言,`MeEditor.highlight` 即插即用
|
||||
- **安全** — HTML 转义,XSS 协议过滤(javascript / vbscript / file / data),属性级注入防护,sanitize 钩子
|
||||
- **桌面端优先** — 纯电脑端设计,无移动端冗余代码
|
||||
- **引用链接** — 支持 `[text][ref]` / `![alt][ref]` 引用式链接和图片,含 title 属性
|
||||
- **RTL 支持** — 完整的从右到左布局适配(阿拉伯语、希伯来语等)
|
||||
@@ -75,10 +76,10 @@ const editor = MeEditor.create('#editor', { mode: 'split' });
|
||||
|
||||
```html
|
||||
<!-- jsDelivr CDN (推荐) -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/@metona-team/metona-editor@0.2.4/dist/metona-editor.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@metona-team/metona-editor@0.2.5/dist/metona-editor.min.js"></script>
|
||||
|
||||
<!-- unpkg CDN -->
|
||||
<script src="https://unpkg.com/@metona-team/metona-editor@0.2.4/dist/metona-editor.min.js"></script>
|
||||
<script src="https://unpkg.com/@metona-team/metona-editor@0.2.5/dist/metona-editor.min.js"></script>
|
||||
|
||||
<!-- Gitea 源 -->
|
||||
<script src="https://git.metona.cn/MetonaTeam/MetonaEditor/raw/branch/master/dist/metona-editor.js"></script>
|
||||
@@ -95,8 +96,8 @@ const editor = MeEditor.create('#editor', { mode: 'split' });
|
||||
# 下载产物文件到项目中
|
||||
# dist/metona-editor.js → UMD (浏览器)
|
||||
# dist/metona-editor.min.js → UMD 压缩
|
||||
# dist/metona-editor.esm.js → ES Module
|
||||
# dist/metona-editor.cjs.js → CommonJS
|
||||
# dist/metona-editor.mjs → ES Module
|
||||
# dist/metona-editor.cjs → CommonJS
|
||||
```
|
||||
|
||||
```html
|
||||
@@ -106,9 +107,9 @@ const editor = MeEditor.create('#editor', { mode: 'split' });
|
||||
|
||||
```javascript
|
||||
// Node.js ESM
|
||||
import MeEditor from './dist/metona-editor.esm.js';
|
||||
import MeEditor from './dist/metona-editor.mjs';
|
||||
// Node.js CJS
|
||||
const MeEditor = require('./dist/metona-editor.cjs.js');
|
||||
const MeEditor = require('./dist/metona-editor.cjs');
|
||||
```
|
||||
|
||||
---
|
||||
@@ -138,9 +139,10 @@ MeEditor.create(container, {
|
||||
historyDebounce: 400, // 历史栈防抖(ms)
|
||||
syncScroll: true, // 分屏同步滚动
|
||||
autoBrackets: true, // 括号自动闭合
|
||||
zenMode: false, // Zen 专注模式
|
||||
zenMode: false, // 启动即进入 Zen 专注模式
|
||||
wordWrap: true, // 自动换行
|
||||
maxLength: 0, // 最大字符数(0=不限)
|
||||
floatingToolbar: true, // 选中文本浮动格式栏
|
||||
|
||||
// 主题与语言
|
||||
theme: 'auto', // 'light' | 'dark' | 'warm' | 'auto'
|
||||
@@ -217,6 +219,30 @@ editor.getHTML(): string
|
||||
editor.refresh(): this // 强制重渲染(内容未变时)
|
||||
editor.insert(text: string, opts?: { replace?: boolean }): this
|
||||
editor.wrap(before: string, after?: string): this
|
||||
editor.replaceAll(search: string, replace: string, caseSensitive?: boolean): number
|
||||
editor.replaceAllRegex(pattern: RegExp, replace: string): number
|
||||
editor.lineCount(): number
|
||||
editor.getLine(line: number): string
|
||||
editor.copyAsMarkdown(): this // 复制源码到剪贴板
|
||||
editor.copyAsHTML(): this // 复制渲染 HTML 到剪贴板
|
||||
```
|
||||
|
||||
### 光标与选区
|
||||
|
||||
```typescript
|
||||
editor.getSelectedText(): string
|
||||
editor.getCursorPosition(): { line: number; column: number }
|
||||
editor.setCursorPosition(line: number, column?: number): this
|
||||
editor.scrollToLine(line: number): this
|
||||
editor.selectLine(line: number): this
|
||||
editor.selectAll(): this
|
||||
```
|
||||
|
||||
### 浮动工具栏
|
||||
|
||||
```typescript
|
||||
editor.toggleFloatingToolbar(): this // 开关选中文本格式栏
|
||||
editor.isFloatingToolbar(): boolean
|
||||
```
|
||||
|
||||
### 命令执行
|
||||
@@ -559,6 +585,27 @@ pluginUtils.getPreset('autoSave') // 预设副本
|
||||
|
||||
---
|
||||
|
||||
## 语法高亮
|
||||
|
||||
v0.2.5 起内置零依赖轻量高亮器(js / ts / tsx / jsx / python / bash / css / html / json / yaml / markdown / java / go / rust)。
|
||||
|
||||
```typescript
|
||||
import MeEditor from '@metona-team/metona-editor';
|
||||
|
||||
// 作为 highlight 钩子(代码块自动高亮)
|
||||
MeEditor.create('#editor', { highlight: MeEditor.highlight });
|
||||
|
||||
// 独立调用
|
||||
const html = MeEditor.highlight(code, 'typescript');
|
||||
|
||||
// 注册自定义语言
|
||||
MeEditor.registerLanguage('myLang', { keywords: ['kw'], builtins: [] });
|
||||
```
|
||||
|
||||
高亮类名:`me-hl-keyword` / `me-hl-string` / `me-hl-comment` / `me-hl-number` / `me-hl-builtin` / `me-hl-function`。
|
||||
|
||||
---
|
||||
|
||||
## 主题系统
|
||||
|
||||
### 内置主题
|
||||
@@ -705,8 +752,8 @@ npm run format
|
||||
dist/
|
||||
├── metona-editor.js UMD(浏览器直接引入)
|
||||
├── metona-editor.min.js UMD 压缩版(CDN)
|
||||
├── metona-editor.esm.js ES Module
|
||||
├── metona-editor.cjs.js CommonJS
|
||||
├── metona-editor.mjs ES Module
|
||||
├── metona-editor.cjs CommonJS
|
||||
└── metona-editor.d.ts TypeScript 类型声明
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user