md-preview-cli-plus 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -5
- package/lib/preview.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
<a></a> <a href="https://www.npmjs.com/package/md-preview-cli-plus"></a> [](https://hexo.io) <a href="https://www.npmjs.com/package/md-preview-cli-plus"></a>
|
2
|
+
|
1
3
|
# Md-preview-CLI
|
4
|
+
|
2
5
|
Markdown real-time preview + export
|
3
6
|
|
4
7
|
Markdown 实时预览 + 导出工具
|
@@ -6,7 +9,9 @@ Markdown 实时预览 + 导出工具
|
|
6
9
|
CLI + Web + Markdown 三位一体
|
7
10
|
|
8
11
|
由于CLI对兼容性要求高,选择 CommonJS 模块化方式
|
9
|
-
|
12
|
+
|
13
|
+
# Getting Started
|
14
|
+
|
10
15
|
```bash
|
11
16
|
npx md-preview --help #help
|
12
17
|
npx md-preview README.md --port 4000 --theme dark --export ./666.html #无需下载 用完删除 不占空间
|
@@ -18,7 +23,7 @@ npx md-preview README.md --port 4000 --theme dark --export ./666.html #无需下
|
|
18
23
|
4. **Colorful Terminal:** Integrate `chalk` for vibrant console output. 🌈
|
19
24
|
5. **Hot Reloading:** Wrap `socket.io` in a `useSocket()` function to watch file changes and trigger browser refresh (similar to Vite).
|
20
25
|
6. **HTML Exporting:** Add `--export <path>` to save rendered HTML output to a file.
|
21
|
-
7. **Theme Support:** Provide multi-theme styling via `--theme=dark`
|
26
|
+
7. **Theme Support:** Provide multi-theme styling via `--theme=dark` or similar options and support custom themes.
|
22
27
|
8. **Plugin Architecture:** Support custom parser plugins.
|
23
28
|
9. **Packaging & Publishing:** Publish as an NPM package; allow usage via `npx md-preview`.
|
24
29
|
10. **Syntax Highlighting:** Use `highlight.js` to render beautifully highlighted code blocks.
|
@@ -33,20 +38,36 @@ npx md-preview README.md --port 4000 --theme dark --export ./666.html #无需下
|
|
33
38
|
- `afterRender`
|
34
39
|
# 功能细化
|
35
40
|
1. 构建CLI 采用commander 解析参数、增加帮助信息--help、版本控制-V --version、错误处理
|
41
|
+
|
36
42
|
2. 文件监听变化 chokidar 跨平台兼容性好 低耗能
|
43
|
+
|
37
44
|
3. 打开open 打开各种文件程序 跨平台兼容性好
|
45
|
+
|
38
46
|
4. 打造彩色终端 🌈chalk
|
47
|
+
|
39
48
|
5. 热刷新页面:封装socket.io为useSocket()监听变化并通知刷新页面(类似 Vite)
|
49
|
+
|
40
50
|
6. 导出 HTML 功能:增加 --export 参数保存 HTML 文件
|
41
|
-
|
42
|
-
|
51
|
+
|
52
|
+
7. 多主题支持:通过 --theme=dark 选择不同样式、支持自定义主题
|
53
|
+
|
54
|
+
8. 插件机制:支持自定义插件及其生命周期钩子、高灵活度配置,支持插件配置文件.previewrc+CLI参数优先级控制
|
55
|
+
|
43
56
|
9. 打包发布:发布为 NPM 包,支持 npx md-preview
|
57
|
+
|
44
58
|
10. 引入代码高亮 highlight.js
|
59
|
+
|
60
|
+
11. 后续:
|
61
|
+
|
62
|
+
结合图床、插件沙箱机制、多语言支持i18n(自动识别/--lang参数切换)、vitest单元测试、WEB UI模式(拖拽+实时编辑)、项目文档VitePress
|
63
|
+
|
45
64
|
# 插件机制
|
65
|
+
|
46
66
|
1. 任选其一:可通过命令行传插件地址;也可以将插件放入某个目录下(例如plugins/)并设置插件配置文件`.previewrc`;如有冲突,则`.previewrc`配置优先级小于命令行参数
|
47
67
|
2. 支持自定义插件,插件系统生命周期钩子 init、beforeRender/afterRender
|
48
68
|
# 项目结构
|
49
69
|
```bash
|
70
|
+
# 旧设定
|
50
71
|
md-preview/
|
51
72
|
├── bin/
|
52
73
|
│ └── cli.js # CLI 命令入口
|
@@ -67,4 +88,3 @@ plugins/
|
|
67
88
|
```js
|
68
89
|
console.log("hello world")
|
69
90
|
```
|
70
|
-
|
package/lib/preview.js
CHANGED
@@ -30,7 +30,7 @@ function startPreview(filePath, options,pluginManager) {
|
|
30
30
|
const server=app.listen(port, () => {
|
31
31
|
console.log(chalk.cyan(`🚀 Local preview started at http://localhost:${port}`))
|
32
32
|
open(`http://localhost:${port}`)
|
33
|
-
})
|
33
|
+
})//返回http.Server对象
|
34
34
|
const io = new Server(server, {
|
35
35
|
cors: { origin: '*' }
|
36
36
|
})
|