@wenyan-md/core 1.0.17 → 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 (39) hide show
  1. package/README.md +19 -169
  2. package/dist/core.js +1060 -416
  3. package/dist/publish.js +64 -66
  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/wrapper.js +17 -8
  25. package/package.json +30 -23
  26. package/dist/browser/wenyan-core.js +0 -94
  27. package/dist/hltheme.js +0 -70
  28. package/dist/math/wenyan-math.js +0 -19
  29. package/dist/styles/wenyan-styles.js +0 -2232
  30. package/dist/theme.js +0 -461
  31. package/dist/types/core.d.ts +0 -17
  32. package/dist/types/hltheme.d.ts +0 -6
  33. package/dist/types/theme.d.ts +0 -11
  34. package/dist/types/utils.d.ts +0 -1
  35. package/dist/types/wechatApi.d.ts +0 -8
  36. package/dist/types/wrapper.d.ts +0 -7
  37. package/dist/utils-YieK94fG.js +0 -9
  38. /package/dist/types/{runtimeEnv.d.ts → node/runtimeEnv.d.ts} +0 -0
  39. /package/dist/types/{publish.d.ts → wechat/publish.d.ts} +0 -0
package/README.md CHANGED
@@ -11,187 +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(inputContent, theme, highlightTheme, isMacStyle, isAddFootnote);
85
- ```
86
-
87
- #### 参数说明
88
-
89
- | 参数名 | 类型 | 说明 |
90
- | ---------------- | --------- | --------------------------------- |
91
- | `inputContent` | `string` | 输入的 Markdown 文本,必填 |
92
- | `theme` | `string` | 排版主题 ID,必填 |
93
- | `highlightTheme` | `string` | 代码高亮主题,必填 |
94
- | `isMacStyle` | `boolean` | 是否启用代码块 Mac 风格,默认开启 |
95
- | `isAddFootnote` | `boolean` | 是否将链接转脚注,默认开启 |
96
-
97
- 排版主题:
98
-
99
- - default / orangeheart / rainbow / lapis / pie / maize / purple / phycat
100
-
101
- 高亮主题:
102
-
103
- - atom-one-dark / atom-one-light / dracula / github-dark / github / monokai / solarized-dark / solarized-light / xcode
104
-
105
- #### 返回值
106
-
107
- | 字段 | 类型 | 说明 |
108
- | ------------- | -------- | ------------------------------- |
109
- | `title` | `string` | 从 frontmatter 中获取的文章标题 |
110
- | `cover` | `string` | 封面图 |
111
- | `content` | `string` | 转换后的 HTML 内容 |
112
- | `description` | `string` | frontmatter 中的文章简介 |
113
-
114
- ---
115
-
116
- ### 2. 发布到微信公众号草稿箱
117
-
118
- ```ts
119
- import { publishToDraft } from "@wenyan-md/core/publish";
120
-
121
- const data = await publishToDraft(title, content, cover, { wechatAppId, wechatAppSecret });
122
-
123
- if (data.media_id) {
124
- console.log("上传成功:", data.media_id);
125
- }
126
- ```
127
-
128
- #### 参数说明
129
-
130
- | 参数名 | 类型 | 说明 |
131
- | ----------------- | -------- | --------------------------------------------------- |
132
- | `title` | `string` | `getGzhContent`接口返回的`title` |
133
- | `content` | `string` | `getGzhContent`接口返回的`content` |
134
- | `cover` | `string` | `getGzhContent`接口返回的`cover` |
135
- | `wechatAppId` | `string` | 微信公众号 APPID(如果通过环境变量注入可省略) |
136
- | `wechatAppSecret` | `string` | 微信公众号 APP_SECRET(如果通过环境变量注入可省略) |
137
-
138
- #### 环境变量注入 APPID 和 APP_SECRET
139
-
140
- 也可以通过环境变量注入 APPID 和 APP_SECRET:
141
-
142
- ```sh
143
- export WECHAT_APP_ID=xxx
144
- export WECHAT_APP_SECRET=yyy
145
- ```
146
-
147
- ```ts
148
- import { publishToDraft } from "@wenyan-md/core/publish";
149
-
150
- const data = await publishToDraft(title, content, cover);
151
-
152
- if (data.media_id) {
153
- console.log("上传成功:", data.media_id);
154
- }
155
- ```
156
-
157
- ## 浏览器直接使用
158
-
159
- 文颜 CORE 提供浏览器可直接引入的 IIFE 构建版本,适合前端或纯静态页面使用。目前浏览器版本仅支持“Markdown 排版美化”,不支持“发布到微信公众号草稿箱”功能。
160
-
161
- ```html
162
- <script src="https://cdn.jsdelivr.net/npm/css-tree/dist/csstree.js"></script>
163
- <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
164
- <script src="https://cdn.jsdelivr.net/npm/@wenyan-md/core/dist/browser/wenyan-core.js"></script>
165
-
166
- <script>
167
- const { configureMarked, renderMarkdown, themes } = WenyanCore;
168
- const html = await renderMarkdown('# Hello from Browser');
169
- document.body.innerHTML = html;
170
- </script>
171
- ```
172
-
173
- ## Markdown Frontmatter 说明
174
-
175
- 每篇文章顶部需包含 frontmatter:
176
-
177
- ```md
178
- ---
179
- title: 示例文章
180
- cover: /path/to/cover.jpg
181
- description: 文章简介
182
- ---
183
32
  ```
184
33
 
185
- - `title`:必填
186
- - `cover`:本地路径或网络图片(正文有图可省略)
34
+ ## API 文档
187
35
 
188
- ## 微信公众号 IP 白名单
36
+ - [Wenyan Core API 文档](docs/api.md)
37
+ - [Wenyan Core API 文档:Node 环境渲染](docs/node.md)
38
+ - [Wenyan Core API 文档:微信公众号发布](docs/wechat.md)
189
39
 
190
- > ⚠️ 重要
191
- >
192
- > 请确保运行服务的服务器 IP 已加入微信公众号后台 IP 白名单。
40
+ ## 内置主题
193
41
 
194
- 配置说明:[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)
195
45
 
196
46
  ## 赞助
197
47