feat: polish A2 business theme, UI chrome, and plain-text table frames
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

Align A2 IM preview with character-only frames (B-style H1, fullwidth table lines), refine shell/titlebar styling, and document the theme rules.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hackrobot 2026-10-03 05:27:46 +08:00
parent 826f0bcf22
commit 751afd89de
17 changed files with 1235 additions and 265 deletions

View File

@ -17,9 +17,9 @@
|------|------|
| 三栏联动 | 左编辑 / 中 Emoji 纯文本 / 右长文富文本;滚动按比例同步,语法与渲染对应 |
| Markdown 实时预览 | 基于 `marked`:中间栏自定义 Emoji Renderer,右侧栏 GFM 富文本 |
| 四套主题 A–D | 经典 / 青简 / 精简 / 聚焦;各预览栏独立切换主题与复制 |
| Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现 |
| 一键复制 | 中间栏复制纯文本(表格全角网格);右侧栏复制富文本 HTML |
| 四套 + A2 主题 | 经典 / **A2 商务**(B 式线框 H1 + 📋📌🔹1️⃣ 职场 emoji;表格全角 `-|`)/ 青简 / 精简 / 聚焦 |
| Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现;纯文本栏禁止 CSS 画框 |
| 一键复制 | 中间栏复制纯文本(所见即粘贴);右侧栏复制富文本 HTML |
| 可视化表格 | MarkText 风格插入/编辑表格,插入前可填单元格 |
| 本地图片 | 拖拽或右键选图插入;Markdown 使用标准 `images/xxx.png`;预览经本地协议显示 |
| 可选 S3 上传 | 设置中开启后,图片可上传到 MinIO/S3(默认端点可配) |
@ -44,6 +44,14 @@
- **图片**:纯文本 `🖼 说明:url`;长文栏正常渲染图片
- **表格**:全角字符网格(Theme B 为 pipe 风格)
### 主题 A2 · 商务(纯文本栏)
- **H1**:主题 B 同款 `┌─┐│└─┘` 线框 + `📋`
- **H2**:`📌` + 细横线;**H3**:`📎`;列表 `🔹` / `1️⃣…`
- **行内代码**:`『…』`;代码块:`┌─┐` 线框
- **表格**:全角 `-|` 线框(与微信/雅黑对齐);图片在纯文本栏不输出
- **任务**:`✅` / `⬜`(无额外列表符)
## 技术栈
- **桌面**:Electron 44 + electron-builder 26
@ -121,6 +129,7 @@ npm start
## 已知说明
- 包名 / `productName` 已统一为 **emojitool** / **emojiTool**。
- Windows 使用自定义标题栏(隐藏原生菜单栏,`Alt` 可临时唤出);青绿品牌图标见 `assets/icon.png`。
- 草稿与设置保存在本机;S3 上传需在设置中自行配置。
- 图片写入 Markdown 为相对路径 `images/...` 或 `https://...`,不含专有协议。
- 三栏滚动按可视进度比例联动,长文档下源码与两侧预览位置大致对应。

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -1,23 +1,11 @@
<svg width="232" height="232" viewBox="0 0 232 232" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_b)">
<path d="M231.5 1V0.5H231H1H0.5V1V231V231.5H1H231H231.5V231V1ZM40.5 25C40.5 33.0082 34.0082 39.5 26 39.5C17.9918 39.5 11.5 33.0082 11.5 25C11.5 16.9918 17.9918 10.5 26 10.5C34.0082 10.5 40.5 16.9918 40.5 25ZM220.5 25C220.5 33.0082 214.008 39.5 206 39.5C197.992 39.5 191.5 33.0082 191.5 25C191.5 16.9918 197.992 10.5 206 10.5C214.008 10.5 220.5 16.9918 220.5 25ZM40.5 205C40.5 213.008 34.0082 219.5 26 219.5C17.9918 219.5 11.5 213.008 11.5 205C11.5 196.992 17.9918 190.5 26 190.5C34.0082 190.5 40.5 196.992 40.5 205ZM220.5 205C220.5 213.008 214.008 219.5 206 219.5C197.992 219.5 191.5 213.008 191.5 205C191.5 196.992 197.992 190.5 206 190.5C214.008 190.5 220.5 196.992 220.5 205ZM209.5 111C209.5 162.639 167.639 204.5 116 204.5C64.3613 204.5 22.5 162.639 22.5 111C22.5 59.3613 64.3613 17.5 116 17.5C167.639 17.5 209.5 59.3613 209.5 111Z" fill="white" stroke="white"/>
<path d="M63.5 146.5C63.5 149.959 60.8969 152.5 58 152.5C55.1031 152.5 52.5 149.959 52.5 146.5C52.5 143.041 55.1031 140.5 58 140.5C60.8969 140.5 63.5 143.041 63.5 146.5Z" stroke="white" stroke-width="5"/>
<path d="M54.9856 139.466C54.9856 139.466 51.1973 116.315 83.1874 93.1647C115.178 70.014 133.698 69.5931 133.698 69.5931" stroke="white" stroke-width="5" stroke-linecap="round"/>
<path d="M178.902 142.686C177.27 139.853 173.652 138.88 170.819 140.512C167.987 142.144 167.014 145.762 168.646 148.595C170.277 151.427 173.896 152.4 176.728 150.768C179.561 149.137 180.534 145.518 178.902 142.686Z" stroke="white" stroke-width="5"/>
<path d="M169.409 151.555C169.409 151.555 151.24 166.394 115.211 150.232C79.182 134.07 69.5718 118.232 69.5718 118.232" stroke="white" stroke-width="5" stroke-linecap="round"/>
<path d="M109.577 41.9707C107.966 44.8143 108.964 48.4262 111.808 50.038C114.651 51.6498 118.263 50.6512 119.875 47.8075C121.487 44.9639 120.488 41.3521 117.645 39.7403C114.801 38.1285 111.189 39.1271 109.577 41.9707Z" stroke="white" stroke-width="5"/>
<path d="M122.038 45.6467C122.038 45.6467 144.047 53.7668 148.412 93.0129C152.778 132.259 144.012 148.579 144.012 148.579" stroke="white" stroke-width="5" stroke-linecap="round"/>
<path d="M59.6334 105C59.6334 105 50.4373 82.1038 61.3054 73.3616C72.1736 64.6194 96 69.1987 96 69.1987" stroke="white" stroke-width="5" stroke-linecap="round"/>
<path d="M149.532 66.9784C149.532 66.9784 174.391 68.9134 177.477 82.6384C180.564 96.3634 165.799 115.833 165.799 115.833" stroke="white" stroke-width="5" stroke-linecap="round"/>
<path d="M138.248 163.363C138.248 163.363 124.023 183.841 110.618 179.573C97.2129 175.305 87.8662 152.728 87.8662 152.728" stroke="white" stroke-width="5" stroke-linecap="round"/>
<path d="M116 119C120.418 119 124 115.642 124 111.5C124 107.358 120.418 104 116 104C111.582 104 108 107.358 108 111.5C108 115.642 111.582 119 116 119Z" fill="white"/>
</g>
<defs>
<filter id="filter0_b" x="-4" y="-4" width="240" height="240" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feGaussianBlur in="BackgroundImage" stdDeviation="2"/>
<feComposite in2="SourceAlpha" operator="in" result="effect1_backgroundBlur"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_backgroundBlur" result="shape"/>
</filter>
</defs>
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="bg" x1="64" y1="64" x2="448" y2="448" gradientUnits="userSpaceOnUse">
<stop stop-color="#14b8a6"/>
<stop offset="1" stop-color="#0f766e"/>
</linearGradient>
</defs>
<rect width="512" height="512" rx="112" fill="url(#bg)"/>
<rect x="168" y="168" width="152" height="152" rx="36" transform="rotate(18 244 244)" stroke="#ecfeff" stroke-width="28" fill="none"/>
<rect x="286" y="286" width="72" height="72" rx="16" fill="#ecfeff"/>
</svg>

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 592 B

