package server import ( "fmt" "regexp" "strings" ) // show_html renders in a sandbox with no scripts and no network, and follows // the dark theme only when the document declares dark support (the same test // as the app's artifactHtmlSupportsDark). shownHTMLWarnings tells the model // when its document relies on what the sandbox blocks, or will stay light, so // it can fix the view rather than believe it was shown as written. var ( shownHTMLScript = regexp.MustCompile(`(?i)]*\son[a-z]+\s*=`) shownHTMLDarkAware = regexp.MustCompile(`(?i)prefers-color-scheme|color-scheme|light-dark\(`) // A remote reference: an attribute or CSS url()/@import naming an // http(s) or protocol-relative address. shownHTMLRemote = regexp.MustCompile(`(?i)(?:\b(?:src|href|srcset|poster|data)\s*=\s*["']?|url\(\s*["']?|@import\s+["'])((?:https?:)?//[^"')\s>]+)`) ) // shownHTMLWarnings lists what in html will not work as written, or nil. func shownHTMLWarnings(html string) []string { var warnings []string if shownHTMLScript.MatchString(html) || shownHTMLHandler.MatchString(html) { warnings = append(warnings, "it contains JavaScript (