MCPcopy Create free account
hub / github.com/Tele-AI/doc-ops-mcp / createHTMLForPDF

Method createHTMLForPDF

src/tools/documentConverter.ts:447–589  ·  view source on GitHub ↗

* 为PDF生成创建HTML内容

(content: DocumentContent, styling: any)

Source from the content-addressed store, hash-verified

445 * 为PDF生成创建HTML内容
446 */
447 private createHTMLForPDF(content: DocumentContent, styling: any): string {
448 const { fontSize, fontFamily, colors } = styling;
449
450 let html = `
451<!DOCTYPE html>
452<html lang="zh-CN">
453<head>
454 <meta charset="UTF-8">
455 <meta name="viewport" content="width=device-width, initial-scale=1.0">
456 <title>${content.title ?? 'Document'}</title>
457 <style>
458 /* 使用本地字体,避免外部资源引用的安全风险 */
459 body {
460 font-family: '微软雅黑', 'Microsoft YaHei', 'SimHei', 'Noto Sans SC', Arial, sans-serif;
461 font-size: ${this.escapeHtml(fontSize.toString())}px;
462 line-height: ${this.escapeHtml(styling.lineHeight.toString())};
463 color: ${this.escapeHtml(colors.text)};
464 margin: 0;
465 padding: 20px;
466 background: white;
467 word-wrap: break-word;
468 word-break: break-all;
469 }
470
471 p {
472 margin: 12px 0;
473 line-height: 1.6;
474 text-align: justify;
475 word-spacing: 0.1em;
476 padding: 4px 0;
477 }
478
479 h1, h2, h3, h4, h5, h6 {
480 margin: 20px 0 12px 0;
481 line-height: 1.4;
482 padding: 6px 0;
483 }
484
485 pre {
486 white-space: pre-wrap;
487 word-wrap: break-word;
488 margin: 12px 0;
489 padding: 12px;
490 background-color: #f8f9fa;
491 border-radius: 4px;
492 }
493
494 br {
495 line-height: 1.6;
496 }
497
498 h1 {
499 color: ${this.escapeHtml(colors.primary)};
500 font-size: ${fontSize * 1.8}px;
501 font-weight: 700;
502 margin-bottom: 20px;
503 line-height: 1.2;
504 }

Callers

nothing calls this directly

Calls 2

escapeHtmlMethod · 0.95
parseContentToHTMLMethod · 0.95

Tested by

no test coverage detected