View File

@ -248,8 +248,9 @@
"electronmon": {
"patterns": [
"!**/**",
"src/main/**"
"src/main/**/*",
"src/shared/**/*"
],
"logLevel": "quiet"
"logLevel": "info"
}
}

View File

@ -0,0 +1,38 @@
import { renderEmojiMarkdown } from '../renderer/lib/emojiMarkdown';
describe('emojiMarkdown nested lists', () => {
it('keeps nested unordered items on their own indented lines', () => {
const md = `## 无序列表
- 第一项要点
- 第二项要点
- 嵌套子项 A
- 嵌套子项 B
- 第三项要点
`;
const html = renderEmojiMarkdown(md, {
appendFooter: false,
themeId: 'A2',
});
const text = html
.replace(/<br\s*\/?>/gi, '\n')
.replace(/<\/div>/gi, '\n')
.replace(/<[^>]+>/g, '');
const lines = text
.split('\n')
.map((line) => line.trimEnd())
.filter((line) => line.trim().length > 0);
const parentIdx = lines.findIndex((line) => line.includes('第二项要点'));
const childAIdx = lines.findIndex((line) => line.includes('嵌套子项 A'));
const childBIdx = lines.findIndex((line) => line.includes('嵌套子项 B'));
expect(parentIdx).toBeGreaterThanOrEqual(0);
expect(childAIdx).toBe(parentIdx + 1);
expect(childBIdx).toBe(parentIdx + 2);
expect(lines[childAIdx]).toMatch(/^ │/);
expect(lines[childBIdx]).toMatch(/^ │/);
expect(lines[parentIdx]).toMatch(/^🔹/);
});
});

View File

