chore: rename project to emojiTool and brand for git.nomadro.cn
Some checks are pending
Test / test (macos-latest) (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
Test / test (windows-latest) (push) Waiting to run

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hackrobot 2026-10-01 22:09:26 +08:00
parent 5140746d34
commit f13ac764e7
19 changed files with 3008 additions and 1134 deletions

220
README.md
View File

@ -1,159 +1,115 @@
<img src=".erb/img/erb-banner.svg" width="100%" />
# emojiTool
<br>
面向微信公众号、聊天框等**纯文本输入场景**的桌面 Markdown 工具:把 Markdown 转成带 Emoji / Unicode 装饰的纯文本,复制后可直接粘贴,不依赖 HTML/CSS 样式。
<p>
Electron React Boilerplate uses <a href="https://electron.atom.io/">Electron</a>, <a href="https://facebook.github.io/react/">React</a>, <a href="https://github.com/reactjs/react-router">React Router</a>, <a href="https://webpack.js.org/">Webpack</a> and <a href="https://www.npmjs.com/package/react-refresh">React Fast Refresh</a>.
</p>
- 产品名:**emojiTool**
- 窗口标题:emojiTool
- 仓库:[git.nomadro.cn/hackrobot/emojiTool](https://git.nomadro.cn/hackrobot/emojiTool)
- 在线品牌:[mdemoji.com](https://mdemoji.com) / [nomadro.com](https://nomadro.com)
- 公众号:[异度世界](https://www.hackrobot.cn)
- 主开发分支:`greenbook`
<br>
基于 [Electron React Boilerplate](https://github.com/electron-react-boilerplate/electron-react-boilerplate) 改造。
<div align="center">
## 功能
[![Build Status][github-actions-status]][github-actions-url]
[![Github Tag][github-tag-image]][github-tag-url]
[![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/Fjy3vfgy5q)
| 能力 | 说明 |
|------|------|
| Markdown 实时预览 | 左侧编辑、右侧预览,基于 `marked` 自定义 Renderer |
| Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现 |
| 一键复制 | 复制为纯文本(表格用字符边框,粘贴到微信/IM 仍可见结构) |
| 草稿自动保存 | 本地 `localStorage` 持久化正文与页脚开关 |
| 模板与片段 | 内置公众号短文/任务清单等模板,工具栏可插入标题、列表等片段 |
| 页脚开关 | 可关闭/编辑自动追加的署名 |
| 左侧目录 | 解析 `#` 标题大纲,点击跳转 |
| 编辑模式 | MD 源码 / 普通编辑可切换(参考 [MarkText](https://github.com/marktext/marktext) 源码体验) |
| 右键插入 | MD 模式下右键插入标题、任务、表格、代码块等 |
| 外链菜单 | 「公众号: 异度世界」「mdemoji.com」 |
[![OpenCollective](https://opencollective.com/electron-react-boilerplate-594/backers/badge.svg)](#backers)
[![OpenCollective](https://opencollective.com/electron-react-boilerplate-594/sponsors/badge.svg)](#sponsors)
[![StackOverflow][stackoverflow-img]][stackoverflow-url]
### Markdown 装饰规则(摘要)
</div>
- **H1**:`╭──╮` 边框 + `📢` 标题
- **H2 / H3**:前缀 `📝`
- **无序列表**:`🔸`,嵌套用 `┊`
- **有序列表**:`1️⃣` … `🔟`
- **任务列表**:`✅` / `⬜`
- **行内代码**:`『…』`
- **引用**:`└─⚡`
- **分隔线**:`➖➖➖➖➖`
- **链接**:`🔗文案` + URL
- **图片**:固定宽度约 `300px`
- **表格**:表头标注 `📊 表格 📊`
## Install
## 技术栈
Clone the repo and install dependencies:
- **桌面**:Electron 26 + electron-builder
- **前端**:React 18、TypeScript、Ant Design 5、Sass Modules
- **Markdown**:marked
- **构建**:Webpack 5(ERB 配置)、electronmon 热重载
```bash
git clone --depth 1 --branch main https://github.com/electron-react-boilerplate/electron-react-boilerplate.git your-project-name
cd your-project-name
npm install
## 目录结构
```
src/
├── main/ # Electron 主进程(窗口、菜单、自动更新)
│ ├── main.ts
│ ├── menu.ts
│ ├── preload.ts
│ └── util.ts
├── renderer/ # 渲染进程
│ ├── App.tsx # 布局与交互
│ ├── App.module.scss # Ink & Leaf 视觉
│ ├── index.ejs
│ └── lib/
│ ├── emojiMarkdown.ts # Markdown → Emoji 纯文本
│ ├── themes.ts
│ ├── toc.ts # 标题目录
│ ├── editorActions.ts # 右键插入动作
│ ├── storage.ts
│ └── templates.ts
│ └── components/
│ └── EditorPane.tsx # 左侧目录 + 编辑器
└── __tests__/
```
**Having issues installing? See our [debugging guide](https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/400)**
业务逻辑:渲染规则在 `lib/emojiMarkdown.ts`,交互在 `App.tsx`。
## Starting Development
## 开发
Start the app in the `dev` environment:
环境要求:Node.js ≥ 14,npm ≥ 7。
```bash
# 建议使用主开发分支
git checkout greenbook
npm install
npm start
```
## Packaging for Production
常用脚本:
To package apps for the local platform:
| 命令 | 说明 |
|------|------|
| `npm start` | 启动开发环境 |
| `npm run build` | 构建 main + renderer |
| `npm run package` | 打包安装包到 `release/build` |
| `npm test` | 运行 Jest |
| `npm run lint` | ESLint |
```bash
npm run package
```
## 分支说明
## Docs
| 分支 | 说明 |
|------|------|
| **`greenbook`** | 当前最新业务分支,含 emoji 编辑器主体功能 |
| `main` | 接近 ERB 初始脚手架,明显落后于 `greenbook` |
| `feature/emoji` | 历史旁支,已被 `greenbook` 覆盖 |
See our [docs and guides here](https://electron-react-boilerplate.js.org/docs/installation)
## 已知说明
## Community
Join our Discord: https://discord.gg/Fjy3vfgy5q
## Sponsors
<a href="https://palette.dev">
<img src=".erb/img/palette-sponsor-banner.svg" width="100%" />
</a>
## Donations
**Donations will ensure the following:**
- 🔨 Long term maintenance of the project
- 🛣 Progress on the [roadmap](https://electron-react-boilerplate.js.org/docs/roadmap)
- 🐛 Quick responses to bug reports and help requests
## Backers
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/electron-react-boilerplate-594#backer)]
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/0/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/0/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/1/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/1/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/2/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/2/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/3/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/3/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/4/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/4/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/5/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/5/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/6/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/6/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/7/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/7/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/8/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/8/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/9/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/9/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/10/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/10/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/11/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/11/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/12/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/12/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/13/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/13/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/14/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/14/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/15/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/15/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/16/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/16/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/17/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/17/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/18/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/18/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/19/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/19/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/20/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/20/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/21/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/21/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/22/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/22/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/23/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/23/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/24/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/24/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/25/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/25/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/26/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/26/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/27/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/27/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/28/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/28/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/backer/29/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/backer/29/avatar.svg"></a>
## Sponsors
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/electron-react-boilerplate-594-594#sponsor)]
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/0/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/1/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/2/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/3/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/4/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/5/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/6/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/7/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/8/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/9/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/9/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/10/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/10/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/11/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/11/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/12/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/12/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/13/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/13/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/14/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/14/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/15/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/15/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/16/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/16/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/17/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/17/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/18/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/18/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/19/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/19/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/20/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/20/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/21/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/21/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/22/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/22/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/23/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/23/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/24/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/24/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/25/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/25/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/26/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/26/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/27/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/27/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/28/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/28/avatar.svg"></a>
<a href="https://opencollective.com/electron-react-boilerplate-594/sponsor/29/website" target="_blank"><img src="https://opencollective.com/electron-react-boilerplate-594/sponsor/29/avatar.svg"></a>
## Maintainers
- [Amila Welihinda](https://github.com/amilajack)
- [John Tran](https://github.com/jooohhn)
- [C. T. Lin](https://github.com/chentsulin)
- [Jhen-Jie Hong](https://github.com/jhen0409)
- 包名 / `productName` 已统一为 **emojitool** / **emojiTool**。
- 暂无云同步、多窗口;草稿保存在本机 `localStorage`(键:`emojitool.draft`)。
- 提供 A–D 四套纯文本主题,复制优先 `innerText`,表格为全角字符网格。
## License
MIT © [Electron React Boilerplate](https://github.com/electron-react-boilerplate)
[github-actions-status]: https://github.com/electron-react-boilerplate/electron-react-boilerplate/workflows/Test/badge.svg
[github-actions-url]: https://github.com/electron-react-boilerplate/electron-react-boilerplate/actions
[github-tag-image]: https://img.shields.io/github/tag/electron-react-boilerplate/electron-react-boilerplate.svg?label=version
[github-tag-url]: https://github.com/electron-react-boilerplate/electron-react-boilerplate/releases/latest
[stackoverflow-img]: https://img.shields.io/badge/stackoverflow-electron_react_boilerplate-blue.svg
[stackoverflow-url]: https://stackoverflow.com/questions/tagged/electron-react-boilerplate
MIT

155
package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "eltools",
"name": "gitlab-instance-0a899031_eltools",
"lockfileVersion": 3,
"requires": true,
"packages": {
@ -13,6 +13,7 @@
"electron-updater": "^6.1.4",
"lodash": "^4.17.21",
"marked": "^12.0.2",
"nodemon": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.16.0"
@ -37,7 +38,7 @@
"@typescript-eslint/parser": "^6.7.0",
"browserslist-config-erb": "^0.0.3",
"chalk": "^4.1.2",
"concurrently": "^8.2.1",
"concurrently": "^8.2.2",
"core-js": "^3.32.2",
"cross-env": "^7.0.3",
"css-loader": "^6.8.1",
@ -46,6 +47,7 @@
"electron": "^26.2.1",
"electron-builder": "^24.6.4",
"electron-devtools-installer": "^3.2.0",
"electron-reload": "^2.0.0-alpha.1",
"electronmon": "^2.0.2",
"eslint": "^8.49.0",
"eslint-config-airbnb-base": "^15.0.0",
@ -84,6 +86,10 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.9.0"
},
"engines": {
"node": ">=14",
"npm": ">=7"
}
},
"node_modules/@aashutoshrathi/word-wrap": {
@ -5902,7 +5908,6 @@
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
"dev": true,
"dependencies": {
"normalize-path": "^3.0.0",
"picomatch": "^2.0.4"
@ -6498,7 +6503,6 @@
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
"dev": true,
"engines": {
"node": ">=8"
}
@ -6655,7 +6659,6 @@
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"dev": true,
"dependencies": {
"fill-range": "^7.0.1"
},
@ -7117,7 +7120,6 @@
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz",
"integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==",
"dev": true,
"funding": [
{
"type": "individual",
@ -7144,7 +7146,6 @@
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
"dev": true,
"dependencies": {
"is-glob": "^4.0.1"
},
@ -7476,10 +7477,11 @@
"dev": true
},
"node_modules/concurrently": {
"version": "8.2.1",
"resolved": "https://registry.npmjs.org/concurrently/-/concurrently-8.2.1.tgz",
"integrity": "sha512-nVraf3aXOpIcNud5pB9M82p1tynmZkrSGQ1p6X/VY8cJ+2LMVqAgXsJxYYefACSHbTYlm92O1xuhdGTjwoEvbQ==",
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/concurrently/-/concurrently-8.2.2.tgz",
"integrity": "sha512-1dP4gpXFhei8IOtlXRE/T/4H88ElHgTiUzh71YUmtjTEHMSRS2Z/fgOxHSxxusGHogsRfxNq1vyAwxSC+EVyDg==",
"dev": true,
"license": "MIT",
"dependencies": {
"chalk": "^4.1.2",
"date-fns": "^2.30.0",
@ -8966,6 +8968,16 @@
"node": ">=12"
}
},
"node_modules/electron-reload": {
"version": "2.0.0-alpha.1",
"resolved": "https://registry.npmjs.org/electron-reload/-/electron-reload-2.0.0-alpha.1.tgz",
"integrity": "sha512-hTde7gv0TEqxbxlB3pj2CwoyCQ9sdiQrcP8GkpzhosxyVeYM3mZbMEVKCZK3L0fED7Mz5A9IWmK7zEvi4H3P1g==",
"dev": true,
"license": "MIT",
"dependencies": {
"chokidar": "^3.5.2"
}
},
"node_modules/electron-to-chromium": {
"version": "1.4.523",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.523.tgz",
@ -10528,7 +10540,6 @@
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"dev": true,
"dependencies": {
"to-regex-range": "^5.0.1"
},
@ -10784,7 +10795,6 @@
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
@ -11664,6 +11674,12 @@
"node": ">= 4"
}
},
"node_modules/ignore-by-default": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
"license": "ISC"
},
"node_modules/immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
@ -11877,7 +11893,6 @@
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
"dev": true,
"dependencies": {
"binary-extensions": "^2.0.0"
},
@ -11971,7 +11986,6 @@
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
@ -12025,7 +12039,6 @@
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
"dev": true,
"dependencies": {
"is-extglob": "^2.1.1"
},
@ -12106,7 +12119,6 @@
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
"dev": true,
"engines": {
"node": ">=0.12.0"
}
@ -14868,6 +14880,91 @@
"integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==",
"dev": true
},
"node_modules/nodemon": {
"version": "3.1.14",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.14.tgz",
"integrity": "sha512-jakjZi93UtB3jHMWsXL68FXSAosbLfY0In5gtKq3niLSkrWznrVBzXFNOEMJUfc9+Ke7SHWoAZsiMkNP3vq6Jw==",
"license": "MIT",
"dependencies": {
"chokidar": "^3.5.2",
"debug": "^4",
"ignore-by-default": "^1.0.1",
"minimatch": "^10.2.1",
"pstree.remy": "^1.1.8",
"semver": "^7.5.3",
"simple-update-notifier": "^2.0.0",
"supports-color": "^5.5.0",
"touch": "^3.1.0",
"undefsafe": "^2.0.5"
},
"bin": {
"nodemon": "bin/nodemon.js"
},
"engines": {
"node": ">=10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/nodemon"
}
},
"node_modules/nodemon/node_modules/balanced-match": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz",
"integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==",
"license": "MIT",
"engines": {
"node": "18 || 20 || >=22"
}
},
"node_modules/nodemon/node_modules/brace-expansion": {
"version": "5.0.12",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
"integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
"license": "MIT",
"dependencies": {
"balanced-match": "^4.0.2"
},
"engines": {
"node": "20 || >=22"
}
},
"node_modules/nodemon/node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"license": "MIT",
"engines": {
"node": ">=4"
}
},
"node_modules/nodemon/node_modules/minimatch": {
"version": "10.2.6",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz",
"integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==",
"license": "BlueOak-1.0.0",
"dependencies": {
"brace-expansion": "^5.0.8"
},
"engines": {
"node": "18 || 20 || >=22"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/nodemon/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"license": "MIT",
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/nopt": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz",
@ -14914,7 +15011,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
@ -15513,7 +15609,6 @@
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true,
"engines": {
"node": ">=8.6"
},
@ -16318,6 +16413,12 @@
"integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==",
"dev": true
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
"integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==",
"license": "MIT"
},
"node_modules/pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
@ -17296,7 +17397,6 @@
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
"dev": true,
"dependencies": {
"picomatch": "^2.2.1"
},
@ -18291,7 +18391,6 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
"integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==",
"dev": true,
"dependencies": {
"semver": "^7.5.3"
},
@ -19254,7 +19353,6 @@
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
"dev": true,
"dependencies": {
"is-number": "^7.0.0"
},
@ -19285,6 +19383,15 @@
"node": ">=6"
}
},
"node_modules/touch": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz",
"integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==",
"license": "ISC",
"bin": {
"nodetouch": "bin/nodetouch.js"
}
},
"node_modules/tough-cookie": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz",
@ -19713,6 +19820,12 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/undefsafe": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==",
"license": "MIT"
},
"node_modules/unicode-canonical-property-names-ecmascript": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz",

View File

@ -1,35 +1,34 @@
{
"description": "A foundation for scalable desktop apps",
"name": "emojitool",
"productName": "emojiTool",
"description": "emojiTool - Markdown to plain-text emoji editor for WeChat / IM",
"keywords": [
"electron",
"boilerplate",
"react",
"markdown",
"emoji",
"wechat",
"typescript",
"ts",
"sass",
"webpack",
"hot",
"reload"
"react"
],
"homepage": "https://github.com/electron-react-boilerplate/electron-react-boilerplate#readme",
"homepage": "https://git.nomadro.cn/hackrobot/emojiTool",
"bugs": {
"url": "https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues"
"url": "https://git.nomadro.cn/hackrobot/emojiTool/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/electron-react-boilerplate/electron-react-boilerplate.git"
"url": "git+https://git.nomadro.cn/hackrobot/emojiTool.git"
},
"license": "MIT",
"author": {
"name": "Electron React Boilerplate Maintainers",
"email": "electronreactboilerplate@gmail.com",
"url": "https://electron-react-boilerplate.js.org"
"name": "hackrobot",
"email": "hackrobot@nomadro.cn",
"url": "https://www.hackrobot.cn"
},
"contributors": [
{
"name": "Amila Welihinda",
"email": "amilajack@gmail.com",
"url": "https://github.com/amilajack"
"name": "hackrobot",
"email": "hackrobot@nomadro.cn",
"url": "https://git.nomadro.cn/hackrobot"
}
],
"main": "./src/main/main.ts",
@ -177,8 +176,8 @@
"webpack-merge": "^5.9.0"
},
"build": {
"productName": "ElectronReact",
"appId": "org.erb.ElectronReact",
"productName": "emojiTool",
"appId": "cn.nomadro.emojitool",
"asar": true,
"asarUnpack": "**\\*.{node,dll}",
"files": [
@ -235,17 +234,13 @@
"./assets/**"
],
"publish": {
"provider": "github",
"owner": "electron-react-boilerplate",
"repo": "electron-react-boilerplate"
"provider": "generic",
"url": "https://git.nomadro.cn/hackrobot/emojiTool"
}
},
"collective": {
"url": "https://opencollective.com/electron-react-boilerplate-594"
},
"devEngines": {
"node": ">=14.x",
"npm": ">=7.x"
"engines": {
"node": ">=14",
"npm": ">=7"
},
"electronmon": {
"patterns": [

View File

@ -1,12 +1,13 @@
{
"name": "electron-react-boilerplate",
"version": "4.6.0",
"description": "A foundation for scalable desktop apps",
"name": "emojitool",
"productName": "emojiTool",
"version": "1.0.0",
"description": "emojiTool - Markdown to plain-text emoji editor",
"license": "MIT",
"author": {
"name": "Electron React Boilerplate Maintainers",
"email": "electronreactboilerplate@gmail.com",
"url": "https://github.com/electron-react-boilerplate"
"name": "hackrobot",
"email": "hackrobot@nomadro.cn",
"url": "https://www.hackrobot.cn"
},
"main": "./dist/main/main.js",
"scripts": {

View File

@ -77,8 +77,11 @@ const createWindow = async () => {
mainWindow = new BrowserWindow({
show: false,
width: 1024,
height: 728,
width: 1280,
height: 800,
minWidth: 900,
minHeight: 600,
title: 'emojiTool',
icon: getAssetPath('icon.png'),
webPreferences: {
preload: app.isPackaged
@ -89,6 +92,11 @@ const createWindow = async () => {
mainWindow.loadURL(resolveHtmlPath('index.html'));
mainWindow.on('page-title-updated', (event) => {
event.preventDefault();
mainWindow?.setTitle('emojiTool');
});
mainWindow.on('ready-to-show', () => {
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');

View File

@ -54,29 +54,29 @@ export default class MenuBuilder {
buildDarwinTemplate(): MenuItemConstructorOptions[] {
const subMenuAbout: DarwinMenuItemConstructorOptions = {
label: 'Electron',
label: 'emojiTool',
submenu: [
{
label: 'About ElectronReact',
label: '关于 emojiTool',
selector: 'orderFrontStandardAboutPanel:',
},
{ type: 'separator' },
{ label: 'Services', submenu: [] },
{ type: 'separator' },
{
label: 'Hide ElectronReact',
label: '隐藏 emojiTool',
accelerator: 'Command+H',
selector: 'hide:',
},
{
label: 'Hide Others',
label: '隐藏其他',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:',
},
{ label: 'Show All', selector: 'unhideAllApplications:' },
{ label: '全部显示', selector: 'unhideAllApplications:' },
{ type: 'separator' },
{
label: 'Quit',
label: '退出',
accelerator: 'Command+Q',
click: () => {
app.quit();
@ -152,32 +152,18 @@ export default class MenuBuilder {
],
};
const subMenuHelp: MenuItemConstructorOptions = {
label: 'Help',
label: '帮助',
submenu: [
{
label: 'Learn More',
label: '公众号: 异度世界',
click() {
shell.openExternal('https://electronjs.org');
shell.openExternal('https://www.hackrobot.cn');
},
},
{
label: 'Documentation',
label: 'mdemoji.com',
click() {
shell.openExternal(
'https://github.com/electron/electron/tree/main/docs#readme',
);
},
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://www.electronjs.org/community');
},
},
{
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/electron/electron/issues');
shell.openExternal('https://mdemoji.com');
},
},
],
@ -289,10 +275,15 @@ export default class MenuBuilder {
{
label: '公众号: 异度世界',
click() {
// 打开网址
shell.openExternal('https://www.hackrobot.cn');
},
},
{
label: 'mdemoji.com',
click() {
shell.openExternal('https://mdemoji.com');
},
},
],
},
];

View File

@ -1,87 +1,576 @@
html,
body {
// user-select: auto;
:global(html),
:global(body),
:global(#root) {
height: 100%;
margin: 0;
}
p {
padding-top: 0 !important;
padding-bottom:0 !important ;
margin-top: 0 !important;
margin-bottom: 0 !important;
:global(body) {
background:
radial-gradient(1200px 600px at 10% -10%, rgba(13, 148, 136, 0.12), transparent 55%),
radial-gradient(900px 500px at 100% 0%, rgba(15, 118, 110, 0.08), transparent 50%),
linear-gradient(180deg, #eef2f4 0%, #e7ecef 100%);
color: #1a2330;
font-family:
'Segoe UI',
'PingFang SC',
'Noto Sans SC',
'Microsoft YaHei',
sans-serif;
overflow: hidden;
-webkit-font-smoothing: antialiased;
}
.index {
:global(p) {
margin: 0;
padding: 0;
}
:global(a) {
color: #0f766e;
}
.app {
--accent: #0d9488;
--accent-deep: #0f766e;
--ink: #1a2330;
--muted: #5b6b7c;
--line: rgba(26, 35, 48, 0.1);
--panel: rgba(255, 255, 255, 0.78);
--panel-solid: #fbfcfd;
--preview-paper: #f4f7f8;
box-sizing: border-box;
display: flex;
flex-direction: column;
// background-color: yellow;
.up {
user-select: auto;
font-size: 16px;
display: flex;
flex-direction: row;
// align-items: center;
// justify-content: space-between;
padding-left: 30px;
padding-right: 30px;
.upLeft{
width: 50%;
min-height: 20px;
// background-color: yellow;
}
.upRight{
flex: 1;
display: flex;
// background-color: green;
flex-direction: row-reverse;
}
}
.down {
// font-size: 28px;
user-select: auto;
font-size: 16px;
display: flex;
flex-direction: row;
// align-items: center;
// justify-content: space-between;
padding-left: 30px;
padding-right: 30px;
.left {
width: 50%;
// min-height: 200px;
// background-color: yellow;
// border: 1px solid red;
// padding: 20px;
min-height: 800px;
.TextArea {
// background-color: yellow;
// height: 100vh;
height: 800px;
}
}
.right {
flex: 1;
// border: 1px solid red;
// padding-top: 20px;
// padding-bottom: 20px;
// background-color: yellow;
.rightHtml {
user-select: auto;
border: 1px solid red;
// padding-top: 10px;
padding-left: 10px;
// background-color: greenyellow;
height: 800px;
overflow-y: auto;
}
}
.origin {
flex: 1;
border: 1px solid red
// padding: 20px;
}
}
height: 100%;
min-height: 100vh;
padding: 18px 20px 16px;
gap: 12px;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
flex-shrink: 0;
animation: riseIn 420ms ease both;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brandMark {
width: 42px;
height: 42px;
border-radius: 12px;
display: grid;
place-items: center;
color: #ecfeff;
font-size: 18px;
background: linear-gradient(145deg, #14b8a6 0%, #0f766e 100%);
box-shadow: 0 10px 24px rgba(13, 148, 136, 0.28);
}
.title {
margin: 0;
font-size: 22px;
line-height: 1.2;
letter-spacing: 0.02em;
font-weight: 700;
color: var(--ink);
}
.subtitle {
margin: 4px 0 0;
font-size: 12px;
color: var(--muted);
letter-spacing: 0.01em;
}
.actions {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
justify-content: flex-end;
}
.themeSwitch {
background: rgba(255, 255, 255, 0.7) !important;
}
.themeMenuItem {
display: flex;
flex-direction: column;
gap: 2px;
max-width: 260px;
padding: 2px 0;
strong {
font-size: 13px;
color: var(--ink, #1a2330);
}
span {
font-size: 12px;
color: var(--muted, #5b6b7c);
line-height: 1.4;
white-space: normal;
}
}
.footerToggle {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.65);
border: 1px solid var(--line);
color: var(--muted);
font-size: 12px;
flex-shrink: 0;
}
.footerPanel {
flex-shrink: 0;
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px 14px;
border-radius: 14px;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.7);
box-shadow: 0 8px 24px rgba(26, 35, 48, 0.06);
animation: riseIn 600ms ease both;
transition: opacity 180ms ease;
}
.footerPanelOff {
opacity: 0.72;
}
.footerPanelHead {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.footerHint {
margin: 0;
flex: 1;
min-width: 160px;
font-size: 12px;
color: var(--muted);
}
.footerEditor {
font-family:
'Cascadia Code',
'JetBrains Mono',
Consolas,
'Microsoft YaHei',
monospace !important;
font-size: 13px !important;
line-height: 1.55 !important;
background: rgba(255, 255, 255, 0.85) !important;
}
.snippetBar {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
flex-shrink: 0;
animation: riseIn 480ms ease both;
}
.snippetLabel {
font-size: 12px;
color: var(--muted);
margin-right: 2px;
}
.snippetBtn {
appearance: none;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.7);
color: var(--ink);
border-radius: 999px;
padding: 4px 12px;
font-size: 12px;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
&:hover {
background: #fff;
border-color: rgba(13, 148, 136, 0.45);
transform: translateY(-1px);
}
&:active {
transform: translateY(0);
}
}
.saveHint {
margin-left: auto;
font-size: 12px;
color: var(--muted);
transition: color 200ms ease;
}
.workspace {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px;
animation: riseIn 560ms ease both;
}
.pane {
min-width: 0;
min-height: 0;
display: flex;
flex-direction: column;
background: var(--panel);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 16px;
box-shadow: 0 12px 40px rgba(26, 35, 48, 0.08);
overflow: hidden;
}
.previewPane {
background: var(--panel-solid);
}
.paneHeader {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 16px;
border-bottom: 1px solid var(--line);
flex-shrink: 0;
gap: 10px;
}
.paneHeaderLeft,
.paneHeaderRight {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
}
.paneTitle {
font-size: 13px;
font-weight: 650;
letter-spacing: 0.04em;
text-transform: uppercase;
color: var(--accent-deep);
}
.paneMeta {
font-size: 12px;
color: var(--muted);
white-space: nowrap;
}
.tocToggle {
appearance: none;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.75);
color: var(--muted);
border-radius: 999px;
padding: 2px 10px;
font-size: 12px;
cursor: pointer;
&:hover {
color: var(--accent-deep);
border-color: rgba(13, 148, 136, 0.4);
}
}
.editorPane {
min-width: 0;
}
.editorBody {
flex: 1;
min-height: 0;
display: flex;
flex-direction: row;
}
.tocPanel {
width: 168px;
flex-shrink: 0;
border-right: 1px solid var(--line);
background: rgba(247, 250, 251, 0.95);
overflow: auto;
padding: 10px 8px 12px;
}
.tocTitle {
font-size: 11px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--muted);
padding: 0 6px 8px;
}
.tocEmpty {
margin: 0;
padding: 6px;
font-size: 12px;
color: var(--muted);
line-height: 1.5;
}
.tocList {
list-style: none;
margin: 0;
padding: 0;
}
.tocItem {
appearance: none;
width: 100%;
border: none;
background: transparent;
text-align: left;
cursor: pointer;
color: var(--ink);
font-size: 12px;
line-height: 1.4;
padding: 6px 8px;
border-radius: 8px;
display: flex;
align-items: flex-start;
gap: 6px;
overflow: hidden;
text-overflow: ellipsis;
&:hover {
background: rgba(13, 148, 136, 0.1);
}
}
.tocItemActive {
background: rgba(13, 148, 136, 0.14);
color: var(--accent-deep);
font-weight: 600;
}
.tocLevel {
flex-shrink: 0;
font-size: 10px;
color: var(--muted);
margin-top: 1px;
}
.editorWrap {
flex: 1;
min-width: 0;
min-height: 0;
display: flex;
flex-direction: column;
}
.editorMarkdown .editor {
font-family:
'Cascadia Code',
'JetBrains Mono',
'SF Mono',
Consolas,
'Microsoft YaHei',
monospace !important;
}
.editorPlain .editor {
font-family:
'Segoe UI',
'PingFang SC',
'Microsoft YaHei',
sans-serif !important;
font-size: 15px !important;
line-height: 1.8 !important;
}
.editor {
flex: 1 !important;
min-height: 0 !important;
height: 100% !important;
resize: none !important;
border: none !important;
border-radius: 0 !important;
box-shadow: none !important;
background: transparent !important;
padding: 16px 18px !important;
font-size: 14px !important;
line-height: 1.7 !important;
&:focus {
box-shadow: none !important;
}
}
.previewScroll {
flex: 1;
min-height: 0;
overflow: auto;
background:
linear-gradient(180deg, rgba(244, 247, 248, 0.95), rgba(244, 247, 248, 1)),
repeating-linear-gradient(
0deg,
transparent,
transparent 27px,
rgba(13, 148, 136, 0.04) 28px
);
}
.previewHtml {
padding: 18px 20px 28px;
font-size: 15px;
line-height: 1.75;
color: var(--ink);
user-select: text;
animation: fadeIn 220ms ease;
:global(img) {
max-width: 100%;
height: auto;
border-radius: 8px;
}
:global(.emoji-footer) {
margin-top: 16px;
padding-top: 4px;
color: var(--ink);
line-height: 1.7;
}
:global(.emoji-table) {
margin: 8px 0 12px;
line-height: 1.45;
}
:global(.emoji-table pre) {
margin: 0;
padding: 10px 12px;
white-space: pre;
overflow-x: auto;
/* Fullwidth grid does not need dual-width mono; any CJK font works */
font-family:
'Microsoft YaHei',
'PingFang SC',
'Noto Sans SC',
'Segoe UI',
sans-serif;
font-size: 14px;
line-height: 1.55;
letter-spacing: 0;
font-variant-ligatures: none;
background: rgba(26, 35, 48, 0.04);
border: 1px dashed rgba(26, 35, 48, 0.18);
border-radius: 8px;
}
:global(.emoji-code) {
margin: 8px 0 12px;
padding: 10px 12px;
border: 1px solid rgba(26, 35, 48, 0.16);
border-radius: 8px;
background: rgba(26, 35, 48, 0.04);
font-size: 13px;
}
:global(.emoji-code pre) {
margin: 8px 0 0;
white-space: pre-wrap;
word-break: break-word;
font-family:
'Cascadia Code',
'JetBrains Mono',
Consolas,
monospace;
line-height: 1.55;
}
}
.emptyState {
height: 100%;
min-height: 240px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
padding: 32px;
color: var(--muted);
animation: fadeIn 280ms ease;
}
.emptyTitle {
margin: 0 0 8px;
font-size: 18px;
font-weight: 650;
color: var(--ink);
}
.emptyDesc {
margin: 0;
font-size: 13px;
line-height: 1.7;
max-width: 280px;
}
@keyframes riseIn {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@media (max-width: 900px) {
.workspace {
grid-template-columns: 1fr;
}
.header {
flex-direction: column;
align-items: flex-start;
}
.actions {
width: 100%;
justify-content: flex-start;
}
}

View File

@ -1,82 +1 @@
html,
body {
user-select: auto;
}
p {
padding: 0 !important;
margin: 0 !important;
}
.index {
display: flex;
flex-direction: column;
.up {
user-select: auto;
font-size: 16px;
display: flex;
flex-direction: row;
// align-items: center;
// justify-content: space-between;
padding-left: 30px;
padding-right: 30px;
.upLeft{
width: 50%;
min-height: 20px;
// background-color: yellow;
}
.upRight{
flex: 1;
display: flex;
// background-color: green;
flex-direction: row-reverse;
}
}
.down {
// font-size: 28px;
user-select: auto;
font-size: 16px;
display: flex;
flex-direction: row;
// align-items: center;
// justify-content: space-between;
padding-left: 30px;
padding-right: 30px;
.left {
width: 50%;
// min-height: 200px;
// background-color: yellow;
// border: 1px solid red;
// padding: 20px;
min-height: 800px;
.TextArea {
// background-color: yellow;
// height: 100vh;
height: 800px;
}
}
.right {
flex: 1;
// border: 1px solid red;
// padding-top: 20px;
// padding-bottom: 20px;
// background-color: yellow;
.rightHtml {
border: 1px solid red;
// padding-top: 10px;
padding-left: 10px;
// background-color: greenyellow;
height: 800px;
overflow-y: auto;
}
}
.origin {
flex: 1;
border: 1px solid red
// padding: 20px;
}
}
}
/* Legacy global styles replaced by App.module.scss */

View File

@ -1,454 +1,378 @@
import { Component, useRef } from 'react';
import { Input } from 'antd';
import { Button, Flex, Modal, Space } from 'antd';
// import Taro from "@tarojs/taro";
// import {
// View,
// Text,
// Image,
// Button,
// Input,
// Editor,
// Textarea,
// } from "@tarojs/components";
// import './APP.scss';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import {
Button,
ConfigProvider,
Dropdown,
Input,
Modal,
Switch,
Tooltip,
message,
} from 'antd';
import type { MenuProps } from 'antd';
import {
DEFAULT_FOOTER_TEXT,
THEME_LIST,
renderEmojiMarkdown,
type ThemeId,
} from './lib/emojiMarkdown';
import { loadDraft, saveDraft, type EditorMode } from './lib/storage';
import { DEFAULT_TEMPLATE_CONTENT, SNIPPETS, TEMPLATES } from './lib/templates';
import { EDITOR_ACTIONS, applyEditorAction } from './lib/editorActions';
import EditorPane from './components/EditorPane';
import styles from './App.module.scss';
// import { AtTabBar } from "taro-ui";
import React, { useCallback, useEffect, useState } from 'react';
// import { AtGrid } from "taro-ui";
// import { Swiper, SwiperItem } from "@tarojs/components";
// import { AtCard } from "taro-ui";
// import { AtImagePicker } from "taro-ui";
// import { AtButton } from "taro-ui";
// import { AtSearchBar } from "taro-ui";
// import { Picker } from "@tarojs/components";
// import { AtList, AtListItem } from "taro-ui";
// import { AtNavBar } from "taro-ui";
// import { AtModal, AtModalHeader, AtModalContent, AtModalAction } from "taro-ui";
// import { AtToast } from "taro-ui";
// import { AtIcon } from "taro-ui";
import see from '../../images/see.png';
import group from '../../images/group.png';
import { marked } from 'marked';
// import _ from "lodash";
import OriginMark from './conpoments/OriginMark/index';
import TextArea from 'antd/es/input/TextArea';
const { TextArea } = Input;
// marked.use(`marked-code-jsx-renderer`);
// marked.use(`marked-extended-tables`);
const SAVE_DEBOUNCE_MS = 400;
// ![测试图片2](http://hackrobot-1258475618.cos.ap-shenzhen-fsi.myqcloud.com/202304081955211.png)
function App() {
const previewRef = useRef<HTMLDivElement>(null);
const initial = useMemo(() => loadDraft(), []);
const createDecoratedTitleHTML = (text: any) => {
const padding = 2; // 内容左右两边的空格数
const [content, setContent] = useState(initial.content);
const [appendFooter, setAppendFooter] = useState(initial.appendFooter);
const [footerText, setFooterText] = useState(initial.footerText);
const [themeId, setThemeId] = useState<ThemeId>(initial.themeId);
const [editorMode, setEditorMode] = useState<EditorMode>(initial.editorMode);
const [tocOpen, setTocOpen] = useState(initial.tocOpen);
const [savedHint, setSavedHint] = useState(false);
const lineChar = '─'; // 水平线字符
const edgeChar = '─'; // 边框装饰字符
// const edgeChar = '━'; // 边框装饰字符
// const cornerTopLeft = '╔';
// const cornerTopRight = '╗';
// const cornerBottomLeft = '╚';
// const cornerBottomRight = '╝';
const cornerTopLeft = '╭'; // 顶部左角
const cornerTopRight = '╮'; // 顶部右角
const cornerBottomLeft = '╰'; // 底部左角
const cornerBottomRight = '╯'; // 底部右角
const activeTheme = useMemo(
() => THEME_LIST.find((t) => t.id === themeId) ?? THEME_LIST[0],
[themeId],
);
// 计算标题长度
const titleLength = text.length + padding * 2;
const lineLength = lineChar.repeat(titleLength);
const edgeLength = edgeChar.repeat(titleLength);
const previewHtml = useMemo(
() =>
renderEmojiMarkdown(content, {
appendFooter,
footerText,
themeId,
}),
[content, appendFooter, footerText, themeId],
);
// 构造 HTML
const topBorder = `${cornerTopLeft}${edgeLength}${cornerTopRight}`;
const bottomBorder = `${cornerBottomLeft}${edgeLength}${cornerBottomRight}`;
const middleLine = ` 📢 ${text}`;
// const middleLine = ` ⚡ ${text}`;
const charCount = content.length;
const hasContent = content.trim().length > 0;
useEffect(() => {
const timer = window.setTimeout(() => {
saveDraft({
content,
appendFooter,
footerText,
themeId,
editorMode,
tocOpen,
});
setSavedHint(true);
}, SAVE_DEBOUNCE_MS);
return () => window.clearTimeout(timer);
}, [content, appendFooter, footerText, themeId, editorMode, tocOpen]);
return `<div>${topBorder}<br/>${middleLine}<br/>${bottomBorder}</div>`;
// return `<div>${topBorder}<br/>${middleLine}<br/>${bottomBorder}</div><br/>`;
};
useEffect(() => {
if (!savedHint) return undefined;
const timer = window.setTimeout(() => setSavedHint(false), 1200);
return () => window.clearTimeout(timer);
}, [savedHint]);
marked.setOptions({
breaks: true, // 是否回车换行
gfm: true, //使用经批准的 GitHub Flavored Markdown (GFM) 规范
// pedantic: true, //严格模式
// highlight(code:any, lang:any) {
// // 语法高亮
// let val = code;
// if (lang) {
// val = hljs.highlight(lang, code).value;
// } else {
// val = hljs.highlightAuto(code).value;
// }
// return val;
// },
});
// 符号
// 🔥❓👉
// 0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟
// ©️⭐🔍〰️➖
const copyPreview = useCallback(async () => {
if (!previewRef.current || !hasContent) {
message.warning('还没有可复制的内容');
return;
}
try {
await navigator.clipboard.writeText(previewRef.current.innerText);
message.success('已复制纯文本,可粘贴到微信/公众号等输入框');
} catch {
message.error('复制失败,请检查剪贴板权限');
}
}, [hasContent]);
// 修改 marked 的解析规则
// const block = marked.Lexer.rules.block;
// block.gfm.hr = /^( *[-*_]){3,} *(?:\n+|$)/;
// 自定义水平线规则,确保它们在文档中被正确识别
// block.gfm.hr =
// /^ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
const clearContent = useCallback(() => {
if (!hasContent) {
setContent('');
return;
}
Modal.confirm({
title: '清空当前内容?',
content: '正文草稿会被清空,主题与页脚设置会保留。',
okText: '清空',
cancelText: '取消',
okButtonProps: { danger: true },
onOk: () => {
setContent('');
message.success('已清空');
},
});
}, [hasContent]);
const renderer = new marked.Renderer();
// const originRenderer = _.cloneDeep(renderer);
const resetFooter = useCallback(() => {
setFooterText(DEFAULT_FOOTER_TEXT);
message.success('已恢复默认页脚');
}, []);
// 图片调整300px
renderer.image = function (href, title, text) {
// console.log("href, title, text", href, title, text);
// <div class="desc">${text}</div>
return `<img width="300px" src="${href}" alt="${text}"/>`;
};
const applyTheme = useCallback((next: ThemeId) => {
setThemeId(next);
const theme = THEME_LIST.find((item) => item.id === next);
message.success(`已切换:${theme?.name ?? next}`);
}, []);
let listSinbal = '🔸';
// 有序列表
renderer.list = function (body, ordered, start) {
const type = ordered ? 'ol' : 'ul';
const startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
const applyTemplate = useCallback(
(templateContent: string, label?: string) => {
setContent(templateContent);
message.success(label ? `已填入「${label}」` : '已填入模板');
},
[],
);
// 移除 `<div>` 和 `</div>` 标签
const cleanedBody = body.replace(/<\/?div>/g, '');
// 正则表达式匹配每个以 <br/> 结尾的列表项
const regex = /([^<]*)<br\/?>/g;
const input = cleanedBody;
// 正则取值
// // const regex = /▫️\s*(.*?)<br\/?>/g;
// const regex = /([^<]*)<br\/?>/g;
// const input = body;
// console.log('input--', input);
const matches = [...input.matchAll(regex)];
console.log('matches--', matches);
const texts = matches.map((match) => match[1]);
console.log('texts===>', texts); // 输出: ["测试111", "测试222", "if"]
const newArray = texts.filter((item) => item.includes(listSinbal));
const numbers = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟'];
// ┊ │ ╏
const string = texts
.map((value, index) => {
console.log('value--', value);
// 判断是否是任务
let task = false;
if (value.includes('🔸⬜') || value.includes('🔸✅')) {
task = true;
const insertSnippet = useCallback(
(snippet: string) => {
const action = EDITOR_ACTIONS.find((item) => item.insert === snippet);
if (action) {
const result = applyEditorAction(
content,
content.length,
content.length,
action,
);
setContent(result.next);
return;
}
return value.indexOf(listSinbal) !== -1
? `<div>${
type === 'ol'
? numbers[newArray.indexOf(value)]
: task
? ''
: listSinbal
}${value.replace(listSinbal, '')} </div>`
: `<div style="white-space:pre;">&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;┊ ${value}</div>`;
})
.join('');
return `${string}`;
};
// 示例输入
const input = `🔸11<br/>🔸22<br/><br/>🔸33`;
console.log(renderer.list(input, false, 1));
// 无序列表 ▫️
renderer.listitem = function (text, task, checked) {
// return `<li>${text}</li>\n`;
return `${listSinbal}${text}<br/>`;
return `${listSinbal}${text}\n`;
// return `${listSinbal}${text}\n`;
// return `➖${text}<br/>`;
};
// 任务列表
renderer.checkbox = function (checked) {
// ✅❌⬜
return !!checked ? '✅' : '⬜';
return (
'<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox">'
setContent((prev) => `${prev}${snippet}`);
},
[content],
);
};
// 标题
renderer.heading = function (text, level, raw) {
console.log('text, level, raw', text, level, raw);
// ignore IDs
// return `📋<span>${text}</span> <br/>`;
// return `🔥<span>${text}</span> <br/>`;
if (level == 1) {
return createDecoratedTitleHTML(text);
} else if (level == 2) {
return `<div>📝${text}</div>\n`;
} else {
return `<div>📝${text}</div>\n`;
}
const persistNow = useCallback(() => {
saveDraft({
content,
appendFooter,
footerText,
themeId,
editorMode,
tocOpen,
});
setSavedHint(true);
message.success('草稿已保存');
}, [content, appendFooter, footerText, themeId, editorMode, tocOpen]);
return `<div>╔═━──────━═╗<br/>
🔥 ${text}<br/>
╚═━──────━═╝
</div>\n`;
useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
const meta = event.ctrlKey || event.metaKey;
if (!meta) return;
// return `<div>* * * * * * * * * * *<br/>
// * ${text} *<br/>
// * * * * * * * * * * *
// </div>\n`;
if (event.key === 'Enter') {
event.preventDefault();
copyPreview();
} else if (event.key.toLowerCase() === 's') {
event.preventDefault();
persistNow();
} else if (event.key.toLowerCase() === 'b' && editorMode === 'markdown') {
// MarkText-like bold shortcut when not in plain mode
event.preventDefault();
const bold = EDITOR_ACTIONS.find((item) => item.id === 'bold');
if (!bold) return;
const el = document.activeElement as HTMLTextAreaElement | null;
const start = el?.selectionStart ?? content.length;
const end = el?.selectionEnd ?? content.length;
const result = applyEditorAction(content, start, end, bold);
setContent(result.next);
}
};
window.addEventListener('keydown', onKeyDown);
return () => window.removeEventListener('keydown', onKeyDown);
}, [copyPreview, persistNow, editorMode, content]);
// return `<div>==================<br/>
// || 📢 ${text} 📢 ||<br/>
// ==================</div>\n`;
const themeItems: MenuProps['items'] = THEME_LIST.map((theme) => ({
key: theme.id,
label: (
<div className={styles.themeMenuItem}>
<strong>{theme.shortName}</strong>
<span>{theme.description}</span>
</div>
),
onClick: () => applyTheme(theme.id),
}));
// return `<h${level}>🔥<span>${text}</span></h${level}>\n`;
// return `<h${level}>🔥${text}</h${level}><br/>`;
};
renderer.text = function (text) {
return text;
};
// 分隔符
renderer.hr = function () {
// return '<hr>\n';
// return '➖➖➖➖➖<br/>';
return '➖➖➖➖➖\n';
};
// 自定义分隔线解析规则
// marked.Lexer.rules.block.gfm.hr = /^(\*{3,}|-{3,}|_{3,})(?:\s*)$/;
// hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
// 内联样式,使用直角引号「」
renderer.codespan = function (text) {
// return `「${text}」`;
return `『${text}』`;
};
// 引用符号
renderer.blockquote = function (quote) {
// console.log("quote", quote);
let content = null;
// var regex = /<p>(.*?)<\/p>/;
var regex = /<div>(.*?)<\/div>/;
var str = quote;
var match = regex.exec(str);
if (match != null) {
content = match[1]; // 获取第一个捕获组的内容
// console.log(content);
}
// <pre></pre>
// &nbsp;
// return `<span style="white-space:pre;" class="blockquote">\t 👉${content}</span><br/> `
// return `<div style="white-space:pre;" class="blockquote">\t 📌${content}</div>\n`; //ok
// ├─⚡
return `<div style="white-space:pre;" class="blockquote">&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;└─⚡${content}</div>`;
};
renderer.table = function (header, body) {
if (body) body = `<tbody>${body}</tbody>`;
const templateItems: MenuProps['items'] = TEMPLATES.map((item) => ({
key: item.id,
label: item.label,
onClick: () => applyTemplate(item.content, item.label),
}));
return (
'📊 表格 📊<br/><table>\n' +
'<thead>\n' +
header +
'</thead>\n' +
body +
'</table>\n'
<ConfigProvider
theme={{
token: {
colorPrimary: '#0d9488',
colorInfo: '#0d9488',
borderRadius: 10,
fontFamily:
'"Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif',
},
}}
>
<div className={styles.app}>
<header className={styles.header}>
<div className={styles.brand}>
<div className={styles.brandMark} aria-hidden>
✦
</div>
<div>
<h1 className={styles.title}>emojiTool</h1>
<p className={styles.subtitle}>
Markdown → 公众号友好纯文本 · nomadro.com
</p>
</div>
</div>
<div className={styles.actions}>
<Dropdown
menu={{
items: themeItems,
selectable: true,
selectedKeys: [themeId],
}}
placement="bottomRight"
>
<Button className={styles.themeSwitch}>
主题 · {activeTheme.shortName} ▾
</Button>
</Dropdown>
<Dropdown menu={{ items: templateItems }} placement="bottomRight">
<Button>模板 ▾</Button>
</Dropdown>
<Button
onClick={() =>
applyTemplate(DEFAULT_TEMPLATE_CONTENT, '语法全览(默认)')
}
>
重置示例
</Button>
<Button onClick={clearContent} disabled={!hasContent}>
清空
</Button>
<Tooltip title="Ctrl / ⌘ + Enter">
<Button
type="primary"
onClick={copyPreview}
disabled={!hasContent}
>
复制预览
</Button>
</Tooltip>
</div>
</header>
<div className={styles.snippetBar}>
<span className={styles.snippetLabel}>插入</span>
{SNIPPETS.map((snippet) => (
<button
key={snippet.id}
type="button"
className={styles.snippetBtn}
onClick={() => insertSnippet(snippet.insert)}
>
{snippet.label}
</button>
))}
<span className={styles.saveHint}>
{savedHint
? '已自动保存'
: `${activeTheme.name} · 右键可插入样式`}
</span>
</div>
<main className={styles.workspace}>
<EditorPane
content={content}
onChange={setContent}
mode={editorMode}
onModeChange={setEditorMode}
tocOpen={tocOpen}
onTocOpenChange={setTocOpen}
charCount={charCount}
/>
<section className={`${styles.pane} ${styles.previewPane}`}>
<div className={styles.paneHeader}>
<span className={styles.paneTitle}>公众号预览</span>
<span className={styles.paneMeta}>{activeTheme.name}</span>
</div>
<div className={styles.previewScroll}>
{hasContent ? (
<div
ref={previewRef}
className={styles.previewHtml}
dangerouslySetInnerHTML={{ __html: previewHtml }}
/>
) : (
<div className={styles.emptyState}>
<p className={styles.emptyTitle}>开始写一篇</p>
<p className={styles.emptyDesc}>
左侧可切换 MD / 普通编辑,右键插入任务、表格等。
<br />
目录可跳转到标题;右侧即时预览主题排版。
</p>
</div>
)}
</div>
</section>
</main>
<section
className={`${styles.footerPanel} ${
appendFooter ? '' : styles.footerPanelOff
}`}
>
<div className={styles.footerPanelHead}>
<div className={styles.footerToggle}>
<span>页脚署名</span>
<Switch
size="small"
checked={appendFooter}
onChange={setAppendFooter}
/>
</div>
<p className={styles.footerHint}>
{appendFooter
? '开启后追加到预览末尾,可自由编辑文案'
: '已关闭,复制时不会带页脚'}
</p>
<Button
type="link"
size="small"
onClick={resetFooter}
disabled={!appendFooter}
>
恢复默认
</Button>
</div>
<TextArea
className={styles.footerEditor}
value={footerText}
onChange={(e) => setFooterText(e.target.value)}
disabled={!appendFooter}
autoSize={{ minRows: 2, maxRows: 4 }}
placeholder="编辑页脚文案…"
spellCheck={false}
/>
</section>
</div>
</ConfigProvider>
);
};
renderer.tablerow = function (content) {
return `<tr>\n${content}</tr>\n`;
};
renderer.tablecell = function (content, flags) {
const type = flags.header ? 'th' : 'td';
const tag = flags.align ? `<${type} align="${flags.align}">` : `<${type}>`;
return tag + `|${content}` + `</${type}>\n`;
};
function cleanUrl(href: any) {
try {
href = encodeURI(href).replace(/%25/g, '%');
} catch (e) {
return null;
}
return href;
}
renderer.link = function (href, title, text) {
const cleanHref = cleanUrl(href);
if (cleanHref === null) {
return text;
}
href = cleanHref;
console.log('href-', href);
let out = '<a href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
}
out += '>' + `🔗` + text + '</a>';
// out += ">" +`🔗`+ text + "</a>"+`(${href})`;
// console.log('out-',out)
return out + `: ${href}`;
};
renderer.paragraph = function (text) {
// return `<p>${text}</p>\n`;
// return `<p>${text}</p>`;
return `<div>${text}</div>`;
};
renderer.br = function () {
return '<br>';
};
renderer.html = function (html, block) {
return html;
};
// 使用拓展
marked.use({ renderer });
// export default class Index extends Component {
const Index = () => {
const divRef = useRef(null);
const [inputValue, setinputValue] = useState('');
const [markText, setmarkText] = useState(``);
const [oldmarkText, setoldmarkText] = useState(null);
const [currentRender, setcurrentRender] = useState(null);
const [markdownTable, setmarkdownTable] = useState();
const [tablecellArr, settablecellArr] = useState([]);
const onConfirm = (onConfirmtxt: any) => {
console.log('onConfirmtxt--->', onConfirmtxt.detail.value);
};
const onBlur = (onBlurtxt: any) => {
console.log('onBlurtxt--->', onBlurtxt.detail.value);
if (onBlurtxt.detail.value) {
setmarkText(onBlurtxt.detail.value);
}
};
const onInput = (onInputtxt: any) => {
console.log('onInputtxt--->', onInputtxt?.target?.value);
setinputValue(onInputtxt.target.value);
// console.log('inputValue',inputValue)
// let value = onInputtxt?.target?.value;
let value = onInputtxt?.target?.value;
// +`🅥🟢🆔:hackrobot`
// +`➕🅥=>🟩🆔: hackrobot,可以找我聊天💬 `
// let contactMe=`<br>➖➖➖➖➖<br/>在🟩【wΞ𝗫𝗜𝗡】➡️联系我 【➕🅥】:
// ╭────────────────╮
// │ 🆔 hackrobot
// ╰────────────────╯
// 💬 随时欢迎聊天
// `
// │ 💬 随时欢迎聊天
// let contactMe = `<br>╭────────────────╮
// │ 🟩【wΞ𝗫𝗜𝗡】➡️联系我【➕🅥】
// │
// │ 🆔 hackrobot
// ╰────────────────╯<br>💬 随时欢迎聊天`;
// let contactMe = `<br>➖➖➖➖➖<br>💬 欢迎交流<br>后台私信发送『关键词』: 加群`;
let contactMe = `<br>➖➖➖➖➖<br>©️ 本文使用🔗『mdemoji.com』 编辑 `;
// setmarkText(value);
// setmarkText(value + contactMe);
if (value?.length < 10) {
setmarkText(value);
} else {
setmarkText(value + contactMe);
}
};
useEffect(() => {}, []);
const copyToClipboard = () => {
if (divRef.current) {
const htmlContentinnerHTML = divRef.current.innerHTML;
console.log('htmlContentinnerHTML', htmlContentinnerHTML);
const htmlContentouterHTML = divRef.current.outerHTML;
console.log('htmlContentouterHTML', htmlContentouterHTML);
const htmlContent = divRef.current.innerText;
// const htmlContent = divRef.current.textContent;
navigator.clipboard
.writeText(htmlContent)
.then(() => {
// alert('Content copied to clipboard!');
})
.catch((err) => {
console.error('Error copying text: ', err);
});
}
};
const info = () => {
Modal.info({
title: 'This is a notification message',
content: (
<div>
<p>some messages...some messages...</p>
<p>some messages...some messages...</p>
</div>
),
onOk() {},
});
};
return (
<div className={styles.index}>
<div className={styles.up}>
<div className={styles.upLeft}>
{/* <Button type="text" danger>
公众号: 异度世界
</Button> */}
</div>
<div className={styles.upRight}>
{/* <button onClick={copyToClipboard}>Copy to Clipboarrd</button> */}
{/* <Button type="primary" onClick={copyToClipboard}>复制</Button> */}
<Button onClick={copyToClipboard}>复制</Button>
</div>
</div>
<div className={styles.down}>
<div className={styles.left}>
<TextArea
// styles="background:#fff;width:100%;min-height:80px;padding:0 30rpx;"
className={styles.TextArea}
autoFocus
allowClear
onChange={onInput}
showCount
/>
</div>
<div className={styles.right}>
<div
className={styles.rightHtml}
ref={divRef}
dangerouslySetInnerHTML={{ __html: marked(markText) }}
></div>
</div>
{/* <div className="origin">
<OriginMark markText={markText} />
</div> */}
</div>
</div>
);
};
export default Index;
export default App;

View File

@ -0,0 +1,225 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { Dropdown, Input, Segmented, Tooltip } from 'antd';
import type { MenuProps } from 'antd';
import type { TextAreaRef } from 'antd/es/input/TextArea';
import {
EDITOR_ACTIONS,
applyEditorAction,
type EditorAction,
} from '../lib/editorActions';
import { offsetAtLine, parseToc } from '../lib/toc';
import styles from '../App.module.scss';
const { TextArea } = Input;
export type EditorMode = 'markdown' | 'plain';
type Props = {
content: string;
onChange: (value: string) => void;
mode: EditorMode;
onModeChange: (mode: EditorMode) => void;
tocOpen: boolean;
onTocOpenChange: (open: boolean) => void;
charCount: number;
};
export default function EditorPane({
content,
onChange,
mode,
onModeChange,
tocOpen,
onTocOpenChange,
charCount,
}: Props) {
const textareaRef = useRef<TextAreaRef>(null);
const [activeTocId, setActiveTocId] = useState<string | null>(null);
const getTextArea = () =>
textareaRef.current?.resizableTextArea?.textArea ?? null;
const toc = useMemo(() => parseToc(content), [content]);
const focusAndSelect = useCallback((start: number, end: number) => {
window.requestAnimationFrame(() => {
const el = getTextArea();
if (!el) return;
el.focus();
el.setSelectionRange(start, end);
// Keep caret roughly in view
const lineHeight = 24;
const before = el.value.slice(0, start);
const line = before.split('\n').length - 1;
el.scrollTop = Math.max(0, line * lineHeight - el.clientHeight / 3);
});
}, []);
const runAction = useCallback(
(action: EditorAction) => {
const el = getTextArea();
const start = el?.selectionStart ?? content.length;
const end = el?.selectionEnd ?? content.length;
const result = applyEditorAction(content, start, end, action);
onChange(result.next);
focusAndSelect(result.selectionStart, result.selectionEnd);
},
[content, focusAndSelect, onChange],
);
const jumpToHeading = useCallback(
(line: number, id: string) => {
setActiveTocId(id);
const start = offsetAtLine(content, line);
const lineText = content.replace(/\r\n/g, '\n').split('\n')[line] ?? '';
focusAndSelect(start, start + lineText.length);
},
[content, focusAndSelect],
);
const contextItems: MenuProps['items'] = useMemo(() => {
const groups: Array<{
key: string;
label: string;
ids: string[];
}> = [
{
key: 'heading',
label: '标题',
ids: ['h1', 'h2', 'h3', 'h4'],
},
{
key: 'inline',
label: '行内样式',
ids: ['bold', 'italic', 'strike', 'code', 'link'],
},
{
key: 'block',
label: '块级结构',
ids: ['ul', 'ol', 'task', 'quote', 'hr'],
},
{
key: 'insert',
label: '插入',
ids: ['table', 'codeblock', 'image'],
},
];
const items: MenuProps['items'] = [];
groups.forEach((group, index) => {
if (index > 0) items.push({ type: 'divider' });
items.push({
key: `group-${group.key}`,
type: 'group',
label: group.label,
children: group.ids.map((id) => {
const action = EDITOR_ACTIONS.find((item) => item.id === id)!;
return {
key: action.id,
label: action.label,
onClick: () => runAction(action),
};
}),
});
});
return items;
}, [runAction]);
const isMarkdown = mode === 'markdown';
return (
<section className={`${styles.pane} ${styles.editorPane}`}>
<div className={styles.paneHeader}>
<div className={styles.paneHeaderLeft}>
<span className={styles.paneTitle}>
{isMarkdown ? 'Markdown' : '普通编辑'}
</span>
<Tooltip title={tocOpen ? '收起目录' : '展开目录'}>
<button
type="button"
className={styles.tocToggle}
onClick={() => onTocOpenChange(!tocOpen)}
>
目录 {tocOpen ? '◂' : '▸'}
</button>
</Tooltip>
</div>
<div className={styles.paneHeaderRight}>
<Segmented
size="small"
value={mode}
onChange={(value) =>
onModeChange(value === 'plain' ? 'plain' : 'markdown')
}
options={[
{ label: 'MD', value: 'markdown' },
{ label: '普通', value: 'plain' },
]}
/>
<span className={styles.paneMeta}>{charCount} 字</span>
</div>
</div>
<div className={styles.editorBody}>
{tocOpen && (
<aside className={styles.tocPanel}>
<div className={styles.tocTitle}>大纲</div>
{toc.length === 0 ? (
<p className={styles.tocEmpty}>暂无标题,用 # 写一级标题</p>
) : (
<ul className={styles.tocList}>
{toc.map((item) => (
<li key={item.id}>
<button
type="button"
className={`${styles.tocItem} ${
activeTocId === item.id ? styles.tocItemActive : ''
}`}
style={{ paddingLeft: 8 + (item.level - 1) * 12 }}
onClick={() => jumpToHeading(item.line, item.id)}
title={item.text}
>
<span className={styles.tocLevel}>H{item.level}</span>
{item.text}
</button>
</li>
))}
</ul>
)}
</aside>
)}
<Dropdown
menu={{ items: isMarkdown ? contextItems : [] }}
trigger={isMarkdown ? ['contextMenu'] : []}
>
<div
className={`${styles.editorWrap} ${
isMarkdown ? styles.editorMarkdown : styles.editorPlain
}`}
>
<TextArea
ref={textareaRef}
className={styles.editor}
value={content}
onChange={(e) => onChange(e.target.value)}
placeholder={
isMarkdown
? `在此输入 Markdown…
右键可插入标题 / 任务 / 表格 / 代码块等
参考 MarkText 的源码编辑体验`
: `普通文本编辑模式
适合自由写作;切换回 MD 后仍可一键转公众号预览`
}
autoFocus
spellCheck={mode === 'plain'}
style={{ height: '100%', resize: 'none' }}
/>
</div>
</Dropdown>
</div>
</section>
);
}

View File

@ -6,7 +6,7 @@
http-equiv="Content-Security-Policy"
content="script-src 'self' 'unsafe-inline'"
/>
<title>emoji编辑器</title>
<title>emojiTool</title>
</head>
<body>
<div id="root"></div>

View File

@ -0,0 +1,160 @@
export type EditorAction = {
id: string;
label: string;
group: 'heading' | 'block' | 'inline' | 'insert';
/** If set, wrap selected text (or placeholder) */
wrap?: { before: string; after: string; placeholder?: string };
/** If set, insert raw markdown at cursor */
insert?: string;
};
export const EDITOR_ACTIONS: EditorAction[] = [
{
id: 'h1',
label: '一级标题',
group: 'heading',
wrap: { before: '# ', after: '', placeholder: '标题' },
},
{
id: 'h2',
label: '二级标题',
group: 'heading',
wrap: { before: '## ', after: '', placeholder: '小标题' },
},
{
id: 'h3',
label: '三级标题',
group: 'heading',
wrap: { before: '### ', after: '', placeholder: '小节标题' },
},
{
id: 'h4',
label: '四级标题',
group: 'heading',
wrap: { before: '#### ', after: '', placeholder: '四级标题' },
},
{
id: 'bold',
label: '加粗',
group: 'inline',
wrap: { before: '**', after: '**', placeholder: '加粗文字' },
},
{
id: 'italic',
label: '斜体',
group: 'inline',
wrap: { before: '*', after: '*', placeholder: '斜体文字' },
},
{
id: 'strike',
label: '删除线',
group: 'inline',
wrap: { before: '~~', after: '~~', placeholder: '删除文字' },
},
{
id: 'code',
label: '行内代码',
group: 'inline',
wrap: { before: '`', after: '`', placeholder: 'code' },
},
{
id: 'link',
label: '链接',
group: 'inline',
wrap: {
before: '[',
after: '](https://example.com)',
placeholder: '链接文案',
},
},
{
id: 'ul',
label: '无序列表',
group: 'block',
insert: '\n- 列表项\n- 列表项\n',
},
{
id: 'ol',
label: '有序列表',
group: 'block',
insert: '\n1. 第一项\n2. 第二项\n',
},
{
id: 'task',
label: '任务列表',
group: 'block',
insert: '\n- [ ] 待办事项\n- [x] 已完成\n',
},
{
id: 'quote',
label: '引用',
group: 'block',
insert: '\n> 这里是一句引用\n',
},
{
id: 'hr',
label: '分隔线',
group: 'block',
insert: '\n---\n',
},
{
id: 'table',
label: '表格',
group: 'insert',
insert:
'\n| 列1 | 列2 | 列3 |\n| --- | --- | --- |\n| A | B | C |\n| D | E | F |\n',
},
{
id: 'codeblock',
label: '代码块',
group: 'insert',
insert: '\n```js\nconsole.log("hello")\n```\n',
},
{
id: 'image',
label: '图片',
group: 'insert',
insert: '\n![图片说明](https://example.com/image.png)\n',
},
];
export type ApplyResult = {
next: string;
selectionStart: number;
selectionEnd: number;
};
export function applyEditorAction(
content: string,
selectionStart: number,
selectionEnd: number,
action: EditorAction,
): ApplyResult {
const selected = content.slice(selectionStart, selectionEnd);
if (action.wrap) {
const { before, after, placeholder = '' } = action.wrap;
const inner = selected || placeholder;
const inserted = `${before}${inner}${after}`;
const next =
content.slice(0, selectionStart) + inserted + content.slice(selectionEnd);
if (selected) {
return {
next,
selectionStart: selectionStart + before.length,
selectionEnd: selectionStart + before.length + selected.length,
};
}
return {
next,
selectionStart: selectionStart + before.length,
selectionEnd: selectionStart + before.length + inner.length,
};
}
const chunk = action.insert ?? '';
const next =
content.slice(0, selectionStart) + chunk + content.slice(selectionEnd);
const cursor = selectionStart + chunk.length;
return { next, selectionStart: cursor, selectionEnd: cursor };
}

View File

@ -0,0 +1,191 @@
import { Marked, Renderer } from 'marked';
import {
DEFAULT_THEME_ID,
resolveTheme,
type EmojiTheme,
type ThemeId,
} from './themes';
import {
TABLE_CELL_SEP,
TABLE_ROW_SEP,
formatPlainTable,
parseMarkedTableRows,
} from './plainTable';
export type { ThemeId } from './themes';
export {
THEME_LIST,
DEFAULT_THEME_ID,
resolveTheme,
isThemeId,
} from './themes';
function cleanUrl(href: string): string | null {
try {
return encodeURI(href).replace(/%25/g, '%');
} catch {
return null;
}
}
function isTaskItem(theme: EmojiTheme, value: string): boolean {
return (
value.includes(`${theme.listSymbol}${theme.taskUnchecked}`) ||
value.includes(`${theme.listSymbol}${theme.taskChecked}`) ||
value.includes('🔸⬜') ||
value.includes('🔸✅') ||
value.includes('▪️◻') ||
value.includes('▪️☑️') ||
value.includes('•○') ||
value.includes('•✓') ||
value.includes('👉▢') ||
value.includes('👉✔')
);
}
function createRenderer(theme: EmojiTheme): Renderer {
const renderer = new Renderer();
const { listSymbol } = theme;
renderer.image = (href, _title, text) => {
const cleanHref = cleanUrl(href || '');
if (!cleanHref) {
return text || '';
}
return theme.image(cleanHref, text || '');
};
renderer.list = (body, ordered) => {
const type = ordered ? 'ol' : 'ul';
const texts = body
.replace(/<\/?div>/g, '')
.split(/<br\s*\/?>/i)
.map((item) => item.trim())
.filter((item) => item.length > 0);
const topped = texts.filter((item) => item.includes(listSymbol));
return texts
.map((value) => {
const task = isTaskItem(theme, value);
if (value.includes(listSymbol)) {
const prefix =
type === 'ol'
? `${theme.orderedNumbers[topped.indexOf(value)] ?? theme.fallbackOrdered} `
: task
? ''
: listSymbol;
return `<div>${prefix}${value.replace(listSymbol, '')}</div>`;
}
return `<div style="white-space:pre;">&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;${theme.nestPrefix} ${value}</div>`;
})
.join('');
};
renderer.listitem = (text) => `${listSymbol}${text}<br/>`;
renderer.checkbox = (checked) =>
checked ? theme.taskChecked : theme.taskUnchecked;
renderer.heading = (text, level) => {
if (level === 1) return theme.heading1(text);
if (level === 2) return theme.heading2(text);
if (level === 3) return theme.heading3(text);
return theme.heading4(text);
};
renderer.text = (text) => text;
renderer.hr = () => theme.hr;
renderer.codespan = (text) => theme.codespan(text);
renderer.code = (code, language) =>
theme.codeblock(code, language || '');
renderer.strong = (text) => theme.strong(text);
renderer.em = (text) => theme.em(text);
renderer.del = (text) => theme.del(text);
renderer.blockquote = (quote) => {
const match = /<div>(.*?)<\/div>/.exec(quote);
const content = match ? match[1] : quote.replace(/<\/?div>/g, '');
return theme.blockquote(content);
};
// Plain-text tables for WeChat / IM paste (HTML borders do not survive copy)
renderer.table = (header, body) => {
const rows = parseMarkedTableRows(header, body);
return formatPlainTable(rows, theme.tableLabel, theme.tableStyle);
};
renderer.tablerow = (content) => `${content}${TABLE_ROW_SEP}`;
renderer.tablecell = (content) => `${content}${TABLE_CELL_SEP}`;
renderer.link = (href, _title, text) => {
const cleanHref = cleanUrl(href);
if (cleanHref === null) {
return text;
}
return theme.link(text, cleanHref);
};
renderer.paragraph = (text) => `<div>${text}</div>`;
renderer.br = () => '<br>';
renderer.html = (html) => html;
return renderer;
}
const markedCache = new Map<ThemeId, Marked>();
function getMarked(themeId: ThemeId): Marked {
// Rebuild each call so table/theme helper updates always apply
const instance = new Marked({
breaks: true,
gfm: true,
renderer: createRenderer(resolveTheme(themeId)),
});
markedCache.set(themeId, instance);
return instance;
}
export const DEFAULT_FOOTER_TEXT = `➖➖➖➖➖
©️ 本文使用🔗『mdemoji.com』 编辑`;
function escapeHtml(text: string): string {
return text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
export function formatFooterHtml(footerText: string): string {
const lines = footerText.replace(/\r\n/g, '\n').split('\n');
const body = lines.map((line) => escapeHtml(line)).join('<br/>');
return `<div class="emoji-footer" style="margin-top:12px;white-space:pre-wrap;">${body}</div>`;
}
export function renderEmojiMarkdown(
source: string,
options?: {
appendFooter?: boolean;
footerText?: string;
themeId?: ThemeId;
},
): string {
const appendFooter = options?.appendFooter !== false;
const footerText = options?.footerText ?? DEFAULT_FOOTER_TEXT;
const themeId = options?.themeId ?? DEFAULT_THEME_ID;
const bodyHtml = getMarked(themeId).parse(source) as string;
if (appendFooter && source.length >= 10 && footerText.trim()) {
return bodyHtml + formatFooterHtml(footerText);
}
return bodyHtml;
}

View File

@ -0,0 +1,238 @@
/**
* Plain-text tables for WeChat / IM / any proportional-font input.
*
* IMPORTANT: Do NOT use half-width box-drawing (┌│─) + ASCII spaces.
* Those only align in true dual-width monospace terminals. WeChat / many
* editors use proportional fonts → columns break.
*
* Solution: FULLWIDTH-only grid (+ - |) + ideographic spaces ( ).
* Every structural char is width 2, so columns stay aligned everywhere.
*/
export function isWideCodePoint(code: number): boolean {
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) return false;
if (code >= 0x300 && code <= 0x36f) return false;
if (code >= 0x1ab0 && code <= 0x1aff) return false;
if (code >= 0x1dc0 && code <= 0x1dff) return false;
if (code >= 0x20d0 && code <= 0x20ff) return false;
if (code >= 0xfe00 && code <= 0xfe0f) return false;
if (code >= 0xfe20 && code <= 0xfe2f) return false;
if (code >= 0x1100 && code <= 0x115f) return true;
if (code === 0x2329 || code === 0x232a) return true;
if (code >= 0x2e80 && code <= 0x303e) return true;
if (code >= 0x3040 && code <= 0xa4cf) return true;
if (code >= 0xac00 && code <= 0xd7a3) return true;
if (code >= 0xf900 && code <= 0xfaff) return true;
if (code >= 0xfe10 && code <= 0xfe19) return true;
if (code >= 0xfe30 && code <= 0xfe6f) return true;
if (code >= 0xff00 && code <= 0xff60) return true;
if (code >= 0xffe0 && code <= 0xffe6) return true;
if (code >= 0x20000 && code <= 0x3fffd) return true;
if (code >= 0x1f000 && code <= 0x1ffff) return true;
if (code >= 0x2600 && code <= 0x27bf) return true;
return false;
}
export function displayWidth(text: string): number {
let width = 0;
for (const char of text) {
const code = char.codePointAt(0) ?? 0;
width += isWideCodePoint(code) ? 2 : 1;
}
return width;
}
const FW_SPACE = '\u3000'; //   width 2
const FW_H = '\uff0d'; // - width 2
const FW_V = '\uff5c'; // | width 2
const FW_PLUS = '\uff0b'; // + width 2
/** Pad with fullwidth spaces only (never ASCII space) */
function padEndFullwidth(text: string, target: number): string {
let width = displayWidth(text);
const goal = target % 2 === 0 ? target : target + 1;
let result = text;
while (width < goal) {
result += FW_SPACE;
width += 2;
}
return result;
}
function stripHtml(html: string): string {
return html
.replace(/<br\s*\/?>/gi, ' ')
.replace(/<[^>]+>/g, '')
.replace(/&nbsp;/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/\u00a0/g, ' ')
.trim();
}
/** ASCII → fullwidth so proportional fonts (WeChat / YaHei) still column-align */
function toFullwidthCompat(text: string): string {
let out = '';
for (const ch of text) {
const code = ch.codePointAt(0) ?? 0;
if (code === 0x20) {
out += FW_SPACE;
} else if (code >= 0x21 && code <= 0x7e) {
out += String.fromCodePoint(code + 0xfee0);
} else {
out += ch;
}
}
return out;
}
export type PlainTableStyle = 'box' | 'pipe' | 'dots';
function colWidths(matrix: string[][]): number[] {
const colCount = matrix[0]?.length ?? 0;
return Array.from({ length: colCount }, (_, col) => {
const raw = Math.max(
4,
...matrix.map((row) => displayWidth(row[col] || '')),
);
return raw % 2 === 0 ? raw : raw + 1;
});
}
/** Horizontal rule segment: each - is width 2, so count = halfUnits/2 */
function fwRule(halfUnits: number): string {
const n = Math.max(1, Math.ceil(halfUnits / 2));
return FW_H.repeat(n);
}
function buildFullwidthBox(matrix: string[][], widths: number[]): string[] {
const rule =
FW_PLUS + widths.map((w) => fwRule(w)).join(FW_PLUS) + FW_PLUS;
const renderRow = (row: string[]) =>
FW_V +
row.map((cell, col) => padEndFullwidth(cell, widths[col])).join(FW_V) +
FW_V;
// Only one divider under header (fewer lines)
const lines: string[] = [rule];
matrix.forEach((row, index) => {
lines.push(renderRow(row));
if (index === 0 && matrix.length > 1) {
lines.push(rule);
}
});
lines.push(rule);
return lines;
}
function buildPipeRows(matrix: string[][], widths: number[]): string[] {
// Also fullwidth for Theme B — same alignment guarantee
return buildFullwidthBox(matrix, widths);
}
function buildDotsRows(matrix: string[][], widths: number[]): string[] {
const total =
widths.reduce((a, b) => a + b, 0) + (widths.length + 1) * 2;
const rule = '·'.repeat(Math.max(8, Math.ceil(total / 2)));
const lines: string[] = [rule];
matrix.forEach((row) => {
lines.push(
row
.map((cell, col) => padEndFullwidth(cell, widths[col]))
.join('|'),
);
});
lines.push(rule);
return lines;
}
/**
* Build a plain-text table that stays aligned in proportional fonts (WeChat etc.).
*/
export function formatPlainTable(
rows: string[][],
label: string,
style: PlainTableStyle = 'box',
): string {
const normalized = rows
.map((row) =>
row.map((cell) => toFullwidthCompat(stripHtml(cell))),
)
.filter((row) => row.some((cell) => cell.length > 0));
if (normalized.length === 0) {
return `<div class="emoji-table"><pre>${label}</pre></div>`;
}
const colCount = Math.max(...normalized.map((row) => row.length));
const matrix = normalized.map((row) => {
const next = [...row];
while (next.length < colCount) next.push('');
return next;
});
const widths = colWidths(matrix);
let body: string[];
if (style === 'dots') {
body = buildDotsRows(matrix, widths);
} else {
// box + pipe → same fullwidth grid (Theme A/B/D)
body = buildFullwidthBox(matrix, widths);
}
const lines = [label, ...body];
const escaped = lines
.join('\n')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
return `<div class="emoji-table"><pre>${escaped}</pre></div>`;
}
export function parseMarkedTableRows(
header: string,
body: string,
): string[][] {
const CELL = '\u0001';
const ROW = '\u0002';
const parseBlock = (block: string) =>
block
.split(ROW)
.map((row) => {
const cells = row.split(CELL).map((cell) => cell.trim());
if (cells.length && cells[cells.length - 1] === '') cells.pop();
return cells;
})
.filter((row) => row.length > 0);
if (header.includes(CELL) || body.includes(CELL)) {
return [...parseBlock(header), ...parseBlock(body)];
}
const rows: string[][] = [];
const rowRe = /<tr[^>]*>([\s\S]*?)<\/tr>/gi;
const cellRe = /<t[hd][^>]*>([\s\S]*?)<\/t[hd]>/gi;
const all = `${header}${body}`;
let rowMatch = rowRe.exec(all);
while (rowMatch) {
const cells: string[] = [];
let cellMatch = cellRe.exec(rowMatch[1]);
while (cellMatch) {
cells.push(stripHtml(cellMatch[1]));
cellMatch = cellRe.exec(rowMatch[1]);
}
if (cells.length) rows.push(cells);
rowMatch = rowRe.exec(all);
}
return rows;
}
export const TABLE_CELL_SEP = '\u0001';
export const TABLE_ROW_SEP = '\u0002';

View File

@ -0,0 +1,78 @@
import {
DEFAULT_FOOTER_TEXT,
DEFAULT_THEME_ID,
isThemeId,
type ThemeId,
} from './emojiMarkdown';
import { DEFAULT_TEMPLATE_CONTENT } from './templates';
export type EditorMode = 'markdown' | 'plain';
export type DraftState = {
content: string;
appendFooter: boolean;
footerText: string;
themeId: ThemeId;
editorMode: EditorMode;
tocOpen: boolean;
};
const STORAGE_KEY = 'emojitool.draft';
const DEFAULT_DRAFT: DraftState = {
content: DEFAULT_TEMPLATE_CONTENT,
appendFooter: true,
footerText: DEFAULT_FOOTER_TEXT,
themeId: DEFAULT_THEME_ID,
editorMode: 'markdown',
tocOpen: true,
};
export function loadDraft(): DraftState {
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) {
return { ...DEFAULT_DRAFT };
}
const parsed = JSON.parse(raw) as Partial<DraftState>;
const themeId: ThemeId = isThemeId(parsed.themeId)
? parsed.themeId
: DEFAULT_THEME_ID;
const content =
typeof parsed.content === 'string' && parsed.content.length > 0
? parsed.content
: DEFAULT_TEMPLATE_CONTENT;
return {
content,
appendFooter:
typeof parsed.appendFooter === 'boolean'
? parsed.appendFooter
: true,
footerText:
typeof parsed.footerText === 'string' && parsed.footerText.length > 0
? parsed.footerText
: DEFAULT_FOOTER_TEXT,
themeId,
editorMode: parsed.editorMode === 'plain' ? 'plain' : 'markdown',
tocOpen: typeof parsed.tocOpen === 'boolean' ? parsed.tocOpen : true,
};
} catch {
return { ...DEFAULT_DRAFT };
}
}
export function saveDraft(draft: DraftState): void {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(draft));
} catch {
// ignore quota / private mode errors
}
}
export function clearDraft(): void {
try {
localStorage.removeItem(STORAGE_KEY);
} catch {
// ignore
}
}

View File

@ -0,0 +1,192 @@
export type TemplateItem = {
id: string;
label: string;
content: string;
};
export type SnippetItem = {
id: string;
label: string;
insert: string;
};
/** 默认首个模板:覆盖渲染器支持的全部 Markdown 语法 */
export const SHOWCASE_TEMPLATE: TemplateItem = {
id: 'showcase',
label: '语法全览(默认)',
content: `# 一级标题 H1
这是普通段落,用于预览正文换行。
## 二级标题 H2
### 三级标题 H3
#### 四级标题 H4
## 行内强调
普通文字里可以有 **加粗**、*斜体*、***粗斜体***,以及 ~~删除线~~。
行内代码:快捷键 \`Ctrl+Enter\` 复制预览。
## 无序列表
- 第一项要点
- 第二项要点
- 嵌套子项 A
- 嵌套子项 B
- 第三项要点
## 有序列表
1. 先写标题再说结果
2. 列表控制在 3~5 条
3. 结尾给一个可执行行动
4. 预览后再复制到公众号
## 任务列表
- [x] 已完成:整理素材
- [ ] 待办:写完草稿
- [ ] 待办:复查链接
## 引用
> 好内容 = 清晰结构 + 一句人话总结
>
> 第二行引用继续演示
## 链接
在线体验:[mdemoji.com](https://mdemoji.com)
裸链接:https://www.markdownguide.org/
文档:[Markdown 指南](https://www.markdownguide.org/)
## 图片
![示例图片](https://via.placeholder.com/300x160.png?text=emoji)
## 代码块
\`\`\`js
function hello(name) {
return '你好,' + name;
}
\`\`\`
\`\`\`
纯文本代码块
第二行
\`\`\`
## 表格
| 语法 | 效果 |
| --- | --- |
| 标题 | 边框 / 前缀装饰 |
| 列表 | Emoji / 符号序号 |
| 链接 | 可复制纯文本 |
| 代码 | 『Ctrl+Enter』 |
## 分隔线
---
切换顶部主题 A / B / C / D,对比同一篇语法的排版差异。
`,
};
export const TEMPLATES: TemplateItem[] = [
SHOWCASE_TEMPLATE,
{
id: 'article',
label: '公众号短文',
content: `# 本周值得一看
## 开场
今天分享三个实用小技巧,帮你把内容写得更清晰。
## 要点
1. 标题先说结果,再讲过程
2. 列表控制在 3~5 条
3. 结尾给一个可执行的行动
> 好内容 = 清晰结构 + 一句人话总结
---
欢迎在评论区留下你的做法。
`,
},
{
id: 'checklist',
label: '任务清单',
content: `# 本周任务
## 待办
- [ ] 写一篇公众号草稿
- [x] 整理素材图片
- [ ] 排期发布并复查链接
## 备注
- 重点检查标题是否过长
- 预览后再复制到后台
`,
},
{
id: 'links',
label: '带链接文章',
content: `# 资源合集
## 推荐阅读
- [Markdown 指南](https://www.markdownguide.org/)
- 在线体验: [mdemoji.com](https://mdemoji.com)
## 小贴士
使用 \`Ctrl+Enter\` 可快速复制预览文本。
---
©️ 欢迎转发收藏
`,
},
];
export const DEFAULT_TEMPLATE_CONTENT = SHOWCASE_TEMPLATE.content;
export const SNIPPETS: SnippetItem[] = [
{ id: 'h1', label: 'H1', insert: '\n# 标题\n' },
{ id: 'h2', label: 'H2', insert: '\n## 小标题\n' },
{ id: 'ul', label: '列表', insert: '\n- 第一项\n- 第二项\n' },
{
id: 'task',
label: '任务',
insert: '\n- [ ] 待办事项\n- [x] 已完成\n',
},
{ id: 'hr', label: '分隔', insert: '\n---\n' },
{
id: 'link',
label: '链接',
insert: '\n[链接文案](https://example.com)\n',
},
{ id: 'quote', label: '引用', insert: '\n> 这里是一句引用\n' },
{
id: 'code',
label: '代码',
insert: '\n`行内代码`\n\n```js\nconsole.log(1)\n```\n',
},
{
id: 'table',
label: '表格',
insert: '\n| 列1 | 列2 |\n| --- | --- |\n| A | B |\n',
},
];

268
src/renderer/lib/themes.ts Normal file
View File

@ -0,0 +1,268 @@
export type ThemeId = 'A' | 'B' | 'C' | 'D';
export type PlainTableStyle = 'box' | 'pipe' | 'dots';
export type EmojiTheme = {
id: ThemeId;
name: string;
shortName: string;
description: string;
listSymbol: string;
orderedNumbers: string[];
nestPrefix: string;
taskChecked: string;
taskUnchecked: string;
heading1: (text: string) => string;
heading2: (text: string) => string;
heading3: (text: string) => string;
heading4: (text: string) => string;
hr: string;
codespan: (text: string) => string;
codeblock: (code: string, language: string) => string;
strong: (text: string) => string;
em: (text: string) => string;
del: (text: string) => string;
blockquote: (content: string) => string;
tableLabel: string;
tableStyle: PlainTableStyle;
link: (text: string, href: string) => string;
image: (href: string, text: string) => string;
fallbackOrdered: string;
};
function frameTitleA(text: string): string {
const padding = 2;
const edgeChar = '─';
const titleLength = text.length + padding * 2;
const edgeLength = edgeChar.repeat(titleLength);
return `<div>╭${edgeLength}╮<br/> 📢 ${text}<br/>╰${edgeLength}╯</div>`;
}
function frameTitleB(text: string): string {
const line = '─'.repeat(Math.max(text.length + 4, 10));
return `<div>┌${line}┐<br/>│ 📌 ${text}<br/>└${line}┘</div>`;
}
function frameTitleC(text: string): string {
return `<div>◆━━━━ ${text} ━━━━◆</div>`;
}
function frameTitleD(text: string): string {
const line = '═'.repeat(Math.max(text.length + 2, 8));
return `<div>╔${line}╗<br/>║ 🎯 ${text}<br/>╚${line}╝</div>`;
}
function escapeCode(code: string): string {
return code
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function plainCodeBlock(title: string, code: string): string {
const line = '────────';
return `<div class="emoji-code"><pre>${title}\n${line}\n${escapeCode(code.replace(/\n$/, ''))}\n${line}</pre></div>`;
}
/** A · 经典 */
export const THEME_A: EmojiTheme = {
id: 'A',
name: '主题 A · 经典',
shortName: 'A 经典',
description: '圆角边框标题 + 序号 emoji,沿用原版风格',
listSymbol: '🔸',
orderedNumbers: [
'1️⃣',
'2️⃣',
'3️⃣',
'4️⃣',
'5️⃣',
'6️⃣',
'7️⃣',
'8️⃣',
'9️⃣',
'🔟',
],
nestPrefix: '┊',
taskChecked: '✅',
taskUnchecked: '⬜',
heading1: frameTitleA,
heading2: (text) => `<div>📝${text}</div>\n`,
heading3: (text) => `<div>📝${text}</div>\n`,
heading4: (text) => `<div>▪️${text}</div>\n`,
hr: '➖➖➖➖➖\n',
codespan: (text) => `『${text}』`,
codeblock: (code, language) =>
plainCodeBlock(`📄 代码${language ? ` · ${language}` : ''}`, code),
strong: (text) => `【${text}】`,
em: (text) => `*${text}*`,
del: (text) => `~${text}~`,
blockquote: (content) =>
`<div style="white-space:pre;" class="blockquote">&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;&#8239;└─⚡${content}</div>`,
tableLabel: '📊 表格 📊',
tableStyle: 'box',
link: (text, href) =>
text === href ? `🔗${href}` : `🔗${text}: ${href}`,
image: (href, text) =>
`<div>🖼 ${text || '图片'}:${href}</div>`,
fallbackOrdered: '🔹',
};
/** B · 青简:书签框 + 圆圈序号,行内代码同样用『』 */
export const THEME_B: EmojiTheme = {
id: 'B',
name: '主题 B · 青简',
shortName: 'B 青简',
description: '书签框标题 + 圆圈序号,『代码』与经典一致',
listSymbol: '▪️',
orderedNumbers: [
'①',
'②',
'③',
'④',
'⑤',
'⑥',
'⑦',
'⑧',
'⑨',
'⑩',
],
nestPrefix: '│',
taskChecked: '☑️',
taskUnchecked: '◻',
heading1: frameTitleB,
heading2: (text) => `<div>▸ ${text}</div>\n`,
heading3: (text) => `<div>‧ ${text}</div>\n`,
heading4: (text) => `<div>· ${text}</div>\n`,
hr: '· · · · · · · ·\n',
codespan: (text) => `『${text}』`,
codeblock: (code, language) =>
plainCodeBlock(`📄『${language || 'code'}』`, code),
strong: (text) => `【${text}】`,
em: (text) => `〈${text}〉`,
del: (text) => `〚${text}〛`,
blockquote: (content) =>
`<div style="white-space:pre;" class="blockquote">┃ ${content}</div>`,
tableLabel: '▣ 表格',
tableStyle: 'pipe',
link: (text, href) =>
text === href ? `↗ ${href}` : `↗ ${text}(${href})`,
image: (href, text) =>
`<div>🖼 ${text || '图片'}:${href}</div>`,
fallbackOrdered: '◦',
};
/** C · 精简:最少装饰,仍转换全部语法 */
export const THEME_C: EmojiTheme = {
id: 'C',
name: '主题 C · 精简',
shortName: 'C 精简',
description: '最少装饰的纯文本风,语法仍全部转换',
listSymbol: '•',
orderedNumbers: [
'1.',
'2.',
'3.',
'4.',
'5.',
'6.',
'7.',
'8.',
'9.',
'10.',
],
nestPrefix: '·',
taskChecked: '✓',
taskUnchecked: '○',
heading1: frameTitleC,
heading2: (text) => `<div>▶ ${text}</div>\n`,
heading3: (text) => `<div>- ${text}</div>\n`,
heading4: (text) => `<div>${text}</div>\n`,
hr: '············\n',
codespan: (text) => `『${text}』`,
codeblock: (code, language) =>
plainCodeBlock(`代码${language ? `(${language})` : ''}`, code),
strong: (text) => `【${text}】`,
em: (text) => `_${text}_`,
del: (text) => `~~${text}~~`,
blockquote: (content) =>
`<div style="white-space:pre;" class="blockquote">❝ ${content}</div>`,
tableLabel: '表',
tableStyle: 'dots',
link: (text, href) =>
text === href ? href : `${text} → ${href}`,
image: (href, text) =>
`<div>[图片] ${text || ''}:${href}</div>`,
fallbackOrdered: '-',
};
/** D · 聚焦 */
export const THEME_D: EmojiTheme = {
id: 'D',
name: '主题 D · 聚焦',
shortName: 'D 聚焦',
description: '双线框标题 + 箭头引导,适合要点清单',
listSymbol: '👉',
orderedNumbers: [
'❶',
'❷',
'❸',
'❹',
'❺',
'❻',
'❼',
'❽',
'❾',
'❿',
],
nestPrefix: '↳',
taskChecked: '✔',
taskUnchecked: '▢',
heading1: frameTitleD,
heading2: (text) => `<div>🔹 ${text}</div>\n`,
heading3: (text) => `<div>🔸 ${text}</div>\n`,
heading4: (text) => `<div>▪ ${text}</div>\n`,
hr: '━━━━━━\n',
codespan: (text) => `『${text}』`,
codeblock: (code, language) =>
plainCodeBlock(`📋『${language || 'code'}』`, code),
strong: (text) => `【${text}】`,
em: (text) => `*${text}*`,
del: (text) => `~${text}~`,
blockquote: (content) =>
`<div style="white-space:pre;" class="blockquote">💬 ${content}</div>`,
tableLabel: '📋 表格',
tableStyle: 'box',
link: (text, href) =>
text === href ? `🔗 ${href}` : `🔗 ${text} · ${href}`,
image: (href, text) =>
`<div>🖼 ${text || '图片'}:${href}</div>`,
fallbackOrdered: '▪',
};
export const THEMES: Record<ThemeId, EmojiTheme> = {
A: THEME_A,
B: THEME_B,
C: THEME_C,
D: THEME_D,
};
export const THEME_LIST: EmojiTheme[] = [
THEME_A,
THEME_B,
THEME_C,
THEME_D,
];
export const DEFAULT_THEME_ID: ThemeId = 'A';
export function resolveTheme(id?: string | null): EmojiTheme {
if (id && id in THEMES) {
return THEMES[id as ThemeId];
}
return THEME_A;
}
export function isThemeId(id: unknown): id is ThemeId {
return id === 'A' || id === 'B' || id === 'C' || id === 'D';
}

51
src/renderer/lib/toc.ts Normal file
View File

@ -0,0 +1,51 @@
export type TocItem = {
id: string;
level: number;
text: string;
line: number;
index: number;
};
/** Parse ATX headings (# … ######) for outline navigation */
export function parseToc(markdown: string): TocItem[] {
const lines = markdown.replace(/\r\n/g, '\n').split('\n');
const items: TocItem[] = [];
let inFence = false;
lines.forEach((line, lineIndex) => {
const fence = line.trim().startsWith('```');
if (fence) {
inFence = !inFence;
return;
}
if (inFence) return;
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
if (!match) return;
const level = match[1].length;
const text = match[2].replace(/#+\s*$/, '').trim();
if (!text) return;
items.push({
id: `toc-${lineIndex}-${items.length}`,
level,
text,
line: lineIndex,
index: items.length,
});
});
return items;
}
/** Character offset at the start of a 0-based line */
export function offsetAtLine(markdown: string, line: number): number {
const lines = markdown.replace(/\r\n/g, '\n').split('\n');
let offset = 0;
const max = Math.min(line, lines.length);
for (let i = 0; i < max; i += 1) {
offset += lines[i].length + 1;
}
return offset;
}

733
yarn.lock

File diff suppressed because it is too large Load Diff