@wenyan-md/core 1.0.16 → 2.0.0

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.
Files changed (40) hide show
  1. package/README.md +19 -176
  2. package/dist/core.js +1060 -416
  3. package/dist/publish.js +66 -67
  4. package/dist/types/core/hlThemeRegistry.d.ts +8 -0
  5. package/dist/types/core/index.d.ts +29 -0
  6. package/dist/types/core/parser/cssParser.d.ts +11 -0
  7. package/dist/types/core/parser/frontMatterParser.d.ts +7 -0
  8. package/dist/types/core/parser/markedParser.d.ts +6 -0
  9. package/dist/types/core/parser/mathjaxParser.d.ts +8 -0
  10. package/dist/types/core/renderer/footnotesRender.d.ts +1 -0
  11. package/dist/types/core/renderer/highlightApplyRender.d.ts +1 -0
  12. package/dist/types/core/renderer/macStyleRender.d.ts +3 -0
  13. package/dist/types/core/renderer/pseudoApplyRender.d.ts +1 -0
  14. package/dist/types/core/renderer/themeApplyRender.d.ts +1 -0
  15. package/dist/types/core/renderer/wechatPostRender.d.ts +1 -0
  16. package/dist/types/core/themeRegistry.d.ts +16 -0
  17. package/dist/types/core/types.d.ts +10 -0
  18. package/dist/types/core/utils.d.ts +6 -0
  19. package/dist/types/node/wrapper.d.ts +9 -0
  20. package/dist/types/wechat/adapters/browser.d.ts +2 -0
  21. package/dist/types/wechat/adapters/node.d.ts +2 -0
  22. package/dist/types/wechat/core.d.ts +6 -0
  23. package/dist/types/wechat/http.d.ts +12 -0
  24. package/dist/types/wechat/publish.d.ts +6 -0
  25. package/dist/wrapper.js +17 -8
  26. package/package.json +30 -23
  27. package/dist/browser/wenyan-core.js +0 -94
  28. package/dist/hltheme.js +0 -70
  29. package/dist/math/wenyan-math.js +0 -19
  30. package/dist/styles/wenyan-styles.js +0 -2232
  31. package/dist/theme.js +0 -461
  32. package/dist/types/core.d.ts +0 -17
  33. package/dist/types/hltheme.d.ts +0 -6
  34. package/dist/types/publish.d.ts +0 -1
  35. package/dist/types/theme.d.ts +0 -11
  36. package/dist/types/utils.d.ts +0 -1
  37. package/dist/types/wechatApi.d.ts +0 -8
  38. package/dist/types/wrapper.d.ts +0 -7
  39. package/dist/utils-YieK94fG.js +0 -9
  40. /package/dist/types/{runtimeEnv.d.ts → node/runtimeEnv.d.ts} +0 -0
package/README.md CHANGED
@@ -11,194 +11,37 @@
11
11
 
12
12
  ## 简介
13
13
 
14
- **文颜(Wenyan)** 是一款多平台 Markdown 排版与发布工具,支持将 Markdown 一键转换并发布至:
14
+ **文颜(Wenyan)** 是一套多平台 Markdown 排版与发布工具链, **文颜 CORE** 是其核心库,专注于:
15
15
 
16
- - 微信公众号
17
- - 知乎
18
- - 今日头条
19
- - 以及其它内容平台(持续扩展中)
16
+ - Markdown → HTML 渲染
17
+ - 主题排版(公众号 / Web)
18
+ - 代码高亮与样式增强
19
+ - 发布前内容处理(脚注、图片、样式兼容)
20
20
 
21
- 文颜的目标是:**让写作者与开发者专注内容,而不是排版和平台适配**。
21
+ 适合以下使用场景:
22
22
 
23
- 本仓库是 **文颜的核心库(CORE)**,适合以下场景:
23
+ - 在 **Node.js / Web** 项目中嵌入排版能力
24
+ - 构建 **CLI / 桌面端 / MCP / AI 写作系统**
25
+ - 自定义 Markdown 排版或内容发布流程
26
+ - 作为文颜生态的二次开发基础
24
27
 
