fix: polish A2 preview spacing, quotes, and heading colors
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:
parent
84d523558e
commit
21ef5167b6
13
README.md
13
README.md
@ -17,7 +17,7 @@
|
||||
|------|------|
|
||||
| 三栏联动 | 左编辑 / 中 Emoji 纯文本 / 右长文富文本;滚动按比例同步,语法与渲染对应 |
|
||||
| Markdown 实时预览 | 基于 `marked`:中间栏自定义 Emoji Renderer,右侧栏 GFM 富文本 |
|
||||
| 四套 + A2 主题 | 经典 / **A2 商务**(B 式线框 H1 + 📋📌🔸1️⃣;表格全角 `-|`)/ 青简 / 精简 / 聚焦 |
|
||||
| 四套 + A2 主题 | 经典 / **A2 商务**(B 式线框 H1 + 📗 / 🔸;表格全角 `-|`)/ 青简 / 精简 / 聚焦 |
|
||||
| Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现;纯文本栏禁止 CSS 画框 |
|
||||
| 一键复制 | 中间栏复制纯文本(所见即粘贴);右侧栏复制富文本 HTML |
|
||||
| 可视化表格 | MarkText 风格插入/编辑表格,插入前可填单元格 |
|
||||
@ -46,12 +46,13 @@
|
||||
|
||||
### 主题 A2 · 商务(纯文本栏)
|
||||
|
||||
- **H1**:主题 B 同款 `┌─┐│└─┘` 线框 + `📋`(最短宽约原 2/3,超长自适应)
|
||||
- **H2**:`📌`;**H3**:`📎`;列表 `🔸` / `1️⃣…`
|
||||
- **行内代码**:`『…』`;代码块:`┌─┐` 线框(最短宽与 H1 对齐,超长自适应)
|
||||
- **H1**:主题 B 同款 `┌─┐│└─┘` 线框 + `📋`(最短宽约 8,超长自适应)
|
||||
- **H2**:`📗`;**H3**:`📎`;列表 `🔸` / `1️⃣…`
|
||||
- **行内代码**:`『…』`;代码块:`┌─┐` 线框(框宽约内容的 27/40)
|
||||
- **表格**:全角 `-|` 线框(与微信/雅黑对齐);图片在纯文本栏不输出
|
||||
- **任务**:`✅` / `⬜`(无额外列表符)
|
||||
- **分隔线**:与 H1 最短框同宽虚线 `· · · …`
|
||||
- **任务**:`✔️` / `⬜`(无额外列表符)
|
||||
- **引用**:` │ …`(侧栏竖线,类似渲染后的 Markdown 引用)
|
||||
- **分隔线**:虚线 `· · · …`
|
||||
|
||||
## 技术栈
|
||||
|
||||
|
||||
@ -819,15 +819,15 @@
|
||||
}
|
||||
|
||||
.previewHtml {
|
||||
padding: 18px 20px 28px;
|
||||
padding: 8px 12px 12px;
|
||||
font-size: 15px;
|
||||
line-height: 1.75;
|
||||
line-height: 1.42;
|
||||
color: var(--ink);
|
||||
user-select: text;
|
||||
animation: fadeIn 220ms ease;
|
||||
|
||||
> :global(div) {
|
||||
margin: 0 0 0.65em;
|
||||
margin: 0 0 0.2em;
|
||||
}
|
||||
|
||||
> :global(div:last-child) {
|
||||
@ -841,15 +841,15 @@
|
||||
}
|
||||
|
||||
:global(.emoji-footer) {
|
||||
margin-top: 16px;
|
||||
padding-top: 4px;
|
||||
margin-top: 6px;
|
||||
padding-top: 0;
|
||||
color: var(--ink);
|
||||
line-height: 1.7;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
:global(.emoji-table) {
|
||||
margin: 8px 0 12px;
|
||||
line-height: 1.45;
|
||||
margin: 2px 0 5px;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
/* 纯文本预览:表格/代码块禁止上色与装饰边框,所见即复制结果 */
|
||||
@ -866,7 +866,7 @@
|
||||
'PingFang SC',
|
||||
monospace;
|
||||
font-size: 14px;
|
||||
line-height: 1.55;
|
||||
line-height: 1.35;
|
||||
letter-spacing: 0;
|
||||
font-variant-ligatures: none;
|
||||
background: transparent;
|
||||
@ -876,7 +876,7 @@
|
||||
}
|
||||
|
||||
:global(.emoji-code) {
|
||||
margin: 8px 0 12px;
|
||||
margin: 2px 0 5px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
@ -895,7 +895,7 @@
|
||||
Consolas,
|
||||
'Microsoft YaHei',
|
||||
monospace;
|
||||
line-height: 1.55;
|
||||
line-height: 1.35;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: inherit;
|
||||
@ -906,9 +906,9 @@
|
||||
* 预览禁止颜色与 CSS 装饰——复制到微信/小红书/抖音/X 等仍是纯字符。
|
||||
*/
|
||||
&[data-theme='A2'] {
|
||||
padding: 20px 22px 32px;
|
||||
padding: 8px 12px 12px;
|
||||
font-size: 15px;
|
||||
line-height: 1.85;
|
||||
line-height: 1.42;
|
||||
letter-spacing: 0;
|
||||
color: var(--ink);
|
||||
/* 与微信一致:纯 CJK 字体,避免 Cascadia 半角框线把对齐弄坏 */
|
||||
@ -920,12 +920,12 @@
|
||||
font-variant-ligatures: none;
|
||||
|
||||
> :global(div) {
|
||||
margin: 0 0 0.75em;
|
||||
margin: 0 0 0.15em;
|
||||
}
|
||||
|
||||
:global(.emoji-h1) {
|
||||
margin: 0.1em 0 1em;
|
||||
line-height: 1.35;
|
||||
margin: 0 0 0.28em;
|
||||
line-height: 1.25;
|
||||
white-space: pre;
|
||||
font-weight: 400;
|
||||
font-variant-ligatures: none;
|
||||
@ -933,24 +933,25 @@
|
||||
}
|
||||
|
||||
:global(.emoji-h2) {
|
||||
margin: 1.1em 0 0.55em;
|
||||
line-height: 1.5;
|
||||
margin: 0.4em 0 0.14em;
|
||||
line-height: 1.3;
|
||||
white-space: pre-wrap;
|
||||
font-weight: 400;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
:global(.emoji-h3) {
|
||||
margin: 0.9em 0 0.4em;
|
||||
margin: 0.28em 0 0.1em;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
:global(.emoji-h4) {
|
||||
margin: 0.7em 0 0.3em;
|
||||
margin: 0.22em 0 0.08em;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
:global(.emoji-hr) {
|
||||
margin: 1.1em 0;
|
||||
margin: 0.3em 0;
|
||||
text-align: left;
|
||||
color: inherit;
|
||||
white-space: pre;
|
||||
@ -958,7 +959,7 @@
|
||||
}
|
||||
|
||||
:global(.emoji-quote) {
|
||||
margin: 0.25em 0;
|
||||
margin: 0.05em 0;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
@ -975,7 +976,7 @@
|
||||
}
|
||||
|
||||
:global(.emoji-footer) {
|
||||
margin-top: 1.2em;
|
||||
margin-top: 0.45em;
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
@ -1033,7 +1034,7 @@
|
||||
|
||||
max-width: 42rem;
|
||||
margin: 0 auto;
|
||||
padding: 28px 28px 40px;
|
||||
padding: 12px 16px 16px;
|
||||
color: var(--md-ink);
|
||||
font-family:
|
||||
'Source Han Sans SC',
|
||||
@ -1043,7 +1044,7 @@
|
||||
'Microsoft YaHei',
|
||||
sans-serif;
|
||||
font-size: 15.5px;
|
||||
line-height: 1.85;
|
||||
line-height: 1.45;
|
||||
letter-spacing: 0.01em;
|
||||
word-break: break-word;
|
||||
user-select: text;
|
||||
@ -1056,7 +1057,7 @@
|
||||
--md-code-bg: #eef6f9;
|
||||
--md-code-fg: #0c4a5c;
|
||||
font-size: 15px;
|
||||
line-height: 1.8;
|
||||
line-height: 1.42;
|
||||
}
|
||||
|
||||
&[data-theme='C'] {
|
||||
@ -1068,7 +1069,7 @@
|
||||
--md-code-fg: #334155;
|
||||
--md-border: rgba(15, 23, 42, 0.08);
|
||||
font-size: 15px;
|
||||
line-height: 1.78;
|
||||
line-height: 1.4;
|
||||
max-width: 38rem;
|
||||
}
|
||||
|
||||
@ -1083,7 +1084,7 @@
|
||||
--md-border: rgba(28, 25, 23, 0.12);
|
||||
--md-pre-bg: #1c1917;
|
||||
font-size: 16px;
|
||||
line-height: 1.9;
|
||||
line-height: 1.48;
|
||||
}
|
||||
|
||||
:global(h1),
|
||||
@ -1094,21 +1095,21 @@
|
||||
:global(h6) {
|
||||
color: var(--md-ink);
|
||||
font-weight: 700;
|
||||
line-height: 1.35;
|
||||
line-height: 1.25;
|
||||
letter-spacing: -0.01em;
|
||||
margin: 1.55em 0 0.55em;
|
||||
margin: 0.55em 0 0.18em;
|
||||
}
|
||||
|
||||
:global(h1) {
|
||||
font-size: 1.85em;
|
||||
margin-top: 0.2em;
|
||||
padding-bottom: 0.35em;
|
||||
margin-top: 0;
|
||||
padding-bottom: 0.12em;
|
||||
border-bottom: 2px solid var(--md-h1-rule);
|
||||
}
|
||||
|
||||
:global(h2) {
|
||||
font-size: 1.4em;
|
||||
padding-bottom: 0.28em;
|
||||
padding-bottom: 0.1em;
|
||||
border-bottom: 1px solid var(--md-border);
|
||||
}
|
||||
|
||||
@ -1129,7 +1130,7 @@
|
||||
}
|
||||
|
||||
:global(p) {
|
||||
margin: 0 0 1em;
|
||||
margin: 0 0 0.3em;
|
||||
}
|
||||
|
||||
:global(a) {
|
||||
@ -1156,33 +1157,33 @@
|
||||
|
||||
:global(ul),
|
||||
:global(ol) {
|
||||
margin: 0 0 1em;
|
||||
padding-left: 1.45em;
|
||||
margin: 0 0 0.3em;
|
||||
padding-left: 1.35em;
|
||||
}
|
||||
|
||||
:global(li) {
|
||||
margin: 0.28em 0;
|
||||
margin: 0.05em 0;
|
||||
}
|
||||
|
||||
:global(li > p) {
|
||||
margin: 0.2em 0;
|
||||
margin: 0.05em 0;
|
||||
}
|
||||
|
||||
:global(li > ul),
|
||||
:global(li > ol) {
|
||||
margin: 0.25em 0 0.35em;
|
||||
margin: 0.08em 0 0.1em;
|
||||
}
|
||||
|
||||
:global(blockquote) {
|
||||
margin: 0 0 1.1em;
|
||||
padding: 0.65em 1em 0.65em 1.05em;
|
||||
margin: 0 0 0.35em;
|
||||
padding: 0.25em 0.7em 0.25em 0.75em;
|
||||
border-left: 3.5px solid var(--md-accent);
|
||||
background: var(--md-quote-bg);
|
||||
border-radius: 0 10px 10px 0;
|
||||
color: #3d4f63;
|
||||
|
||||
:global(p) {
|
||||
margin: 0.35em 0;
|
||||
margin: 0.1em 0;
|
||||
}
|
||||
|
||||
:global(p:first-child) {
|
||||
@ -1197,7 +1198,7 @@
|
||||
:global(hr) {
|
||||
border: none;
|
||||
height: 1px;
|
||||
margin: 1.6em 0;
|
||||
margin: 0.5em 0;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
@ -1223,8 +1224,8 @@
|
||||
}
|
||||
|
||||
:global(pre) {
|
||||
margin: 0 0 1.15em;
|
||||
padding: 14px 16px;
|
||||
margin: 0 0 0.35em;
|
||||
padding: 8px 10px;
|
||||
overflow-x: auto;
|
||||
border-radius: 12px;
|
||||
background: var(--md-pre-bg);
|
||||
@ -1247,7 +1248,7 @@
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
display: block;
|
||||
margin: 1em auto;
|
||||
margin: 0.35em auto;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 8px 28px rgba(26, 35, 48, 0.1);
|
||||
}
|
||||
@ -1255,7 +1256,7 @@
|
||||
:global(table) {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 0 0 1.2em;
|
||||
margin: 0 0 0.4em;
|
||||
font-size: 0.94em;
|
||||
overflow: hidden;
|
||||
border-radius: 10px;
|
||||
@ -1264,7 +1265,7 @@
|
||||
|
||||
:global(th),
|
||||
:global(td) {
|
||||
padding: 10px 14px;
|
||||
padding: 5px 8px;
|
||||
border-bottom: 1px solid var(--md-border);
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
|
||||
@ -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>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
source: string,
|
||||
options?: {
|
||||
@ -312,7 +336,8 @@ export function renderEmojiMarkdown(
|
||||
const footerText = options?.footerText ?? DEFAULT_FOOTER_TEXT;
|
||||
const themeId = options?.themeId ?? DEFAULT_THEME_ID;
|
||||
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);
|
||||
|
||||
if (appendFooter && footerText.trim()) {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Marked, Renderer } from 'marked';
|
||||
import { preferThematicBreakOverSetext } from './emojiMarkdown';
|
||||
|
||||
/**
|
||||
* Display-only: resolve local image hrefs for the article HTML preview.
|
||||
@ -122,7 +123,9 @@ export function renderRichMarkdown(
|
||||
): string {
|
||||
const appendFooter = options?.appendFooter !== false;
|
||||
const footerText = options?.footerText ?? '';
|
||||
const bodyHtml = richMarked.parse(source) as string;
|
||||
const bodyHtml = richMarked.parse(
|
||||
preferThematicBreakOverSetext(source),
|
||||
) as string;
|
||||
|
||||
if (appendFooter && footerText.trim()) {
|
||||
return bodyHtml + formatArticleFooter(footerText);
|
||||
|
||||
@ -65,22 +65,22 @@ function frameTitleB(text: string): string {
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
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);
|
||||
return `<div class="emoji-h1">┌${line}┐<br/>│ ${body}<br/>└${line}┘</div>\n`;
|
||||
}
|
||||
|
||||
/** 分隔线与 H1 最短框同宽虚线 */
|
||||
/** 分隔线虚线 */
|
||||
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`;
|
||||
}
|
||||
|
||||
@ -102,11 +102,15 @@ function plainCodeBlockA2(title: string, code: string): string {
|
||||
const body = escapeCode(code.replace(/\n$/, ''));
|
||||
const lines = body.split('\n');
|
||||
const head = `💻 ${title}`;
|
||||
// 最短宽与 H1/分割线一致(原约 12+余量的 2/3 量级),内容更长时自适应
|
||||
const maxW = Math.max(
|
||||
// 框宽:上一档再 ×6/5(内容宽 × 27/40;不低于 H1 最短宽)
|
||||
const natural = Math.max(
|
||||
displayWidth(head),
|
||||
...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);
|
||||
return `<div class="emoji-code emoji-code-a2"><pre>┌${edge}┐
|
||||
@ -169,7 +173,7 @@ export const THEME_A2: EmojiTheme = {
|
||||
name: '主题 A2 · 商务',
|
||||
shortName: 'A2 商务',
|
||||
description:
|
||||
'正式商务 + 职场 emoji 色彩:B 式线框、钉选/清单符号、彩色序号',
|
||||
'正式商务 + 职场 emoji:B 式线框、📗 二级标题、小橙钻列表',
|
||||
listSymbol: '🔸',
|
||||
orderedNumbers: [
|
||||
'1️⃣',
|
||||
@ -184,10 +188,10 @@ export const THEME_A2: EmojiTheme = {
|
||||
'🔟',
|
||||
],
|
||||
nestPrefix: '│',
|
||||
taskChecked: '✅',
|
||||
taskChecked: '✔️',
|
||||
taskUnchecked: '⬜',
|
||||
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`,
|
||||
heading4: (text) => `<div class="emoji-h4">▪️ ${text}</div>\n`,
|
||||
hr: businessHr(),
|
||||
@ -198,7 +202,7 @@ export const THEME_A2: EmojiTheme = {
|
||||
em: (text) => `〈${text}〉`,
|
||||
del: (text) => `〚${text}〛`,
|
||||
blockquote: (content) =>
|
||||
`<div class="emoji-quote" style="white-space:pre;">💬┃ ${content}</div>`,
|
||||
`<div class="emoji-quote" style="white-space:pre;"> │ ${content}</div>`,
|
||||
tableLabel: '📊 表格',
|
||||
tableStyle: 'frame',
|
||||
link: (text, href) =>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user