fix: polish A2 preview spacing, quotes, and heading colors
Some checks failed
Test / test (macos-latest) (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
Test / test (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled

Tighten plain/article vertical rhythm, treat bare --- as hr not setext H2, and refine A2 H2/list/task emoji so colors stay distinct.
This commit is contained in:
hackrobot 2026-10-03 10:36:30 +08:00
parent 84d523558e
commit 21ef5167b6
5 changed files with 105 additions and 71 deletions

View File

@ -17,7 +17,7 @@
|------|------| |------|------|
| 三栏联动 | 左编辑 / 中 Emoji 纯文本 / 右长文富文本;滚动按比例同步,语法与渲染对应 | | 三栏联动 | 左编辑 / 中 Emoji 纯文本 / 右长文富文本;滚动按比例同步,语法与渲染对应 |
| Markdown 实时预览 | 基于 `marked`:中间栏自定义 Emoji Renderer,右侧栏 GFM 富文本 | | Markdown 实时预览 | 基于 `marked`:中间栏自定义 Emoji Renderer,右侧栏 GFM 富文本 |
| 四套 + A2 主题 | 经典 / **A2 商务**(B 式线框 H1 + 📋📌🔸1️⃣;表格全角 `-|`)/ 青简 / 精简 / 聚焦 | | 四套 + A2 主题 | 经典 / **A2 商务**(B 式线框 H1 + 📗 / 🔸;表格全角 `-|`)/ 青简 / 精简 / 聚焦 |
| Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现;纯文本栏禁止 CSS 画框 | | Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现;纯文本栏禁止 CSS 画框 |
| 一键复制 | 中间栏复制纯文本(所见即粘贴);右侧栏复制富文本 HTML | | 一键复制 | 中间栏复制纯文本(所见即粘贴);右侧栏复制富文本 HTML |
| 可视化表格 | MarkText 风格插入/编辑表格,插入前可填单元格 | | 可视化表格 | MarkText 风格插入/编辑表格,插入前可填单元格 |
@ -46,12 +46,13 @@
### 主题 A2 · 商务(纯文本栏) ### 主题 A2 · 商务(纯文本栏)
- **H1**:主题 B 同款 `┌─┐│└─┘` 线框 + `📋`(最短宽约原 2/3,超长自适应) - **H1**:主题 B 同款 `┌─┐│└─┘` 线框 + `📋`(最短宽约 8,超长自适应)
- **H2**:`📌`;**H3**:`📎`;列表 `🔸` / `1️⃣…` - **H2**:`📗`;**H3**:`📎`;列表 `🔸` / `1️⃣…`
- **行内代码**:`『…』`;代码块:`┌─┐` 线框(最短宽与 H1 对齐,超长自适应) - **行内代码**:`『…』`;代码块:`┌─┐` 线框(框宽约内容的 27/40)
- **表格**:全角 `-|` 线框(与微信/雅黑对齐);图片在纯文本栏不输出 - **表格**:全角 `-|` 线框(与微信/雅黑对齐);图片在纯文本栏不输出
- **任务**:`✅` / `⬜`(无额外列表符) - **任务**:`✔️` / `⬜`(无额外列表符)
- **分隔线**:与 H1 最短框同宽虚线 `· · · …` - **引用**:` │ …`(侧栏竖线,类似渲染后的 Markdown 引用)
- **分隔线**:虚线 `· · · …`
## 技术栈 ## 技术栈

View File

@ -819,15 +819,15 @@
} }
.previewHtml { .previewHtml {
padding: 18px 20px 28px; padding: 8px 12px 12px;
font-size: 15px; font-size: 15px;
line-height: 1.75; line-height: 1.42;
color: var(--ink); color: var(--ink);
user-select: text; user-select: text;
animation: fadeIn 220ms ease; animation: fadeIn 220ms ease;
> :global(div) { > :global(div) {
margin: 0 0 0.65em; margin: 0 0 0.2em;
} }
> :global(div:last-child) { > :global(div:last-child) {
@ -841,15 +841,15 @@
} }
:global(.emoji-footer) { :global(.emoji-footer) {
margin-top: 16px; margin-top: 6px;
padding-top: 4px; padding-top: 0;
color: var(--ink); color: var(--ink);
line-height: 1.7; line-height: 1.4;
} }
:global(.emoji-table) { :global(.emoji-table) {
margin: 8px 0 12px; margin: 2px 0 5px;
line-height: 1.45; line-height: 1.3;
} }
/* 纯文本预览:表格/代码块禁止上色与装饰边框,所见即复制结果 */ /* 纯文本预览:表格/代码块禁止上色与装饰边框,所见即复制结果 */
@ -866,7 +866,7 @@
'PingFang SC', 'PingFang SC',
monospace; monospace;
font-size: 14px; font-size: 14px;
line-height: 1.55; line-height: 1.35;
letter-spacing: 0; letter-spacing: 0;
font-variant-ligatures: none; font-variant-ligatures: none;
background: transparent; background: transparent;
@ -876,7 +876,7 @@
} }
:global(.emoji-code) { :global(.emoji-code) {
margin: 8px 0 12px; margin: 2px 0 5px;
padding: 0; padding: 0;
border: none; border: none;
border-radius: 0; border-radius: 0;
@ -895,7 +895,7 @@
Consolas, Consolas,
'Microsoft YaHei', 'Microsoft YaHei',
monospace; monospace;
line-height: 1.55; line-height: 1.35;
background: transparent; background: transparent;
border: none; border: none;
color: inherit; color: inherit;
@ -906,9 +906,9 @@
* 预览禁止颜色与 CSS 装饰——复制到微信/小红书/抖音/X 等仍是纯字符。 * 预览禁止颜色与 CSS 装饰——复制到微信/小红书/抖音/X 等仍是纯字符。
*/ */
&[data-theme='A2'] { &[data-theme='A2'] {
padding: 20px 22px 32px; padding: 8px 12px 12px;
font-size: 15px; font-size: 15px;
line-height: 1.85; line-height: 1.42;
letter-spacing: 0; letter-spacing: 0;
color: var(--ink); color: var(--ink);
/* 与微信一致:纯 CJK 字体,避免 Cascadia 半角框线把对齐弄坏 */ /* 与微信一致:纯 CJK 字体,避免 Cascadia 半角框线把对齐弄坏 */
@ -920,12 +920,12 @@
font-variant-ligatures: none; font-variant-ligatures: none;
> :global(div) { > :global(div) {
margin: 0 0 0.75em; margin: 0 0 0.15em;
} }
:global(.emoji-h1) { :global(.emoji-h1) {
margin: 0.1em 0 1em; margin: 0 0 0.28em;
line-height: 1.35; line-height: 1.25;
white-space: pre; white-space: pre;
font-weight: 400; font-weight: 400;
font-variant-ligatures: none; font-variant-ligatures: none;
@ -933,24 +933,25 @@
} }
:global(.emoji-h2) { :global(.emoji-h2) {
margin: 1.1em 0 0.55em; margin: 0.4em 0 0.14em;
line-height: 1.5; line-height: 1.3;
white-space: pre-wrap; white-space: pre-wrap;
font-weight: 400; font-weight: 600;
letter-spacing: 0.02em;
} }
:global(.emoji-h3) { :global(.emoji-h3) {
margin: 0.9em 0 0.4em; margin: 0.28em 0 0.1em;
font-weight: 400; font-weight: 400;
} }
:global(.emoji-h4) { :global(.emoji-h4) {
margin: 0.7em 0 0.3em; margin: 0.22em 0 0.08em;
font-weight: 400; font-weight: 400;
} }
:global(.emoji-hr) { :global(.emoji-hr) {
margin: 1.1em 0; margin: 0.3em 0;
text-align: left; text-align: left;
color: inherit; color: inherit;
white-space: pre; white-space: pre;
@ -958,7 +959,7 @@
} }
:global(.emoji-quote) { :global(.emoji-quote) {
margin: 0.25em 0; margin: 0.05em 0;
color: inherit; color: inherit;
} }
@ -975,7 +976,7 @@
} }
:global(.emoji-footer) { :global(.emoji-footer) {
margin-top: 1.2em; margin-top: 0.45em;
color: inherit; color: inherit;
} }
} }
@ -1033,7 +1034,7 @@
max-width: 42rem; max-width: 42rem;
margin: 0 auto; margin: 0 auto;
padding: 28px 28px 40px; padding: 12px 16px 16px;
color: var(--md-ink); color: var(--md-ink);
font-family: font-family:
'Source Han Sans SC', 'Source Han Sans SC',
@ -1043,7 +1044,7 @@
'Microsoft YaHei', 'Microsoft YaHei',
sans-serif; sans-serif;
font-size: 15.5px; font-size: 15.5px;
line-height: 1.85; line-height: 1.45;
letter-spacing: 0.01em; letter-spacing: 0.01em;
word-break: break-word; word-break: break-word;
user-select: text; user-select: text;
@ -1056,7 +1057,7 @@
--md-code-bg: #eef6f9; --md-code-bg: #eef6f9;
--md-code-fg: #0c4a5c; --md-code-fg: #0c4a5c;
font-size: 15px; font-size: 15px;
line-height: 1.8; line-height: 1.42;
} }
&[data-theme='C'] { &[data-theme='C'] {
@ -1068,7 +1069,7 @@
--md-code-fg: #334155; --md-code-fg: #334155;
--md-border: rgba(15, 23, 42, 0.08); --md-border: rgba(15, 23, 42, 0.08);
font-size: 15px; font-size: 15px;
line-height: 1.78; line-height: 1.4;
max-width: 38rem; max-width: 38rem;
} }
@ -1083,7 +1084,7 @@
--md-border: rgba(28, 25, 23, 0.12); --md-border: rgba(28, 25, 23, 0.12);
--md-pre-bg: #1c1917; --md-pre-bg: #1c1917;
font-size: 16px; font-size: 16px;
line-height: 1.9; line-height: 1.48;
} }
:global(h1), :global(h1),
@ -1094,21 +1095,21 @@
:global(h6) { :global(h6) {
color: var(--md-ink); color: var(--md-ink);
font-weight: 700; font-weight: 700;
line-height: 1.35; line-height: 1.25;
letter-spacing: -0.01em; letter-spacing: -0.01em;
margin: 1.55em 0 0.55em; margin: 0.55em 0 0.18em;
} }
:global(h1) { :global(h1) {
font-size: 1.85em; font-size: 1.85em;
margin-top: 0.2em; margin-top: 0;
padding-bottom: 0.35em; padding-bottom: 0.12em;
border-bottom: 2px solid var(--md-h1-rule); border-bottom: 2px solid var(--md-h1-rule);
} }
:global(h2) { :global(h2) {
font-size: 1.4em; font-size: 1.4em;
padding-bottom: 0.28em; padding-bottom: 0.1em;
border-bottom: 1px solid var(--md-border); border-bottom: 1px solid var(--md-border);
} }
@ -1129,7 +1130,7 @@
} }
:global(p) { :global(p) {
margin: 0 0 1em; margin: 0 0 0.3em;
} }
:global(a) { :global(a) {
@ -1156,33 +1157,33 @@
:global(ul), :global(ul),
:global(ol) { :global(ol) {
margin: 0 0 1em; margin: 0 0 0.3em;
padding-left: 1.45em; padding-left: 1.35em;
} }
:global(li) { :global(li) {
margin: 0.28em 0; margin: 0.05em 0;
} }
:global(li > p) { :global(li > p) {
margin: 0.2em 0; margin: 0.05em 0;
} }
:global(li > ul), :global(li > ul),
:global(li > ol) { :global(li > ol) {
margin: 0.25em 0 0.35em; margin: 0.08em 0 0.1em;
} }
:global(blockquote) { :global(blockquote) {
margin: 0 0 1.1em; margin: 0 0 0.35em;
padding: 0.65em 1em 0.65em 1.05em; padding: 0.25em 0.7em 0.25em 0.75em;
border-left: 3.5px solid var(--md-accent); border-left: 3.5px solid var(--md-accent);
background: var(--md-quote-bg); background: var(--md-quote-bg);
border-radius: 0 10px 10px 0; border-radius: 0 10px 10px 0;
color: #3d4f63; color: #3d4f63;
:global(p) { :global(p) {
margin: 0.35em 0; margin: 0.1em 0;
} }
:global(p:first-child) { :global(p:first-child) {
@ -1197,7 +1198,7 @@
:global(hr) { :global(hr) {
border: none; border: none;
height: 1px; height: 1px;
margin: 1.6em 0; margin: 0.5em 0;
background: linear-gradient( background: linear-gradient(
90deg, 90deg,
transparent, transparent,
@ -1223,8 +1224,8 @@
} }
:global(pre) { :global(pre) {
margin: 0 0 1.15em; margin: 0 0 0.35em;
padding: 14px 16px; padding: 8px 10px;
overflow-x: auto; overflow-x: auto;
border-radius: 12px; border-radius: 12px;
background: var(--md-pre-bg); background: var(--md-pre-bg);
@ -1247,7 +1248,7 @@
max-width: 100%; max-width: 100%;
height: auto; height: auto;
display: block; display: block;
margin: 1em auto; margin: 0.35em auto;
border-radius: 10px; border-radius: 10px;
box-shadow: 0 8px 28px rgba(26, 35, 48, 0.1); box-shadow: 0 8px 28px rgba(26, 35, 48, 0.1);
} }
@ -1255,7 +1256,7 @@
:global(table) { :global(table) {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
margin: 0 0 1.2em; margin: 0 0 0.4em;
font-size: 0.94em; font-size: 0.94em;
overflow: hidden; overflow: hidden;
border-radius: 10px; border-radius: 10px;
@ -1264,7 +1265,7 @@
:global(th), :global(th),
:global(td) { :global(td) {
padding: 10px 14px; padding: 5px 8px;
border-bottom: 1px solid var(--md-border); border-bottom: 1px solid var(--md-border);
text-align: left; text-align: left;
vertical-align: top; vertical-align: top;

View File

@ -300,6 +300,30 @@ export function formatFooterHtml(footerText: string): string {
return `<div class="emoji-footer" style="margin-top:12px;white-space:pre-wrap;">${body}</div>`; return `<div class="emoji-footer" style="margin-top:12px;white-space:pre-wrap;">${body}</div>`;
} }
/**
* CommonMark 会把「段落\n---」解析成 setext 二级标题。
* 本工具用户期望 --- 始终是分隔线:在规则行前补空行(跳过代码块)。
*/
export function preferThematicBreakOverSetext(source: string): string {
const lines = source.replace(/\r\n/g, '\n').split('\n');
const out: string[] = [];
let inFence = false;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (/^(```|~~~)/.test(line)) {
inFence = !inFence;
}
const isRule = !inFence && /^(?:-{3,}|={3,})[ \t]*$/.test(line);
if (isRule && out.length > 0 && out[out.length - 1].trim() !== '') {
out.push('');
}
out.push(line);
}
return out.join('\n');
}
export function renderEmojiMarkdown( export function renderEmojiMarkdown(
source: string, source: string,
options?: { options?: {
@ -312,7 +336,8 @@ export function renderEmojiMarkdown(
const footerText = options?.footerText ?? DEFAULT_FOOTER_TEXT; const footerText = options?.footerText ?? DEFAULT_FOOTER_TEXT;
const themeId = options?.themeId ?? DEFAULT_THEME_ID; const themeId = options?.themeId ?? DEFAULT_THEME_ID;
const theme = resolveTheme(themeId); const theme = resolveTheme(themeId);
const rawHtml = getMarked(themeId).parse(source) as string; const normalized = preferThematicBreakOverSetext(source);
const rawHtml = getMarked(themeId).parse(normalized) as string;
const bodyHtml = expandEmojiLists(rawHtml, theme); const bodyHtml = expandEmojiLists(rawHtml, theme);
if (appendFooter && footerText.trim()) { if (appendFooter && footerText.trim()) {

View File

@ -1,4 +1,5 @@
import { Marked, Renderer } from 'marked'; import { Marked, Renderer } from 'marked';
import { preferThematicBreakOverSetext } from './emojiMarkdown';
/** /**
* Display-only: resolve local image hrefs for the article HTML preview. * Display-only: resolve local image hrefs for the article HTML preview.
@ -122,7 +123,9 @@ export function renderRichMarkdown(
): string { ): string {
const appendFooter = options?.appendFooter !== false; const appendFooter = options?.appendFooter !== false;
const footerText = options?.footerText ?? ''; const footerText = options?.footerText ?? '';
const bodyHtml = richMarked.parse(source) as string; const bodyHtml = richMarked.parse(
preferThematicBreakOverSetext(source),
) as string;
if (appendFooter && footerText.trim()) { if (appendFooter && footerText.trim()) {
return bodyHtml + formatArticleFooter(footerText); return bodyHtml + formatArticleFooter(footerText);

View File

@ -65,22 +65,22 @@ function frameTitleB(text: string): string {
/** /**
* A2 一级标题:沿用主题 B 线框 ┌─┐│└─┘,emoji 用 📋。 * A2 一级标题:沿用主题 B 线框 ┌─┐│└─┘,emoji 用 📋。
* 最短固定宽度为原 28 的 2/3;标题更长时框线随字数加长。 * 最短固定宽度 8;标题更长时框线随字数加长。
*/ */
const A2_FRAME_MIN_WIDTH = Math.round(28 * (2 / 3)); // 19 const A2_H1_MIN_WIDTH = Math.round(13 * (3 / 5)); // 8
/** 分隔线保持上一档最短宽 */
const A2_HR_WIDTH = 19;
function frameTitleA2(text: string): string { function frameTitleA2(text: string): string {
const body = `📋 ${text}`; const body = `📋 ${text}`;
const width = Math.max(displayWidth(body), A2_FRAME_MIN_WIDTH); const width = Math.max(displayWidth(body), A2_H1_MIN_WIDTH);
const line = '─'.repeat(width); const line = '─'.repeat(width);
return `<div class="emoji-h1">┌${line}┐<br/>│ ${body}<br/>└${line}┘</div>\n`; return `<div class="emoji-h1">┌${line}┐<br/>│ ${body}<br/>└${line}┘</div>\n`;
} }
/** 分隔线与 H1 最短框同宽虚线 */ /** 分隔线虚线 */
function businessHr(): string { function businessHr(): string {
const dots = Array.from({ length: A2_FRAME_MIN_WIDTH }, () => '·').join( const dots = Array.from({ length: A2_HR_WIDTH }, () => '·').join(' ');
' ',
);
return `<div class="emoji-hr">${dots}</div>\n`; return `<div class="emoji-hr">${dots}</div>\n`;
} }
@ -102,11 +102,15 @@ function plainCodeBlockA2(title: string, code: string): string {
const body = escapeCode(code.replace(/\n$/, '')); const body = escapeCode(code.replace(/\n$/, ''));
const lines = body.split('\n'); const lines = body.split('\n');
const head = `💻 ${title}`; const head = `💻 ${title}`;
// 最短宽与 H1/分割线一致(原约 12+余量的 2/3 量级),内容更长时自适应 // 框宽:上一档再 ×6/5(内容宽 × 27/40;不低于 H1 最短宽)
const maxW = Math.max( const natural = Math.max(
displayWidth(head), displayWidth(head),
...lines.map((line) => displayWidth(line)), ...lines.map((line) => displayWidth(line)),
A2_FRAME_MIN_WIDTH, 1,
);
const maxW = Math.max(
A2_H1_MIN_WIDTH,
Math.round(natural * (3 / 4) * (3 / 4) * (6 / 5)),
); );
const edge = repeatToDisplayWidth('─', maxW); const edge = repeatToDisplayWidth('─', maxW);
return `<div class="emoji-code emoji-code-a2"><pre>┌${edge}┐ return `<div class="emoji-code emoji-code-a2"><pre>┌${edge}┐
@ -169,7 +173,7 @@ export const THEME_A2: EmojiTheme = {
name: '主题 A2 · 商务', name: '主题 A2 · 商务',
shortName: 'A2 商务', shortName: 'A2 商务',
description: description:
'正式商务 + 职场 emoji 色彩:B 式线框、钉选/清单符号、彩色序号', '正式商务 + 职场 emoji:B 式线框、📗 二级标题、小橙钻列表',
listSymbol: '🔸', listSymbol: '🔸',
orderedNumbers: [ orderedNumbers: [
'1️⃣', '1️⃣',
@ -184,10 +188,10 @@ export const THEME_A2: EmojiTheme = {
'🔟', '🔟',
], ],
nestPrefix: '│', nestPrefix: '│',
taskChecked: '✅', taskChecked: '✔️',
taskUnchecked: '⬜', taskUnchecked: '⬜',
heading1: frameTitleA2, heading1: frameTitleA2,
heading2: (text) => `<div class="emoji-h2">📌 ${text}</div>\n`, heading2: (text) => `<div class="emoji-h2">📗 ${text}</div>\n`,
heading3: (text) => `<div class="emoji-h3">📎 ${text}</div>\n`, heading3: (text) => `<div class="emoji-h3">📎 ${text}</div>\n`,
heading4: (text) => `<div class="emoji-h4">▪️ ${text}</div>\n`, heading4: (text) => `<div class="emoji-h4">▪️ ${text}</div>\n`,
hr: businessHr(), hr: businessHr(),
@ -198,7 +202,7 @@ export const THEME_A2: EmojiTheme = {
em: (text) => `〈${text}〉`, em: (text) => `〈${text}〉`,
del: (text) => `〚${text}〛`, del: (text) => `〚${text}〛`,
blockquote: (content) => blockquote: (content) =>
`<div class="emoji-quote" style="white-space:pre;">💬┃ ${content}</div>`, `<div class="emoji-quote" style="white-space:pre;"> │ ${content}</div>`,
tableLabel: '📊 表格', tableLabel: '📊 表格',
tableStyle: 'frame', tableStyle: 'frame',
link: (text, href) => link: (text, href) =>