* 转换为HTML格式
(
content: DocumentContent,
outputPath: string,
styling: any
)
| 190 | * 转换为HTML格式 |
| 191 | */ |
| 192 | private async convertToHTML( |
| 193 | content: DocumentContent, |
| 194 | outputPath: string, |
| 195 | styling: any |
| 196 | ): Promise<DocumentConversionResult> { |
| 197 | try { |
| 198 | // 将内容转换为HTML |
| 199 | const htmlContent = this.parseContentToHTML(content.content); |
| 200 | |
| 201 | const html = ` |
| 202 | <!DOCTYPE html> |
| 203 | <html lang="zh-CN"> |
| 204 | <head> |
| 205 | <meta charset="UTF-8"> |
| 206 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 207 | <title>${this.escapeHtml(content.title ?? '文档')}</title> |
| 208 | ${content.author ? `<meta name="author" content="${this.escapeHtml(content.author)}">` : ''} |
| 209 | ${content.description ? `<meta name="description" content="${this.escapeHtml(content.description)}">` : ''} |
| 210 | <style> |
| 211 | body { |
| 212 | font-family: '${this.escapeHtml(styling.fontFamily)}', 'Microsoft YaHei', 'SimHei', Arial, sans-serif; |
| 213 | font-size: ${styling.fontSize}px; |
| 214 | line-height: ${styling.lineHeight}; |
| 215 | color: ${this.escapeHtml(styling.colors.text)}; |
| 216 | max-width: 800px; |
| 217 | margin: 0 auto; |
| 218 | padding: ${styling.margins.top / 4}px ${styling.margins.left / 4}px; |
| 219 | background-color: #fff; |
| 220 | } |
| 221 | h1, h2, h3, h4, h5, h6 { |
| 222 | color: ${this.escapeHtml(styling.colors.primary)}; |
| 223 | margin-top: 30px; |
| 224 | margin-bottom: 15px; |
| 225 | } |
| 226 | h1 { |
| 227 | font-size: 2.5em; |
| 228 | text-align: center; |
| 229 | border-bottom: 3px solid ${this.escapeHtml(styling.colors.primary)}; |
| 230 | padding-bottom: 10px; |
| 231 | } |
| 232 | h2 { |
| 233 | font-size: 1.8em; |
| 234 | border-left: 4px solid ${this.escapeHtml(styling.colors.primary)}; |
| 235 | padding-left: 15px; |
| 236 | } |
| 237 | h3 { |
| 238 | font-size: 1.4em; |
| 239 | } |
| 240 | p { |
| 241 | margin-bottom: 15px; |
| 242 | text-align: justify; |
| 243 | text-indent: 2em; |
| 244 | } |
| 245 | .meta-info { |
| 246 | background-color: #f8f9fa; |
| 247 | padding: 15px; |
| 248 | border-left: 4px solid ${this.escapeHtml(styling.colors.secondary)}; |
| 249 | margin-bottom: 30px; |
no test coverage detected