import html from db import get_setting def esc(s): return html.escape(str(s)) def snippet(text, query, ctx=80): pos = text.lower().find(query.lower()) if pos == -1: return text[:200] start = max(0, pos - ctx) end = min(len(text), pos + len(query) + ctx) return ("..." if start > 0 else "") + text[start:end] + ("..." if end < len(text) else "") def wrap_page(body_html): css = get_setting("custom_css") style = f"" if css else "" return f"
{style}{body_html}"