dashboard: box each section (h2 large / h3 nested) in session detail pages
This commit is contained in:
@@ -17,6 +17,7 @@ from __future__ import annotations
|
||||
import datetime as _dt
|
||||
import html as _html
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -113,6 +114,10 @@ tr:last-child td{border-bottom:none}
|
||||
.md hr{border:0;border-top:1px solid #232b38;margin:18px 0}
|
||||
.md blockquote{border-left:3px solid #2f5f96;margin:10px 0;padding:2px 14px;color:#b9c3d3}
|
||||
.md p.pending{border:1px dashed #3f5a7d;border-radius:8px;padding:10px 14px;color:#7f8aa0;background:#141821;margin:8px 0}
|
||||
.md .sec{background:#141821;border:1px solid #2a2e3a;border-radius:12px;padding:4px 18px 14px;margin:16px 0}
|
||||
.md .sec>h2:first-child{margin-top:.5em}
|
||||
.md .subsec{background:#171a21;border:1px solid #262b36;border-left:3px solid #3f5a7d;border-radius:8px;padding:2px 16px 12px;margin:12px 0}
|
||||
.md .subsec>h3:first-child{margin-top:.5em}
|
||||
"""
|
||||
|
||||
# 页头/页脚:banner 结构(参考 FRA 模板)
|
||||
@@ -183,7 +188,26 @@ def render_md(text: str) -> str:
|
||||
out = _md.markdown(text, extensions=["tables", "fenced_code"])
|
||||
except ImportError:
|
||||
out = "<pre>" + _html.escape(text) + "</pre>"
|
||||
return out.replace("<p>(待登记)</p>", '<p class="pending">(待登记)</p>')
|
||||
out = out.replace("<p>(待登记)</p>", '<p class="pending">(待登记)</p>')
|
||||
return _wrap_sections(out)
|
||||
|
||||
|
||||
def _wrap_sections(html: str) -> str:
|
||||
"""把渲染后的 HTML 按 h2 分大框、h3 分小框,便于阅读。"""
|
||||
chunks = re.split(r"(?=<h2)", html)
|
||||
out = []
|
||||
for c in chunks:
|
||||
c = c.strip()
|
||||
if not c:
|
||||
continue
|
||||
if c.startswith("<h2"):
|
||||
inner = "".join(
|
||||
f'<div class="subsec">{s.strip()}</div>' if s.strip().startswith("<h3") else s
|
||||
for s in re.split(r"(?=<h3)", c))
|
||||
out.append(f'<section class="sec">{inner}</section>')
|
||||
else:
|
||||
out.append(c)
|
||||
return "".join(out)
|
||||
|
||||
|
||||
def session_body(s: dict, files: list[tuple[str, str]]) -> str:
|
||||
|
||||
Reference in New Issue
Block a user