@ -87,6 +87,9 @@ const createWindow = async () => {
return path.join(RESOURCES_PATH, ...paths);
};
const isMac = process.platform === 'darwin';
const chromeBg = '#eef2f3';
mainWindow = new BrowserWindow({
show: false,
width: 1560,
@ -95,6 +98,21 @@ const createWindow = async () => {
minHeight: 600,
title: 'emojiTool',
icon: getAssetPath('icon.png'),
backgroundColor: chromeBg,
autoHideMenuBar: !isMac,
...(isMac
? {
titleBarStyle: 'hiddenInset' as const,
trafficLightPosition: { x: 14, y: 12 },
}
: {
titleBarStyle: 'hidden' as const,
titleBarOverlay: {
color: chromeBg,
symbolColor: '#334155',
height: 44,
},
}),
webPreferences: {
preload: app.isPackaged
? path.join(__dirname, 'preload.js')
@ -153,6 +171,9 @@ app.on('window-all-closed', () => {
app
.whenReady()
.then(() => {
if (process.platform === 'win32') {
app.setAppUserModelId('cn.nomadro.emojitool');
}
installLocalImageProtocol();
const migrated = migrateLegacyImages();
if (migrated > 0) {

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@ import type { MenuProps } from 'antd';
import {
DEFAULT_FOOTER_TEXT,
THEME_LIST,
ARTICLE_THEME_LIST,
renderEmojiMarkdown,
type ThemeId,
} from './lib/emojiMarkdown';
@ -91,7 +92,9 @@ function App() {
[themeId],
);
const articleTheme = useMemo(
() => THEME_LIST.find((t) => t.id === articleThemeId) ?? THEME_LIST[0],
() =>
ARTICLE_THEME_LIST.find((t) => t.id === articleThemeId) ??
ARTICLE_THEME_LIST[0],
[articleThemeId],
);
@ -237,8 +240,9 @@ function App() {
}, []);
const applyArticleTheme = useCallback((next: ThemeId) => {
if (next === 'A2') return;
setArticleThemeId(next);
const theme = THEME_LIST.find((item) => item.id === next);
const theme = ARTICLE_THEME_LIST.find((item) => item.id === next);
message.success(`长文主题:${theme?.name ?? next}`);
}, []);
@ -343,8 +347,11 @@ function App() {
}, [copyPreview, copyArticleHtml, persistNow, clearContent]);
const makeThemeItems = useCallback(
(onSelect: (id: ThemeId) => void): MenuProps['items'] =>
THEME_LIST.map((theme) => ({
(
themes: typeof THEME_LIST,
onSelect: (id: ThemeId) => void,
): MenuProps['items'] =>
themes.map((theme) => ({
key: theme.id,
label: (
<div className={styles.themeMenuItem}>
@ -357,8 +364,11 @@ function App() {
[],
);
const plainThemeItems = makeThemeItems(applyPlainTheme);
const articleThemeItems = makeThemeItems(applyArticleTheme);
const plainThemeItems = makeThemeItems(THEME_LIST, applyPlainTheme);
const articleThemeItems = makeThemeItems(
ARTICLE_THEME_LIST,
applyArticleTheme,
);
const templateItems: MenuProps['items'] = TEMPLATES.map((item) => ({
key: item.id,
@ -378,46 +388,71 @@ function App() {
token: {
colorPrimary: '#0d9488',
colorInfo: '#0d9488',
borderRadius: 10,
borderRadius: 8,
colorText: '#1a2330',
colorTextSecondary: '#64748b',
colorBorder: 'rgba(26, 35, 48, 0.12)',
fontFamily:
'"Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif',
controlHeight: 32,
controlHeightSM: 28,
},
}}
>
<div className={styles.app}>
<header className={styles.header}>
<div
className={styles.app}
data-platform={
typeof navigator !== 'undefined' && /Mac/i.test(navigator.platform)
? 'darwin'
: 'win'
}
>
<header className={styles.titleBar}>
<div className={styles.brand}>
<div className={styles.brandMark} aria-hidden>
✦
</div>
<div className={styles.brandMark} aria-hidden />
<div className={styles.brandText}>
<h1 className={styles.title}>emojiTool</h1>
<p className={styles.subtitle}>
编辑 · 纯文本 · 长文 · mdemoji.com
</p>
<p className={styles.subtitle}>编辑 · 纯文本 · 长文</p>
</div>
</div>
<div className={styles.actions}>
<Tooltip title="图床、编辑器等全局选项">
<Button onClick={() => setSettingsOpen(true)}>设置</Button>
</Tooltip>
<div className={styles.actionGroup}>
<Tooltip title="图床、编辑器等全局选项">
<Button type="text" onClick={() => setSettingsOpen(true)}>
设置
</Button>
</Tooltip>
</div>
<Dropdown menu={{ items: templateItems }} placement="bottomRight">
<Button>模板 ▾</Button>
</Dropdown>
<div className={styles.actionGroup}>
<Dropdown menu={{ items: templateItems }} placement="bottomRight">
<Button type="default" size="small">
模板 ▾
</Button>
</Dropdown>
<Button
type="default"
size="small"
onClick={() =>
applyTemplate(DEFAULT_TEMPLATE_CONTENT, '语法全览(默认)')
}
>
重置示例
</Button>
</div>
<Button
onClick={() =>
applyTemplate(DEFAULT_TEMPLATE_CONTENT, '语法全览(默认)')
}
>
重置示例
</Button>
<Button onClick={clearContent} disabled={!hasContent}>
清空
</Button>
<div className={styles.actionGroup}>
<Button
type="text"
danger
size="small"
onClick={clearContent}
disabled={!hasContent}
>
清空
</Button>
</div>
</div>
</header>
@ -438,7 +473,12 @@ function App() {
{snippet.label}
</button>
))}
<span className={styles.saveHint} aria-live="polite">
<span
className={`${styles.saveHint} ${
savedHint ? styles.saveHintSaved : ''
}`}
aria-live="polite"
>
{hintText}
</span>
</div>
@ -455,9 +495,17 @@ function App() {
charCount={charCount}
/>
<section className={`${styles.pane} ${styles.previewPane}`}>
<section
className={`${styles.pane} ${styles.previewPane}`}
data-theme={themeId}
>
<div className={styles.paneHeader}>
<span className={styles.paneTitle}>纯文本预览</span>
<div className={styles.paneHeaderLeft}>
<span className={styles.paneTitle}>纯文本预览</span>
<span className={`${styles.paneBadge} ${styles.paneBadgeIm}`}>
IM
</span>
</div>
<div className={styles.paneHeaderActions}>
<Dropdown
menu={{
@ -490,14 +538,19 @@ function App() {
<div
ref={previewRef}
className={styles.previewHtml}
data-theme={themeId}
aria-live="polite"
dangerouslySetInnerHTML={{ __html: previewHtml }}
/>
) : (
<div className={styles.emptyState}>
<div
className={`${styles.emptyIcon} ${styles.emptyIconIm}`}
aria-hidden
/>
<p className={styles.emptyTitle}>纯文本效果</p>
<p className={styles.emptyDesc}>
面向微信公众号、评论区、聊天框等纯文本场景,复制后可直接粘贴。
面向微信、评论区、聊天框;复制后可直接粘贴。
</p>
</div>
)}
@ -509,7 +562,14 @@ function App() {
data-theme={articleThemeId}
>
<div className={styles.paneHeader}>
<span className={styles.paneTitle}>长文渲染</span>
<div className={styles.paneHeaderLeft}>
<span className={styles.paneTitle}>长文渲染</span>
<span
className={`${styles.paneBadge} ${styles.paneBadgeArticle}`}
>
长文
</span>
</div>
<div className={styles.paneHeaderActions}>
<Dropdown
menu={{
@ -548,9 +608,13 @@ function App() {
/>
) : (
<div className={styles.emptyState}>
<div
className={`${styles.emptyIcon} ${styles.emptyIconArticle}`}
aria-hidden
/>
<p className={styles.emptyTitle}>长文预览</p>
<p className={styles.emptyDesc}>
本栏可单独切换主题;点「复制」粘贴到富文本编辑器。
可单独切换主题;复制后粘贴到富文本编辑器。
</p>
</div>
)}

View File

@ -475,6 +475,7 @@ const EditorPane = forwardRef<EditorPaneHandle, Props>(function EditorPane(
<span className={styles.paneTitle}>
{isMarkdown ? 'Markdown' : '普通编辑'}
</span>
<span className={styles.paneBadge}>源码</span>
<Tooltip title={tocOpen ? '收起目录' : '展开目录'}>
<button
type="button"
@ -510,17 +511,19 @@ const EditorPane = forwardRef<EditorPaneHandle, Props>(function EditorPane(
)}
</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' },
]}
/>
<div className={styles.modeSegmented}>
<Segmented
size="small"
value={mode}
onChange={(value) =>
onModeChange(value === 'plain' ? 'plain' : 'markdown')
}
options={[
{ label: 'MD', value: 'markdown' },
{ label: '普通', value: 'plain' },
]}
/>
</div>
<span className={styles.paneMeta}>{charCount} 字</span>
</div>
</div>

View File

@ -1,7 +1,38 @@
.modal {
:global(.ant-modal-content) {
border-radius: 12px;
overflow: hidden;
box-shadow: 0 8px 32px rgba(26, 35, 48, 0.12);
}
:global(.ant-modal-header) {
padding: 16px 20px 12px;
border-bottom: 1px solid rgba(26, 35, 48, 0.08);
}
:global(.ant-modal-title) {
font-weight: 600;
letter-spacing: -0.01em;
color: #1a2330;
}
:global(.ant-modal-body) {
max-height: min(70vh, 560px);
overflow: auto;
padding: 16px 20px 8px;
}
:global(.ant-modal-footer) {
padding: 12px 20px 16px;
border-top: 1px solid rgba(26, 35, 48, 0.06);
}
:global(.ant-tabs-nav) {
margin-bottom: 12px;
}
:global(.ant-form-item) {
margin-bottom: 14px;
}
}
@ -16,5 +47,9 @@
margin: 8px 0 0;
font-size: 12px;
line-height: 1.6;
color: #5b6b7c;
color: #64748b;
padding: 8px 10px;
border-radius: 8px;
background: rgba(13, 148, 136, 0.06);
border: 1px solid rgba(13, 148, 136, 0.12);
}

View File

@ -1,18 +1,36 @@
.insertModal {
:global(.ant-modal-content) {
border-radius: 12px;
overflow: hidden;
box-shadow: 0 8px 32px rgba(26, 35, 48, 0.12);
}
:global(.ant-modal-header) {
padding: 16px 20px 10px;
border-bottom: 1px solid rgba(26, 35, 48, 0.08);
}
:global(.ant-modal-title) {
text-align: center;
font-weight: 600;
letter-spacing: -0.01em;
color: #1a2330;
}
:global(.ant-modal-body) {
padding-top: 8px;
padding: 12px 20px 8px;
}
:global(.ant-modal-footer) {
padding: 12px 20px 16px;
border-top: 1px solid rgba(26, 35, 48, 0.06);
}
}
.insertBody {
display: flex;
flex-direction: column;
gap: 16px;
gap: 14px;
padding: 4px 0 2px;
}
@ -39,34 +57,55 @@
display: grid;
gap: 6px;
padding: 14px;
border-radius: 12px;
background:
linear-gradient(180deg, #f7fafb 0%, #eef3f5 100%);
border-radius: 10px;
background: linear-gradient(180deg, #f7fafb 0%, #eef3f5 100%);
border: 1px solid rgba(26, 35, 48, 0.08);
min-height: 120px;
max-height: 220px;
overflow: auto;
scrollbar-width: thin;
}
.gridCell {
aspect-ratio: 1.6 / 1;
min-height: 22px;
border-radius: 4px;
border: 1px solid rgba(15, 118, 110, 0.28);
background: rgba(255, 255, 255, 0.85);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
border: 1px solid rgba(13, 148, 136, 0.28);
background: rgba(255, 255, 255, 0.9);
transition: border-color 140ms ease, background 140ms ease;
}
.hint {
margin: 0;
text-align: center;
font-size: 12px;
color: #5b6b7c;
color: #64748b;
}
.editModal {
:global(.ant-modal-content) {
border-radius: 12px;
overflow: hidden;
box-shadow: 0 8px 32px rgba(26, 35, 48, 0.12);
}
:global(.ant-modal-header) {
padding: 16px 20px 10px;
border-bottom: 1px solid rgba(26, 35, 48, 0.08);
}
:global(.ant-modal-title) {
font-weight: 600;
color: #1a2330;
}
:global(.ant-modal-body) {
padding-top: 8px;
padding: 12px 20px 8px;
}
:global(.ant-modal-footer) {
padding: 12px 20px 16px;
border-top: 1px solid rgba(26, 35, 48, 0.06);
}
}
@ -87,15 +126,16 @@
.toolLabel {
font-size: 12px;
color: #5b6b7c;
color: #64748b;
}
.editScroll {
overflow: auto;
max-height: min(52vh, 420px);
border: 1px solid rgba(26, 35, 48, 0.1);
border-radius: 12px;
border: 1px solid rgba(26, 35, 48, 0.09);
border-radius: 10px;
background: #fbfcfd;
scrollbar-width: thin;
}
.editTable {
@ -137,6 +177,7 @@
display: block;
width: 100%;
text-align: left;
transition: color 140ms ease;
&:hover {
color: #0d9488;
@ -170,16 +211,21 @@
border-radius: 6px;
border: 1px solid rgba(26, 35, 48, 0.12);
background: #fff;
color: #5b6b7c;
color: #64748b;
font-size: 13px;
line-height: 1;
cursor: pointer;
display: inline-grid;
place-items: center;
transition:
color 140ms ease,
border-color 140ms ease,
background 140ms ease;
&:hover:not(:disabled) {
color: #0f766e;
border-color: rgba(13, 148, 136, 0.4);
background: rgba(13, 148, 136, 0.06);
}
&:disabled {

View File

@ -15,11 +15,20 @@ import {
export type { ThemeId } from './themes';
export {
THEME_LIST,
ARTICLE_THEME_LIST,
DEFAULT_THEME_ID,
resolveTheme,
isThemeId,
isArticleThemeId,
} from './themes';
/** Structural markers — Marked renders inner lists before outer list() runs */
const LI_OPEN = '{{LI}}';
const LI_CLOSE = '{{/LI}}';
const LIST_OL_OPEN = '{{LIST:1}}';
const LIST_UL_OPEN = '{{LIST:0}}';
const LIST_CLOSE = '{{/LIST}}';
function cleanUrl(href: string): string | null {
try {
return encodeURI(href).replace(/%25/g, '%');
@ -30,14 +39,166 @@ function cleanUrl(href: string): string | null {
function isTaskItem(theme: EmojiTheme, value: string): boolean {
return (
value.includes(`${theme.listSymbol}${theme.taskUnchecked}`) ||
value.includes(`${theme.listSymbol}${theme.taskChecked}`)
value.includes(theme.taskUnchecked) || value.includes(theme.taskChecked)
);
}
function findMatchingClose(
source: string,
from: number,
open: string,
close: string,
): number {
let depth = 1;
let i = from;
while (i < source.length) {
if (source.startsWith(open, i)) {
depth += 1;
i += open.length;
continue;
}
if (source.startsWith(close, i)) {
depth -= 1;
if (depth === 0) return i;
i += close.length;
continue;
}
i += 1;
}
return -1;
}
function expandEmojiLists(input: string, theme: EmojiTheme): string {
const expandFrom = (source: string, depth: number): string => {
let out = '';
let i = 0;
while (i < source.length) {
const ul = source.indexOf(LIST_UL_OPEN, i);
const ol = source.indexOf(LIST_OL_OPEN, i);
let start = -1;
let ordered = false;
let openLen = 0;
if (ul === -1 && ol === -1) {
out += source.slice(i);
break;
}
if (ul === -1 || (ol !== -1 && ol < ul)) {
start = ol;
ordered = true;
openLen = LIST_OL_OPEN.length;
} else {
start = ul;
ordered = false;
openLen = LIST_UL_OPEN.length;
}
out += source.slice(i, start);
const contentStart = start + openLen;
const end = findListClose(source, contentStart);
if (end < 0) {
out += source.slice(start);
break;
}
const content = source.slice(contentStart, end);
out += renderListContent(content, ordered, depth, theme, expandFrom);
i = end + LIST_CLOSE.length;
}
return out;
};
return expandFrom(input, 0);
}
/** Match {{/LIST}} with nesting of either {{LIST:0}} or {{LIST:1}} */
function findListClose(source: string, from: number): number {
let depth = 1;
let i = from;
while (i < source.length) {
if (source.startsWith(LIST_UL_OPEN, i) || source.startsWith(LIST_OL_OPEN, i)) {
depth += 1;
i += LIST_UL_OPEN.length;
continue;
}
if (source.startsWith(LIST_CLOSE, i)) {
depth -= 1;
if (depth === 0) return i;
i += LIST_CLOSE.length;
continue;
}
i += 1;
}
return -1;
}
function extractListItems(content: string): string[] {
const items: string[] = [];
let i = 0;
while (i < content.length) {
const start = content.indexOf(LI_OPEN, i);
if (start === -1) break;
const contentStart = start + LI_OPEN.length;
const end = findMatchingClose(content, contentStart, LI_OPEN, LI_CLOSE);
if (end < 0) break;
items.push(content.slice(contentStart, end));
i = end + LI_CLOSE.length;
}
return items;
}
function renderListContent(
content: string,
ordered: boolean,
depth: number,
theme: EmojiTheme,
expandFrom: (source: string, depth: number) => string,
): string {
const items = extractListItems(content);
let orderedIndex = 0;
const indent = '\u3000'.repeat(depth);
const { listSymbol, nestPrefix } = theme;
return items
.map((raw) => {
// Expand any nested lists inside this item first (correct depth)
const expanded = expandFrom(raw, depth + 1);
// Nested list lines always use white-space:pre; plain <div> is paragraph wrap
const nestedBlocks: string[] = [];
const main = expanded
.replace(/<div style="white-space:pre;">[\s\S]*?<\/div>/g, (block) => {
nestedBlocks.push(block);
return '';
})
.replace(/<\/?div>/gi, '')
.replace(/<br\s*\/?>/gi, '')
.replaceAll(listSymbol, '')
.trim();
const task = isTaskItem(theme, main);
let line: string;
if (depth > 0) {
line = `<div style="white-space:pre;">${indent}${nestPrefix} ${main}</div>`;
} else if (ordered) {
const num =
theme.orderedNumbers[orderedIndex] ?? `${orderedIndex + 1}.`;
orderedIndex += 1;
line = `<div>${num} ${main}</div>`;
} else if (task) {
// 任务列表只要 ✅/⬜,不要再叠一层列表符号
line = `<div>${main}</div>`;
} else {
line = `<div>${listSymbol} ${main}</div>`;
}
return `${line}${nestedBlocks.join('')}`;
})
.join('');
}
function createRenderer(theme: EmojiTheme): Renderer {
const renderer = new Renderer();
const { listSymbol } = theme;
renderer.image = (href, _title, text) => {
const cleanHref = cleanUrl(href || '');
@ -47,39 +208,10 @@ function createRenderer(theme: EmojiTheme): Renderer {
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);
renderer.listitem = (text) => `${LI_OPEN}${text}${LI_CLOSE}`;
let orderedIndex = 0;
return texts
.map((value) => {
const task = isTaskItem(theme, value);
if (value.includes(listSymbol)) {
let prefix: string;
if (type === 'ol') {
prefix = `${theme.orderedNumbers[orderedIndex] ?? `${orderedIndex + 1}.`} `;
orderedIndex += 1;
} else if (task) {
prefix = '';
} else {
prefix = 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.list = (body, ordered) =>
`${ordered ? LIST_OL_OPEN : LIST_UL_OPEN}${body}${LIST_CLOSE}`;
renderer.checkbox = (checked) =>
checked ? theme.taskChecked : theme.taskUnchecked;
@ -120,7 +252,6 @@ function createRenderer(theme: EmojiTheme): Renderer {
return lines.map((line) => theme.blockquote(line)).join('');
};
// 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);
@ -153,7 +284,7 @@ function getMarked(themeId: ThemeId): Marked {
});
}
export const DEFAULT_FOOTER_TEXT = `➖➖➖➖➖
export const DEFAULT_FOOTER_TEXT = `············
©️ 本文使用🔗『mdemoji.com』 编辑`;
function escapeHtml(text: string): string {
@ -180,7 +311,9 @@ export function renderEmojiMarkdown(
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;
const theme = resolveTheme(themeId);
const rawHtml = getMarked(themeId).parse(source) as string;
const bodyHtml = expandEmojiLists(rawHtml, theme);
if (appendFooter && footerText.trim()) {
return bodyHtml + formatFooterHtml(footerText);

View File

@ -90,7 +90,7 @@ function toFullwidthCompat(text: string): string {
return out;
}
export type PlainTableStyle = 'box' | 'pipe' | 'dots';
export type PlainTableStyle = 'box' | 'pipe' | 'dots' | 'frame';
function colWidths(matrix: string[][]): number[] {
const colCount = matrix[0]?.length ?? 0;
@ -130,6 +130,31 @@ function buildFullwidthBox(matrix: string[][], widths: number[]): string[] {
return lines;
}
/**
* A2 线框表:只用全角 -|(与代码块同一套)。
* 顶/底/表头分隔线纯 -(不用 | 接头,否则竖笔画会冒出横线)。
*/
function buildFrameBox(matrix: string[][], widths: number[]): string[] {
const total =
widths.reduce((a, b) => a + b, 0) + (widths.length + 1) * 2;
const rule = FW_H.repeat(Math.max(1, total / 2));
const renderRow = (row: string[]) =>
FW_V +
row.map((cell, col) => padEndFullwidth(cell, widths[col])).join(FW_V) +
FW_V;
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;
}
/** Pipe style: fullwidth cells, divider only under header (no outer top/bottom box) */
function buildPipeRows(matrix: string[][], widths: number[]): string[] {
const renderRow = (row: string[]) =>
@ -197,6 +222,8 @@ export function formatPlainTable(
body = buildDotsRows(matrix, widths);
} else if (style === 'pipe') {
body = buildPipeRows(matrix, widths);
} else if (style === 'frame') {
body = buildFrameBox(matrix, widths);
} else {
body = buildFullwidthBox(matrix, widths);
}

View File

@ -1,6 +1,7 @@
import {
DEFAULT_FOOTER_TEXT,
DEFAULT_THEME_ID,
isArticleThemeId,
isThemeId,
type ThemeId,
} from './emojiMarkdown';
@ -42,9 +43,12 @@ export function loadDraft(): DraftState {
const themeId: ThemeId = isThemeId(parsed.themeId)
? parsed.themeId
: DEFAULT_THEME_ID;
const articleThemeId: ThemeId = isThemeId(parsed.articleThemeId)
? parsed.articleThemeId
: themeId;
const rawArticle = parsed.articleThemeId;
const articleThemeId: ThemeId = isArticleThemeId(rawArticle)
? rawArticle
: isArticleThemeId(themeId)
? themeId
: DEFAULT_THEME_ID;
const content =
typeof parsed.content === 'string'
? parsed.content

View File

@ -77,11 +77,6 @@ function hello(name) {
}
\`\`\`
\`\`\`
纯文本代码块
第二行
\`\`\`
## 表格
| 语法 | 效果 |

View File

@ -1,6 +1,8 @@
export type ThemeId = 'A' | 'B' | 'C' | 'D';
import { displayWidth } from './plainTable';
export type PlainTableStyle = 'box' | 'pipe' | 'dots';
export type ThemeId = 'A' | 'A2' | 'B' | 'C' | 'D';
export type PlainTableStyle = 'box' | 'pipe' | 'dots' | 'frame';
export type EmojiTheme = {
id: ThemeId;
@ -30,6 +32,19 @@ export type EmojiTheme = {
fallbackOrdered: string;
};
function escapeCode(code: string): string {
return code
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function repeatToDisplayWidth(ch: string, target: number): string {
const unit = Math.max(1, displayWidth(ch));
const count = Math.max(1, Math.ceil(target / unit));
return ch.repeat(count);
}
function frameTitleA(text: string): string {
const padding = 2;
const edgeChar = '─';
@ -38,9 +53,40 @@ function frameTitleA(text: string): string {
return `<div>╭${edgeLength}╮<br/> 📢 ${text}<br/>╰${edgeLength}╯</div>`;
}
/**
* 主题 B 一级标题书签框(保持原样)
*/
function frameTitleB(text: string): string {
const line = '─'.repeat(Math.max(text.length + 4, 10));
return `<div>┌${line}┐<br/>│ 📌 ${text}<br/>└${line}┘</div>`;
const body = `📌 ${text}`;
const width = Math.max(displayWidth(body), 10);
const line = '─'.repeat(width);
return `<div>┌${line}┐<br/>│ ${body}<br/>└${line}┘</div>`;
}
/**
* A2 一级标题:沿用主题 B 线框 ┌─┐│└─┘,emoji 用 📋。
*/
function frameTitleA2(text: string): string {
const body = `📋 ${text}`;
const width = Math.max(displayWidth(body), 10);
const line = '─'.repeat(width);
return `<div class="emoji-h1">┌${line}┐<br/>│ ${body}<br/>└${line}┘</div>`;
}
/** A2 线条:等长、无 emoji,细线 / 虚线 */
const A2_LINE_WIDTH = 16;
function a2Line(style: 'title' | 'section'): string {
if (style === 'title') {
return repeatToDisplayWidth('─', A2_LINE_WIDTH);
}
return Array.from({ length: Math.ceil(A2_LINE_WIDTH / 2) }, () => '·').join(
' ',
);
}
function businessHr(): string {
return `<div class="emoji-hr">${a2Line('section')}</div>\n`;
}
function frameTitleC(text: string): string {
@ -52,18 +98,28 @@ function frameTitleD(text: string): string {
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>`;
}
function plainCodeBlockA2(title: string, code: string): string {
const body = escapeCode(code.replace(/\n$/, ''));
const lines = body.split('\n');
const head = `💻 ${title}`;
const maxW = Math.max(
displayWidth(head),
...lines.map((line) => displayWidth(line)),
12,
);
const edge = repeatToDisplayWidth('─', maxW + 2);
return `<div class="emoji-code emoji-code-a2"><pre>┌${edge}┐
│ ${head}
├${edge}┤
${lines.map((line) => `│ ${line}`).join('\n')}
└${edge}┘</pre></div>`;
}
/** A · 经典 */
export const THEME_A: EmojiTheme = {
id: 'A',
@ -90,7 +146,7 @@ export const THEME_A: EmojiTheme = {
heading2: (text) => `<div>📝 ${text}</div>\n`,
heading3: (text) => `<div>📎 ${text}</div>\n`,
heading4: (text) => `<div>▪️ ${text}</div>\n`,
hr: '➖➖➖➖➖\n',
hr: '· · · · · · · ·\n',
codespan: (text) => `『${text}』`,
codeblock: (code, language) =>
plainCodeBlock(`📄 代码${language ? ` · ${language}` : ''}`, code),
@ -108,6 +164,57 @@ export const THEME_A: EmojiTheme = {
fallbackOrdered: '🔹',
};
/**
* A2 · 商务正式(带色)
* 职场向 emoji 自带色彩:📋📌🔹✅1️⃣… + 双线框线。
* 不用花朵/闪粉/颜文字;适合群通报、对外摘要、评论区正式发言。
*/
export const THEME_A2: EmojiTheme = {
id: 'A2',
name: '主题 A2 · 商务',
shortName: 'A2 商务',
description:
'正式商务 + 职场 emoji 色彩:B 式线框、钉选/清单符号、彩色序号',
listSymbol: '🔹',
orderedNumbers: [
'1️⃣',
'2️⃣',
'3️⃣',
'4️⃣',
'5️⃣',
'6️⃣',
'7️⃣',
'8️⃣',
'9️⃣',
'🔟',
],
nestPrefix: '│',
taskChecked: '✅',
taskUnchecked: '⬜',
heading1: frameTitleA2,
heading2: (text) => {
const title = `📌 ${text}`;
return `<div class="emoji-h2">${title}<br/>${a2Line('title')}</div>\n`;
},
heading3: (text) => `<div class="emoji-h3">📎 ${text}</div>\n`,
heading4: (text) => `<div class="emoji-h4">▪️ ${text}</div>\n`,
hr: businessHr(),
codespan: (text) => `『${text}』`,
codeblock: (code, language) =>
plainCodeBlockA2(language ? `代码 · ${language}` : '代码', code),
strong: (text) => `【${text}】`,
em: (text) => `〈${text}〉`,
del: (text) => `〚${text}〛`,
blockquote: (content) =>
`<div class="emoji-quote" style="white-space:pre;">💬┃ ${content}</div>`,
tableLabel: '📊 表格',
tableStyle: 'frame',
link: (text, href) =>
text === href ? `🔗 ${href}` : `🔗 ${text} → ${href}`,
image: () => '',
fallbackOrdered: '🔸',
};
/** B · 青简:书签框 + 圆圈序号,行内代码同样用『』 */
export const THEME_B: EmojiTheme = {
id: 'B',
@ -222,7 +329,7 @@ export const THEME_D: EmojiTheme = {
heading2: (text) => `<div>🔹 ${text}</div>\n`,
heading3: (text) => `<div>🔸 ${text}</div>\n`,
heading4: (text) => `<div>▪ ${text}</div>\n`,
hr: '━━━━━━\n',
hr: '────────\n',
codespan: (text) => `『${text}』`,
codeblock: (code, language) =>
plainCodeBlock(`📋『${language || 'code'}』`, code),
@ -242,12 +349,23 @@ export const THEME_D: EmojiTheme = {
export const THEMES: Record<ThemeId, EmojiTheme> = {
A: THEME_A,
A2: THEME_A2,
B: THEME_B,
C: THEME_C,
D: THEME_D,
};
/** 纯文本预览可选主题(含 A2) */
export const THEME_LIST: EmojiTheme[] = [
THEME_A,
THEME_A2,
THEME_B,
THEME_C,
THEME_D,
];
/** 长文预览主题(A2 仅用于纯文本) */
export const ARTICLE_THEME_LIST: EmojiTheme[] = [
THEME_A,
THEME_B,
THEME_C,
@ -264,5 +382,11 @@ export function resolveTheme(id?: string | null): EmojiTheme {
}
export function isThemeId(id: unknown): id is ThemeId {
return (
id === 'A' || id === 'A2' || id === 'B' || id === 'C' || id === 'D'
);
}
export function isArticleThemeId(id: unknown): id is Exclude<ThemeId, 'A2'> {
return id === 'A' || id === 'B' || id === 'C' || id === 'D';
}