25
- - 嵌入 Node.js / Web 项目
26
- - 构建自定义写作或发布系统
27
- - 与 CLI / 桌面端 / MCP / AI 系统集成
28
- - 二次开发排版或发布能力
29
-
30
- ## 文颜的不同版本
31
-
32
- 文颜目前提供多种形态,覆盖不同使用场景:
33
-
34
- * [macOS App Store 版](https://github.com/caol64/wenyan) - MAC 桌面应用
35
- * [跨平台桌面版](https://github.com/caol64/wenyan-pc) - Windows / Linux
36
- * [CLI 版本](https://github.com/caol64/wenyan-cli) - 命令行 / CI 自动化发布
37
- * [MCP 版本](https://github.com/caol64/wenyan-mcp) - AI 自动发文
38
- * 👉 **CORE 版本**(本项目)- 文颜核心能力库
39
-
40
- ## 功能特性
41
-
42
- * 使用内置主题对 Markdown 内容排版
43
- * 自动处理并上传图片(本地 / 网络)
44
- * 支持数学公式(MathJax)
45
- * 一键发布文章到微信公众号草稿箱
46
- * 可在 Node / 浏览器 环境中运行
47
-
48
- ## 主题效果预览
49
-
50
- 👉 [内置主题预览](https://yuzhi.tech/docs/wenyan/theme)
51
-
52
- 文颜内置并适配了多个优秀的 Typora 主题,在此感谢原作者:
53
-
54
- - [Orange Heart](https://github.com/evgo2017/typora-theme-orange-heart)
55
- - [Rainbow](https://github.com/thezbm/typora-theme-rainbow)
56
- - [Lapis](https://github.com/YiNNx/typora-theme-lapis)
57
- - [Pie](https://github.com/kevinzhao2233/typora-theme-pie)
58
- - [Maize](https://github.com/BEATREE/typora-maize-theme)
59
- - [Purple](https://github.com/hliu202/typora-purple-theme)
60
- - [物理猫-薄荷](https://github.com/sumruler/typora-theme-phycat)
61
-
62
- ## 安装方式
28
+ ## 安装
63
29
 
64
30
  ```bash
65
- pnpm add @wenyan-md/core
66
- # 或者
67
31
  npm install @wenyan-md/core
68
- # 或者
69
- yarn add @wenyan-md/core
70
- ```
71
-
72
- ## 基本用法
73
-
74
- ### 1. Markdown 排版美化
75
-
76
- ```ts
77
- import { getGzhContent } from "@wenyan-md/core/wrapper";
78
-
79
- const inputContent = "# Hello, Wenyan";
80
- const theme = "lapis";
81
- const highlightTheme = "solarized-light";
82
- const isMacStyle = true;
83
-
84
- const { title, cover, content, description } = await getGzhContent(
85
- inputContent,
86
- theme,
87
- highlightTheme,
88
- isMacStyle,
89
- isAddFootnote,
90
- );
91
- ```
92
-
93
- #### 参数说明
94
-
95
- | 参数名 | 类型 | 说明 |
96
- | --- | --- | --- |
97
- | `inputContent` | `string` | 输入的 Markdown 文本,必填 |
98
- | `theme` | `string` | 排版主题 ID,必填 |
99
- | `highlightTheme` | `string` | 代码高亮主题,必填 |
100
- | `isMacStyle` | `boolean` | 是否启用代码块 Mac 风格,默认开启 |
101
- | `isAddFootnote` | `boolean` | 是否将链接转脚注,默认开启 |
102
-
103
- 排版主题:
104
-
105
- - default / orangeheart / rainbow / lapis / pie / maize / purple / phycat
106
-
107
- 高亮主题:
108
-
109
- - atom-one-dark / atom-one-light / dracula / github-dark / github / monokai / solarized-dark / solarized-light / xcode
110
-
111
- #### 返回值
112
-
113
- | 字段 | 类型 | 说明 |
114
- | --- | --- | --- |
115
- | `title` | `string` | 从 frontmatter 中获取的文章标题 |
116
- | `cover` | `string` | 封面图 |
117
- | `content` | `string` | 转换后的 HTML 内容 |
118
- | `description` | `string` | frontmatter 中的文章简介 |
119
-
120
- ---
121
-
122
- ### 2. 发布到微信公众号草稿箱
123
-
124
- ```ts
125
- import { publishToDraft } from "@wenyan-md/core/publish";
126
-
127
- const data = await publishToDraft(title, content, cover, wechatAppId, wechatAppSecret);
128
-
129
- if (data.media_id) {
130
- console.log("上传成功:", data.media_id);
131
- }
132
- ```
133
-
134
- #### 参数说明
135
-
136
- | 参数名 | 类型 | 说明 |
137
- | --- | --- | --- |
138
- | `title` | `string` | 文章标题 |
139
- | `content` | `string` | HTML 内容 |
140
- | `cover` | `string` | 封面图 URL |
141
- | `wechatAppId` | `string` | 微信公众号 APPID |
142
- | `wechatAppSecret` | `string` | 微信公众号 APP_SECRET |
143
-
144
- #### 环境变量注入APPID和APP_SECRET
145
-
146
- 也可以通过环境变量注入APPID和APP_SECRET:
147
-
148
- ```sh
149
- export WECHAT_APP_ID=xxx
150
- export WECHAT_APP_SECRET=yyy
151
- ```
152
-
153
- ```ts
154
- import { publishToDraft } from "@wenyan-md/core/publish";
155
-
156
- const data = await publishToDraft(title, content, cover);
157
-
158
- if (data.media_id) {
159
- console.log("上传成功:", data.media_id);
160
- }
161
- ```
162
-
163
- ## 浏览器直接使用
164
-
165
- 文颜 CORE 提供浏览器可直接引入的 IIFE 构建版本,适合前端或纯静态页面使用。目前不支持“发布到微信公众号草稿箱”功能。
166
-
167
- ```html
168
- <script src="https://cdn.jsdelivr.net/npm/css-tree/dist/csstree.js"></script>
169
- <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
170
- <script src="https://cdn.jsdelivr.net/npm/@wenyan-md/core/dist/browser/wenyan-core.js"></script>
171
-
172
- <script>
173
- const { configureMarked, renderMarkdown, themes } = WenyanCore;
174
- configureMarked();
175
- const html = await renderMarkdown('# Hello from Browser');
176
- document.body.innerHTML = html;
177
- </script>
178
- ```
179
-
180
- ## Markdown Frontmatter 说明
181
-
182
- 每篇文章顶部需包含 frontmatter:
183
-
184
- ```md
185
- ---
186
- title: 示例文章
187
- cover: /path/to/cover.jpg
188
- description: 文章简介
189
- ---
190
32
  ```
191
33
 
192
- * `title`:必填
193
- * `cover`:本地路径或网络图片(正文有图可省略)
34
+ ## API 文档
194
35
 
195
- ## 微信公众号 IP 白名单
36
+ - [Wenyan Core API 文档](docs/api.md)
37
+ - [Wenyan Core API 文档:Node 环境渲染](docs/node.md)
38
+ - [Wenyan Core API 文档:微信公众号发布](docs/wechat.md)
196
39
 
197
- > ⚠️ 重要
198
- >
199
- > 请确保运行服务的服务器 IP 已加入微信公众号后台 IP 白名单。
40
+ ## 内置主题
200
41
 
201
- 配置说明:[https://yuzhi.tech/docs/wenyan/upload](https://yuzhi.tech/docs/wenyan/upload)
42
+ - [内置主题](src/assets/themes/)
43
+ - [内置代码高亮主题](src/assets/highlight/styles/)
44
+ - [内置主题预览](https://yuzhi.tech/docs/wenyan/theme)
202
45
 
203
46
  ## 赞助
204
47