LibWebView: Move line-number styling into HTML_HIGHLIGHTER_STYLE

This commit is contained in:
Sam Atkins 2024-09-25 11:58:39 +01:00 committed by Sam Atkins
parent e03da0e600
commit af23f3890b
Notes: github-actions[bot] 2024-09-30 07:54:22 +00:00
2 changed files with 24 additions and 45 deletions

View file

@ -232,48 +232,7 @@ StringView SourceHighlighterClient::class_for_token(u64 token_type) const
}
}
static String generate_style()
{
StringBuilder builder;
builder.append(HTML_HIGHLIGHTER_STYLE);
builder.append(R"~~~(
.html {
counter-reset: line;
}
.line {
counter-increment: line;
white-space: pre;
}
.line::before {
content: counter(line) " ";
display: inline-block;
width: 2.5em;
padding-right: 0.5em;
text-align: right;
}
@media (prefers-color-scheme: dark) {
.line::before {
color: darkgrey;
}
}
@media (prefers-color-scheme: light) {
.line::before {
color: dimgray;
}
}
)~~~"sv);
return MUST(builder.to_string());
}
String SourceHighlighterClient::to_html_string(URL::URL const& url) const
String SourceHighlighterClient::to_html_string(String const& url, HighlightOutputMode mode) const
{
StringBuilder builder;
@ -306,8 +265,8 @@ String SourceHighlighterClient::to_html_string(URL::URL const& url) const
<head>
<meta name="color-scheme" content="dark light">)~~~"sv);
builder.appendff("<title>View Source - {}</title>", escape_html_entities(MUST(url.to_string())));
builder.appendff("<style type=\"text/css\">{}</style>", generate_style());
builder.appendff("<title>View Source - {}</title>", escape_html_entities(url));
builder.appendff("<style type=\"text/css\">{}</style>", HTML_HIGHLIGHTER_STYLE);
builder.append(R"~~~(
</head>
<body>

View file

@ -76,6 +76,7 @@ constexpr inline StringView HTML_HIGHLIGHTER_STYLE = R"~~~(
html {
background-color: rgb(30, 30, 30);
color: white;
counter-reset: line;
}
:root {
@ -86,6 +87,7 @@ constexpr inline StringView HTML_HIGHLIGHTER_STYLE = R"~~~(
--internal-color: darkgrey;
--string-color: goldenrod;
--error-color: red;
--line-number-color: darkgrey;
}
}
@ -98,6 +100,7 @@ constexpr inline StringView HTML_HIGHLIGHTER_STYLE = R"~~~(
--internal-color: dimgrey;
--string-color: darkgoldenrod;
--error-color: darkred;
--line-number-color: dimgrey;
}
}
@ -106,6 +109,23 @@ constexpr inline StringView HTML_HIGHLIGHTER_STYLE = R"~~~(
font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.line {
counter-increment: line;
white-space: pre;
}
.line::before {
content: counter(line) " ";
display: inline-block;
width: 2.5em;
padding-right: 0.5em;
text-align: right;
color: var(--line-number-color);
}
.tag {
font-weight: 600;
color: var(--keyword-color);