mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 04:31:27 +08:00
fix: update paths for style resources in electron-builder configuration and ExportService
This commit is contained in:
parent
bb76f83367
commit
1ec308f9a3
@ -11,10 +11,6 @@ export const PRINT_HTML_TEMPLATE = `
|
||||
<meta charset="utf-8">
|
||||
<title>{{filename}}</title>
|
||||
<style>
|
||||
@page {
|
||||
margin: 1cm;
|
||||
size: A4;
|
||||
}
|
||||
@media print {
|
||||
body {
|
||||
-webkit-print-color-adjust: exact;
|
||||
|
||||
@ -438,12 +438,36 @@ export class ExportService {
|
||||
const fontCss = await loadCssFile('font.css')
|
||||
const richtextCss = await loadCssFile('richtext.css')
|
||||
|
||||
// PDF专用样式,解决代码块溢出问题
|
||||
const pdfSpecificCss = `
|
||||
@media print {
|
||||
.tiptap pre {
|
||||
white-space: pre-wrap !important;
|
||||
word-wrap: break-word !important;
|
||||
overflow-wrap: break-word !important;
|
||||
max-width: 100% !important;
|
||||
box-sizing: border-box !important;
|
||||
}
|
||||
|
||||
.tiptap pre code {
|
||||
white-space: pre-wrap !important;
|
||||
word-wrap: break-word !important;
|
||||
overflow-wrap: break-word !important;
|
||||
}
|
||||
|
||||
.tiptap {
|
||||
max-width: 100% !important;
|
||||
overflow: hidden !important;
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const tempHtmlPath = path.join(os.tmpdir(), `temp_${Date.now()}.html`)
|
||||
await fs.promises.writeFile(
|
||||
tempHtmlPath,
|
||||
PRINT_HTML_TEMPLATE.replace('{{filename}}', filename.replace('.pdf', ''))
|
||||
.replace('{{colorCss}}', colorCss)
|
||||
.replace('{{richtextCss}}', richtextCss)
|
||||
.replace('{{richtextCss}}', richtextCss + pdfSpecificCss)
|
||||
.replace('{{fontCss}}', fontCss)
|
||||
.replace('{{content}}', content)
|
||||
)
|
||||
|
||||
@ -55,7 +55,32 @@ const addSyntaxHighlighting = async (html: string): Promise<string> => {
|
||||
const highlightedCode = tempDoc.querySelector('code')
|
||||
|
||||
if (highlightedCode) {
|
||||
// 保留原有的类名和属性
|
||||
const originalClasses = codeElement.className
|
||||
const originalAttributes = Array.from(codeElement.attributes)
|
||||
|
||||
// 替换内容
|
||||
codeElement.innerHTML = highlightedCode.innerHTML
|
||||
|
||||
// 合并类名
|
||||
const highlightedClasses = highlightedCode.className
|
||||
const mergedClasses = [originalClasses, highlightedClasses]
|
||||
.filter((cls) => cls && cls.trim())
|
||||
.join(' ')
|
||||
.split(' ')
|
||||
.filter((cls, index, arr) => cls && arr.indexOf(cls) === index) // 去重
|
||||
.join(' ')
|
||||
|
||||
if (mergedClasses) {
|
||||
codeElement.className = mergedClasses
|
||||
}
|
||||
|
||||
// 保留原有的其他属性(除了class)
|
||||
originalAttributes.forEach((attr) => {
|
||||
if (attr.name !== 'class' && !codeElement.hasAttribute(attr.name)) {
|
||||
codeElement.setAttribute(attr.name, attr.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user