diff --git a/public/static/css/phone-image-templates.css b/public/static/css/phone-image-templates.css index 9df46d3..4481255 100644 --- a/public/static/css/phone-image-templates.css +++ b/public/static/css/phone-image-templates.css @@ -747,7 +747,17 @@ body > .page-header-right .layui-btn:not(.layui-btn-primary):not(.layui-btn-norm box-sizing: border-box; } +/* ============================================ + Editor Content - Basic Readability + 编辑器容器仅保留基础可读性样式 + ============================================ */ + +/* Editor container - basic readability only */ #editor-text-area { + font-family: var(--pi-font-family); + font-size: var(--pi-font-size-base); + line-height: var(--pi-line-height); + color: var(--pi-color-text); width: 540px; min-height: 300px; padding: 10px; @@ -755,93 +765,95 @@ body > .page-header-right .layui-btn:not(.layui-btn-primary):not(.layui-btn-norm box-sizing: border-box; } +/* Keep images constrained in editor */ +#editor-text-area img { + max-width: 100%; + height: auto; +} + /* ============================================ - Editor Content Typography (编辑器内排版样式) - 与截图输出区域(staging)的视觉保持一致 - 作用域: #editor-text-area 内部元素 + Render Preview Area (渲染预览区排版样式) + 中间预览列的完整排版样式 ============================================ */ -#editor-text-area { +#render-preview { font-family: var(--pi-font-family); font-size: var(--pi-font-size-base); line-height: var(--pi-line-height); color: var(--pi-color-text); } -/* 编辑区标题字号 — 与 .page-content h2~h6 对齐 */ -#editor-text-area h1 { +/* 预览区标题字号 */ +#render-preview h1 { font-size: 22px; font-weight: bold; letter-spacing: 1px; margin-top: 24px; margin-bottom: 12px; - color: var(--pi-color-text); line-height: 1.4; } -#editor-text-area h2 { +#render-preview h2 { font-weight: normal; font-size: 18px; letter-spacing: 1px; margin-top: 24px; margin-bottom: 12px; - color: #333; } -#editor-text-area h3 { +#render-preview h3 { font-weight: normal; font-size: 16px; margin-top: 20px; margin-bottom: 10px; - color: #555; } -#editor-text-area h4 { +#render-preview h4 { font-size: 14px; font-weight: bold; - margin-top: var(--pi-spacing-sm); + margin-top: 10px; margin-bottom: 5px; } -#editor-text-area h5 { +#render-preview h5 { font-size: 13px; font-weight: bold; - margin-top: var(--pi-spacing-sm); + margin-top: 10px; margin-bottom: 5px; } -#editor-text-area h6 { +#render-preview h6 { font-size: 12px; font-weight: bold; - margin-top: var(--pi-spacing-sm); + margin-top: 10px; margin-bottom: 5px; - color: var(--pi-color-text-light); + color: #999; } -/* 编辑区段落 */ -#editor-text-area p { +/* 预览区段落 */ +#render-preview p { text-indent: 2em; margin-bottom: 16px; color: #333; } -/* 编辑区图片 */ -#editor-text-area img { +/* 预览区图片 */ +#render-preview img { max-width: 100% !important; height: auto !important; display: block; margin: 10px 0; } -/* 编辑区表格 */ -#editor-text-area table { +/* 预览区表格 */ +#render-preview table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; } -#editor-text-area th { +#render-preview th { background-color: #f0f0f0; font-weight: bold; padding: 8px 10px; @@ -849,17 +861,17 @@ body > .page-header-right .layui-btn:not(.layui-btn-primary):not(.layui-btn-norm text-align: left; } -#editor-text-area td { +#render-preview td { padding: 8px 10px; border: 1px solid #ddd; } -#editor-text-area tr:nth-child(even) td { +#render-preview tr:nth-child(even) td { background-color: #f9f9f9; } -/* 编辑区代码块 */ -#editor-text-area pre { +/* 预览区代码块 */ +#render-preview pre { background: #f5f5f5; border: 1px solid #e0e0e0; border-radius: 4px; @@ -870,34 +882,34 @@ body > .page-header-right .layui-btn:not(.layui-btn-primary):not(.layui-btn-norm margin: 10px 0; } -#editor-text-area code { +#render-preview code { font-family: 'Courier New', Consolas, monospace; font-size: 13px; } -#editor-text-area pre code { +#render-preview pre code { background: none; border: none; padding: 0; } -/* 编辑区引用 */ -#editor-text-area blockquote { +/* 预览区引用 */ +#render-preview blockquote { border-left: 1px solid #ccc; font-style: normal; color: #888; padding-left: 15px; - margin: var(--pi-spacing-sm) 0; + margin: 10px 0; } -/* 编辑区列表 */ -#editor-text-area ul, -#editor-text-area ol { - padding-left: var(--pi-spacing); - margin-bottom: var(--pi-spacing-sm); +/* 预览区列表 */ +#render-preview ul, +#render-preview ol { + padding-left: 20px; + margin-bottom: 10px; } -#editor-text-area li { +#render-preview li { margin-bottom: 5px; } diff --git a/public/static/js/phone-image.js b/public/static/js/phone-image.js index 97c36bc..657e09a 100644 --- a/public/static/js/phone-image.js +++ b/public/static/js/phone-image.js @@ -95,9 +95,10 @@ var PhoneImageEngine = (function () { var pageHeight = sizeConfig.height; var contentAreaHeight = pageHeight - (config.contentPadding * 2); - // 从 wangeditor 读取内容 - var editorHtml = window.phoneImageEditor ? window.phoneImageEditor.getHtml() : postData.content_html; - var cleanHtml = preprocessContent(editorHtml); + // 从预览区读取已预处理的内容 + syncPreview(); + var previewEl = document.getElementById('render-preview'); + var cleanHtml = previewEl ? previewEl.innerHTML : ''; var blocks = parseHtmlToBlocks(cleanHtml); // 空内容检测 @@ -111,7 +112,7 @@ var PhoneImageEngine = (function () { pages.push(generateCoverPage(sizeConfig)); // 内容分页(使用 captureEditorBlocks,T3 会完善截图逻辑) - captureEditorBlocks(editorHtml, blocks, contentAreaHeight, sizeConfig).then(function(contentPages) { + captureEditorBlocks(cleanHtml, blocks, contentAreaHeight, sizeConfig).then(function(contentPages) { pages = pages.concat(contentPages); // 尾页 @@ -194,6 +195,15 @@ var PhoneImageEngine = (function () { return html; } + /** + * 同步渲染预览区 - 将编辑器HTML写入预览区 + */ + function syncPreview() { + var html = window.phoneImageEditor ? window.phoneImageEditor.getHtml() : postData.content_html; + var cleanHtml = preprocessContent(html); + $('#render-preview').html(cleanHtml); + } + /** * 将HTML解析为块级元素数组 * 每个块: { type, html, estimatedHeight } @@ -354,7 +364,6 @@ var PhoneImageEngine = (function () { if (blocks[i].type === 'page-break') { if (currentGroup.blocks.length > 0) groups.push(currentGroup); currentGroup = { blocks: [], domIndices: [] }; - // page-break 对应 wangeditor 中的 divider(hr),在 DOM 中也是一个子元素 domIdx++; continue; } @@ -369,70 +378,55 @@ var PhoneImageEngine = (function () { return deferred.promise(); } - // 获取编辑器子元素 - var editorChildren = getEditorChildren(); - - // 创建测量容器(500px = 540 - 20*2 padding,与内容区一致) - var $mc = $('