From 7feee33abd8a545361fc7f8a047cc11ac214d558 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 18 Sep 2021 16:47:18 -0700 Subject: [PATCH] Add background and border around code blocks --- src/theme/css/general.css | 6 +++++ src/theme/css/variables.css | 18 ++++++++++++++ src/utils/mod.rs | 48 ++++++++++++++++++------------------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/theme/css/general.css b/src/theme/css/general.css index 0e4f07a5..06baba6c 100644 --- a/src/theme/css/general.css +++ b/src/theme/css/general.css @@ -189,3 +189,9 @@ blockquote { .result-no-output { font-style: italic; } + +pre.syntect { + color: var(--syntect-fg); + background: var(--syntect-bg); + padding: 0.5em; +} diff --git a/src/theme/css/variables.css b/src/theme/css/variables.css index 56b634bc..710f697b 100644 --- a/src/theme/css/variables.css +++ b/src/theme/css/variables.css @@ -40,6 +40,9 @@ --table-header-bg: hsl(210, 25%, 28%); --table-alternate-bg: hsl(210, 25%, 11%); + --syntect-bg: #191f26; + --syntect-fg: #e6e1cf; + --searchbar-border-color: #848484; --searchbar-bg: #424242; --searchbar-fg: #fff; @@ -80,6 +83,9 @@ --table-header-bg: hsl(200, 7%, 28%); --table-alternate-bg: hsl(200, 7%, 11%); + --syntect-bg: #1d1f21; + --syntect-fg: #c5c8c6; + --searchbar-border-color: #aaa; --searchbar-bg: #b7b7b7; --searchbar-fg: #000; @@ -120,6 +126,9 @@ --table-header-bg: hsl(0, 0%, 80%); --table-alternate-bg: hsl(0, 0%, 97%); + --syntect-bg: #f6f7f6; + --syntect-fg: #000; + --searchbar-border-color: #aaa; --searchbar-bg: #fafafa; --searchbar-fg: #000; @@ -160,6 +169,9 @@ --table-header-bg: hsl(226, 23%, 31%); --table-alternate-bg: hsl(226, 23%, 14%); + --syntect-bg: #1d1f21; + --syntect-fg: #c5c8c6; + --searchbar-border-color: #aaa; --searchbar-bg: #aeaec6; --searchbar-fg: #000; @@ -200,6 +212,9 @@ --table-header-bg: #b3a497; --table-alternate-bg: hsl(60, 9%, 84%); + --syntect-bg: #f6f7f6; + --syntect-fg: #000; + --searchbar-border-color: #aaa; --searchbar-bg: #fafafa; --searchbar-fg: #000; @@ -241,6 +256,9 @@ --table-header-bg: hsl(200, 7%, 28%); --table-alternate-bg: hsl(200, 7%, 11%); + --syntect-bg: #1d1f21; + --syntect-fg: #c5c8c6; + --searchbar-border-color: #aaa; --searchbar-bg: #b7b7b7; --searchbar-fg: #000; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 9eba634a..02b56e46 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -338,7 +338,7 @@ impl<'a> SyntaxHighlighter<'a> { } self.is_playground = true; return Event::Html(CowStr::from(format!( - r#"
"#,
+                                r#"
"#,
                                 classes.join(" ")
                             )));
                         } else {
@@ -355,7 +355,7 @@ impl<'a> SyntaxHighlighter<'a> {
                     Event::Html(CowStr::from("
"))
                 } else {
                     Event::Html(CowStr::from(format!(
-                        r#"
"#,
+                        r#"
"#,
                         classes.join(" ")
                     )))
                 }
@@ -578,7 +578,7 @@ more text with spaces
 "#;
 
             let expected = r#"

some text with spaces

-
fn main() {
+
fn main() {
 // code inside is unchanged
 }
 
@@ -704,19 +704,19 @@ more text with spaces fn add_playground() { let inputs = [ ("```rust\nx()\n```", - "
fn main() {\nx()\n}\n
"), + "
fn main() {\nx()\n}\n
"), ("```rust\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("```rust editable\nlet s = \"foo\n # bar\n\";\n```", - "
let s = "foo\n bar\n";\n
"), + "
let s = "foo\n bar\n";\n
"), ("```rust editable\nlet s = \"foo\n ## bar\n\";\n```", - "
let s = "foo\n # bar\n";\n
"), + "
let s = "foo\n # bar\n";\n
"), ("```rust editable\nlet s = \"foo\n # bar\n#\n\";\n```", - "
let s = "foo\n bar\n\n";\n
"), + "
let s = "foo\n bar\n\n";\n
"), ("```rust ignore\nlet s = \"foo\n # bar\n\";\n```", - "
let s = "foo\n bar\n";\n
"), + "
let s = "foo\n bar\n";\n
"), ("```rust editable\n#![no_std]\nlet s = \"foo\";\n #[some_attr]\n```", - "
#![no_std]\nlet s = "foo";\n #[some_attr]\n
"), + "
#![no_std]\nlet s = "foo";\n #[some_attr]\n
"), ]; for (src, should_be) in &inputs { let got = render_markdown( @@ -736,13 +736,13 @@ more text with spaces fn add_playground_edition2015() { let inputs = [ ("```rust\nx()\n```", - "
fn main() {\nx()\n}\n
"), + "
fn main() {\nx()\n}\n
"), ("```rust\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("```rust edition2015\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("```rust edition2018\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ]; for (src, should_be) in &inputs { let got = render_markdown( @@ -762,13 +762,13 @@ more text with spaces fn add_playground_edition2018() { let inputs = [ ("```rust\nx()\n```", - "
fn main() {\nx()\n}\n
"), + "
fn main() {\nx()\n}\n
"), ("```rust\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("```rust edition2015\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("```rust edition2018\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ]; for (src, should_be) in &inputs { let got = render_markdown( @@ -788,13 +788,13 @@ more text with spaces fn add_playground_edition2021() { let inputs = [ ("```rust\nx()\n```", - "
fn main() {\nx()\n}\n
"), + "
fn main() {\nx()\n}\n
"), ("```rust\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("```rust edition2015\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ("```rust edition2018\nfn main() {}\n```", - "
fn main() {}\n
"), + "
fn main() {}\n
"), ]; for (src, should_be) in &inputs { let got = render_markdown( @@ -814,9 +814,9 @@ more text with spaces fn no_add_playground_to_other_languages() { let inputs = [ ("```html,testhtml\n

\n```", - "

<p>\n
"), + "
<p>\n
"), ("```js es7\nf()\n```", - "
f()\n
"), + "
f()\n
"), ]; for (src, should_be) in &inputs { let got = render_markdown(