Skip to content

Commit

Permalink
Format code with rustfmt and compile SCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 10, 2024
1 parent bb259f2 commit 7bf2337
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
17 changes: 11 additions & 6 deletions src/code_block/highlight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use pulldown_cmark::{CodeBlockKind, Event, Parser, Tag};
use pulldown_cmark::{
CodeBlockKind,
Event,
Parser,
Tag,
};

pub fn highlight_code(code: &str, language: &str) -> String {
let mut highlighted = String::new();
Expand All @@ -11,23 +16,23 @@ pub fn highlight_code(code: &str, language: &str) -> String {
highlighted.push_str("<pre><code class=\"language-");
highlighted.push_str(&lang);
highlighted.push_str("\">");
},
}
Event::End(pulldown_cmark::TagEnd::CodeBlock) => {
highlighted.push_str("</code></pre>");
},
}
Event::Text(text) => {
// Basic syntax highlighting (you may want to expand this)
let highlighted_text = text
.replace('&', "&amp;")
.replace('<', "&lt;")
.replace('>', "&gt;")
.replace('"',"&quot;")
.replace('"', "&quot;")
.replace('\'', "&#39;");
highlighted.push_str(&highlighted_text);
},
}
_ => {}
}
}

highlighted
}
}
12 changes: 8 additions & 4 deletions src/code_block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub mod highlight;

use crate::{
spacing::Padding,
Toast,
use_toast,
Button,
Toast,
ToastType,
Button
};

#[derive(Clone, PartialEq, Properties)]
Expand All @@ -33,14 +33,18 @@ pub fn code_block(props: &CodeBlockProps) -> Html {
let code = props.snippet.clone();
Callback::from(move |_| {
let code = code.clone();

let window = web_sys::window().expect("window");
let nav = window.navigator().clipboard();

match nav {
Some(a) => {
let _ = a.write_text(code.as_str());
toasts_manager.spawn(Toast::new(ToastType::Info, "Clipboard", "Code successfully copied to clipboard"));
toasts_manager.spawn(Toast::new(
ToastType::Info,
"Clipboard",
"Code successfully copied to clipboard",
));
}
None => {
toasts_manager.spawn(Toast::new(ToastType::Error, "Clipboard", "Unable to copy code to clipboard"));
Expand Down
28 changes: 22 additions & 6 deletions style/dist/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion style/dist/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bf2337

Please sign in to comment.