Spaces:
Running on Zero
Running on Zero
zhiyi commited on
Commit ·
613e06a
1
Parent(s): 29bb346
Enable PDF printing from deck preview
Browse files- app.py +2 -2
- static/deck.js +1 -0
- tests/test_app.py +6 -2
app.py
CHANGED
|
@@ -915,7 +915,7 @@ def render_presentation(report: dict[str, Any], papers: list[dict[str, Any]], cu
|
|
| 915 |
title, subtitle = esc(report.get("title", "Algorithm Research")), esc(report.get("subtitle", ""))
|
| 916 |
return f'''<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
| 917 |
<title>{title}</title><style>{deck_css}</style></head><body>
|
| 918 |
-
<nav class="deck-nav"><button id="menu" aria-label="打开目录" aria-expanded="false">☰</button><strong>{title}</strong><span id="counter"></span><button id="prev" aria-label="上一页">←</button><button id="next" aria-label="下一页">→</button><button
|
| 919 |
<aside id="overview" class="overview" aria-hidden="true"><header><strong>演示目录</strong><button id="close-overview" aria-label="关闭目录">×</button></header><a data-slide-target="cover">封面</a><a data-slide-target="summary">核心结论</a><a data-slide-target="agenda">研究结构</a>{agenda_items}<a data-slide-target="references">参考文献与局限</a></aside><div id="scrim" class="scrim"></div>
|
| 920 |
<main><section class="slide cover active" id="cover" data-title="封面"><div class="cover-orb"></div><p class="eyebrow">ALGORITHM RESEARCH / {esc(cutoff)}</p><h1>{title}</h1><p class="subtitle">{subtitle}</p><div class="cover-meta"><span>{esc(report.get("research_type"))}</span><span>{esc(evidence_label)}</span></div><p class="evidence-note">{esc(evidence_note)}</p><p class="hint">方向键翻页 · 点击左上角查看目录 · 可打印保存</p></section>
|
| 921 |
<section class="slide" id="summary" data-title="核心结论"><p class="eyebrow">01 / EXECUTIVE SUMMARY</p><h2>先看结论</h2><div class="summary-grid">{summary_html}</div></section>
|
|
@@ -934,7 +934,7 @@ def create_bundle(job_dir: Path, html_path: Path, report_path: Path) -> Path:
|
|
| 934 |
|
| 935 |
def preview_frame(content: str) -> str:
|
| 936 |
source = html.escape(content, quote=True)
|
| 937 |
-
return f'<iframe title="Interactive research presentation" srcdoc="{source}" style="width:100%;height:80vh;border:0;border-radius:14px;background:#071018;box-shadow:0 14px 40px #12283c2b" sandbox="allow-scripts allow-popups"></iframe>'
|
| 938 |
|
| 939 |
|
| 940 |
def run_research_ui(
|
|
|
|
| 915 |
title, subtitle = esc(report.get("title", "Algorithm Research")), esc(report.get("subtitle", ""))
|
| 916 |
return f'''<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
| 917 |
<title>{title}</title><style>{deck_css}</style></head><body>
|
| 918 |
+
<nav class="deck-nav"><button id="menu" aria-label="打开目录" aria-expanded="false">☰</button><strong>{title}</strong><span id="counter"></span><button id="prev" aria-label="上一页">←</button><button id="next" aria-label="下一页">→</button><button id="print" title="打印或保存为 PDF">保存 PDF</button></nav>
|
| 919 |
<aside id="overview" class="overview" aria-hidden="true"><header><strong>演示目录</strong><button id="close-overview" aria-label="关闭目录">×</button></header><a data-slide-target="cover">封面</a><a data-slide-target="summary">核心结论</a><a data-slide-target="agenda">研究结构</a>{agenda_items}<a data-slide-target="references">参考文献与局限</a></aside><div id="scrim" class="scrim"></div>
|
| 920 |
<main><section class="slide cover active" id="cover" data-title="封面"><div class="cover-orb"></div><p class="eyebrow">ALGORITHM RESEARCH / {esc(cutoff)}</p><h1>{title}</h1><p class="subtitle">{subtitle}</p><div class="cover-meta"><span>{esc(report.get("research_type"))}</span><span>{esc(evidence_label)}</span></div><p class="evidence-note">{esc(evidence_note)}</p><p class="hint">方向键翻页 · 点击左上角查看目录 · 可打印保存</p></section>
|
| 921 |
<section class="slide" id="summary" data-title="核心结论"><p class="eyebrow">01 / EXECUTIVE SUMMARY</p><h2>先看结论</h2><div class="summary-grid">{summary_html}</div></section>
|
|
|
|
| 934 |
|
| 935 |
def preview_frame(content: str) -> str:
|
| 936 |
source = html.escape(content, quote=True)
|
| 937 |
+
return f'<iframe title="Interactive research presentation" srcdoc="{source}" style="width:100%;height:80vh;border:0;border-radius:14px;background:#071018;box-shadow:0 14px 40px #12283c2b" sandbox="allow-scripts allow-popups allow-modals"></iframe>'
|
| 938 |
|
| 939 |
|
| 940 |
def run_research_ui(
|
static/deck.js
CHANGED
|
@@ -41,6 +41,7 @@ function showById(id) {
|
|
| 41 |
|
| 42 |
document.getElementById('prev').addEventListener('click', () => show(current - 1));
|
| 43 |
document.getElementById('next').addEventListener('click', () => show(current + 1));
|
|
|
|
| 44 |
menu.addEventListener('click', () => overview.classList.contains('open') ? closeOverview() : openOverview());
|
| 45 |
document.getElementById('close-overview').addEventListener('click', closeOverview);
|
| 46 |
scrim.addEventListener('click', closeOverview);
|
|
|
|
| 41 |
|
| 42 |
document.getElementById('prev').addEventListener('click', () => show(current - 1));
|
| 43 |
document.getElementById('next').addEventListener('click', () => show(current + 1));
|
| 44 |
+
document.getElementById('print').addEventListener('click', () => window.print());
|
| 45 |
menu.addEventListener('click', () => overview.classList.contains('open') ? closeOverview() : openOverview());
|
| 46 |
document.getElementById('close-overview').addEventListener('click', closeOverview);
|
| 47 |
scrim.addEventListener('click', closeOverview);
|
tests/test_app.py
CHANGED
|
@@ -4,7 +4,7 @@ from unittest.mock import patch
|
|
| 4 |
|
| 5 |
from pydantic import ValidationError
|
| 6 |
|
| 7 |
-
from app import ResearchReport, chat_json, deduplicate, infer_section_source_ids, normalize_comparison, normalize_process, parse_json_object, prepare_evidence_inputs, render_presentation, render_section_content, render_value, safe_slug, search_literature, serializable_validation_errors
|
| 8 |
|
| 9 |
|
| 10 |
def base_report(section):
|
|
@@ -63,11 +63,15 @@ class AppTests(unittest.TestCase):
|
|
| 63 |
section = {"title": "Scope", "purpose": "Define the technical decision boundary.", "takeaway": "The boundary determines the useful evidence.", "layout": "text", "content": {"points": ["A meaningful point", "Another meaningful point"]}, "source_ids": []}
|
| 64 |
output = render_presentation(base_report(section), [], "2026-01-01")
|
| 65 |
self.assertIn("<!doctype html>", output)
|
| 66 |
-
self.assertIn("保存 PDF", output)
|
| 67 |
self.assertIn('id="overview"', output)
|
| 68 |
self.assertIn('id="agenda"', output)
|
| 69 |
self.assertIn('data-slide-target="section-1"', output)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def test_source_chip_links_to_rendered_reference(self):
|
| 72 |
section = {"title": "Evidence", "purpose": "Connect a claim to retrieved evidence.", "takeaway": "The cited result supports this bounded conclusion.", "layout": "evidence", "content": {"claim": "A supported claim", "conditions": ["A stated condition"]}, "source_ids": ["paper-1"]}
|
| 73 |
report = base_report(section)
|
|
|
|
| 4 |
|
| 5 |
from pydantic import ValidationError
|
| 6 |
|
| 7 |
+
from app import ResearchReport, chat_json, deduplicate, infer_section_source_ids, normalize_comparison, normalize_process, parse_json_object, prepare_evidence_inputs, preview_frame, render_presentation, render_section_content, render_value, safe_slug, search_literature, serializable_validation_errors
|
| 8 |
|
| 9 |
|
| 10 |
def base_report(section):
|
|
|
|
| 63 |
section = {"title": "Scope", "purpose": "Define the technical decision boundary.", "takeaway": "The boundary determines the useful evidence.", "layout": "text", "content": {"points": ["A meaningful point", "Another meaningful point"]}, "source_ids": []}
|
| 64 |
output = render_presentation(base_report(section), [], "2026-01-01")
|
| 65 |
self.assertIn("<!doctype html>", output)
|
| 66 |
+
self.assertIn('<button id="print" title="打印或保存为 PDF">保存 PDF</button>', output)
|
| 67 |
self.assertIn('id="overview"', output)
|
| 68 |
self.assertIn('id="agenda"', output)
|
| 69 |
self.assertIn('data-slide-target="section-1"', output)
|
| 70 |
|
| 71 |
+
def test_preview_allows_browser_print_dialog(self):
|
| 72 |
+
frame = preview_frame("<!doctype html><title>Deck</title>")
|
| 73 |
+
self.assertIn('sandbox="allow-scripts allow-popups allow-modals"', frame)
|
| 74 |
+
|
| 75 |
def test_source_chip_links_to_rendered_reference(self):
|
| 76 |
section = {"title": "Evidence", "purpose": "Connect a claim to retrieved evidence.", "takeaway": "The cited result supports this bounded conclusion.", "layout": "evidence", "content": {"claim": "A supported claim", "conditions": ["A stated condition"]}, "source_ids": ["paper-1"]}
|
| 77 |
report = base_report(section)
|