namespace XFESystem.Documents; public sealed partial class DocumentPreviewBuilder { /// /// The website's article component, for the system's own web renderer. The /// caller must serve this page and WebResources at the same bundled origin. /// This API never executes scripts contained in the Markdown source. /// public PreviewDocument MarkdownWeb(string text, string title = "Markdown", string language = "zh-CN", bool dark = true) => BuildWebsite(markdownRenderer.RenderHtml(text), title, language, dark); public PreviewDocument CodeWeb(string text, string path, string language = "zh-CN", bool dark = true) => BuildWebsite($"
{E(text)}
", path, language, dark); private static PreviewDocument BuildWebsite(string body, string title, string language, bool dark) { // These orders are the shared website partials' order, following the // Bootstrap/theme sheets in _Layout and docs-layout in Docs/View. string[] styles = ["/css/bootstrap.min.css", "/css/theme-variables.css", "/css/bootstrap-icons.min.css", "/css/docs/code-style.css", "/css/docs/markdown-style.css", "/css/docs/log.css", "/css/docs/terminal.css", "/css/docs/katex.min.css", "/css/docs/docs-layout.css"]; string[] scripts = ["/js/docs/highlight.min.js", "/js/docs/xaml.js", "/js/docs/csharp.js", "/js/docs/bash.js", "/js/docs/powershell.js", "/js/docs/dos.js", "/js/docs/log.js", "/js/docs/plaintext.js", "/js/docs/katex.min.js", "/js/docs/auto-render.min.js", "/js/docs/doc-utils.js", "/js/docs/code-block-tools.js", "/js/docs/docs-reader.js"]; var links = string.Join("\n", styles.Select(path => $"")); var includes = string.Join("\n", scripts.Select(path => $"")); var theme = dark ? "dark" : "light"; var html = $$""" {{E(title)}} {{links}}
{{body}}
{{includes}} """; // BrowserService currently treats declared CSP as unsupported and // blocks author scripts. Do not pretend that omission implements CSP: // the resource host must apply this explicit local-only policy, and may // not serve arbitrary caller HTML from its trusted packaged origin. const string policy = "default-src 'none'; script-src 'self'; style-src 'self'; font-src 'self'; " + "img-src data: blob:; connect-src 'none'; object-src 'none'; frame-src 'none'; base-uri 'none'; form-action 'none'"; return new PreviewDocument(html, true, policy); } }