Skip to main content

export_engine/
html.rs

1// Self-contained HTML report. Logic moved from peek-cli `render_html`.
2
3use crate::markdown::render_markdown;
4use crate::snapshot::ProcessSnapshot;
5
6/// Render a process snapshot as a dark-themed standalone HTML document.
7pub fn render_html(snapshot: &ProcessSnapshot) -> String {
8    let md = render_markdown(snapshot);
9    let name = &snapshot.process.name;
10    let pid = snapshot.process.pid;
11    format!(
12        r#"<!DOCTYPE html>
13<html lang="en">
14<head>
15<meta charset="UTF-8">
16<meta name="viewport" content="width=device-width,initial-scale=1">
17<title>peek — {name} ({pid})</title>
18<style>
19  body{{font-family:monospace;max-width:960px;margin:2rem auto;padding:1rem;background:#0d1117;color:#c9d1d9}}
20  h1{{color:#58a6ff}} h2{{color:#79c0ff;border-bottom:1px solid #30363d;padding-bottom:.3rem;margin-top:2rem}}
21  table{{border-collapse:collapse;width:100%;margin:1rem 0}}
22  th,td{{border:1px solid #30363d;padding:.4rem .8rem;text-align:left}}
23  th{{background:#161b22;color:#58a6ff}}
24  code{{background:#161b22;padding:.1rem .3rem;border-radius:3px;color:#79c0ff}}
25  pre{{background:#161b22;padding:1rem;overflow-x:auto;border-radius:6px}}
26  blockquote{{border-left:4px solid #388bfd;padding-left:1rem;color:#8b949e}}
27</style>
28</head>
29<body>
30<pre><code>{md_esc}</code></pre>
31</body>
32</html>"#,
33        name = name,
34        pid = pid,
35        md_esc = md
36            .replace('&', "&amp;")
37            .replace('<', "&lt;")
38            .replace('>', "&gt;"),
39    )
40}