From fcaa994d4ec07ec96a7d2f0b4c47098b0e80fcac Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 22 Nov 2023 11:54:17 -0500 Subject: [PATCH] LibWebView: Extract CSS to highlight HTML source to a constant We will be re-using (and extending) this style in the WebView-based DOM inspector. --- .../LibWebView/SourceHighlighter.cpp | 44 +----------------- .../Libraries/LibWebView/SourceHighlighter.h | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/Userland/Libraries/LibWebView/SourceHighlighter.cpp b/Userland/Libraries/LibWebView/SourceHighlighter.cpp index 38a31605e0..0807e21097 100644 --- a/Userland/Libraries/LibWebView/SourceHighlighter.cpp +++ b/Userland/Libraries/LibWebView/SourceHighlighter.cpp @@ -23,51 +23,11 @@ String highlight_source(URL const& url, StringView source) )~~~"sv); builder.appendff("View Source - {}", url); - + builder.appendff("", HTML_HIGHLIGHTER_STYLE); builder.append(R"~~~( - -
+
 )~~~"sv);
 
     size_t previous_position = 0;
diff --git a/Userland/Libraries/LibWebView/SourceHighlighter.h b/Userland/Libraries/LibWebView/SourceHighlighter.h
index 69345cf5c9..2d4f204947 100644
--- a/Userland/Libraries/LibWebView/SourceHighlighter.h
+++ b/Userland/Libraries/LibWebView/SourceHighlighter.h
@@ -13,4 +13,50 @@ namespace WebView {
 
 String highlight_source(URL const&, StringView);
 
+constexpr inline StringView HTML_HIGHLIGHTER_STYLE = R"~~~(
+    .html {
+        font-size: 10pt;
+        font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
+    }
+
+    .tag {
+        font-weight: 600;
+    }
+
+    @media (prefers-color-scheme: dark) {
+        /* FIXME: We should be able to remove the HTML style when "color-scheme" is supported */
+        html {
+            background-color: rgb(30, 30, 30);
+            color: white;
+        }
+        .comment {
+            color: lightgreen;
+        }
+        .tag {
+            color: orangered;
+        }
+        .attribute-name {
+            color: orange;
+        }
+        .attribute-value {
+            color: deepskyblue;
+        }
+    }
+
+    @media (prefers-color-scheme: light) {
+        .comment {
+            color: green;
+        }
+        .tag {
+            color: red;
+        }
+        .attribute-name {
+            color: darkorange;
+        }
+        .attribute-value {
+            color: blue;
+        }
+    }
+)~~~"sv;
+
 }