From ca7bdfe053c8824841927529292761db9c616c04 Mon Sep 17 00:00:00 2001
From: thek4n
Date: Mon, 13 Jul 2026 19:44:44 +0300
Subject: [PATCH] fix(copy-button): fix copy code button
---
TODO.md | 1 +
src/main.rs | 18 +++---------------
src/markdown.rs | 36 ++++++++++++++++++++++++++++++------
templates/base.html | 1 +
4 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/TODO.md b/TODO.md
index fa56e1b..568cd28 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,3 +2,4 @@
* [X] ~~Сделать кнопку скопировать путь~~
* [X] ~~Сделать кнопку скопировать путь вместе с командой (`note edit ...`)~~
+* [X] ~~Сделать отображение типа кода и кнопку скопировать код~~
diff --git a/src/main.rs b/src/main.rs
index a411824..afa45ef 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -185,9 +185,7 @@ async fn root_handler(State(state): State) -> impl IntoResponse {
}
}
-async fn render_single_file(
- file_path: &StdPath,
-) -> Result {
+async fn render_single_file(file_path: &StdPath) -> Result {
let metadata = match fs::metadata(file_path).await {
Ok(m) => m,
Err(_) => return Err(StatusCode::NOT_FOUND),
@@ -216,12 +214,7 @@ async fn render_single_file(
let html_content = if extension == "md" {
markdown_to_html(&content, display_path)
} else {
- code_to_html(
- &content,
- extension.as_str(),
- &ss,
- &ts,
- )
+ code_to_html(&content, extension.as_str(), &ss, &ts)
};
let filename = file_path
@@ -318,12 +311,7 @@ async fn serve_file(
let html_content = if extension == "md" {
markdown_to_html(&content, &full_path)
} else {
- code_to_html(
- &content,
- extension.as_str(),
- &ss,
- &ts,
- )
+ code_to_html(&content, extension.as_str(), &ss, &ts)
};
let filename = safe_path
diff --git a/src/markdown.rs b/src/markdown.rs
index d5a2f31..aef0efc 100644
--- a/src/markdown.rs
+++ b/src/markdown.rs
@@ -137,7 +137,7 @@ fn render_end_tag(tag: TagEnd) -> String {
TagEnd::List(false) => output.push_str(""),
TagEnd::Item => output.push_str(""),
TagEnd::Paragraph => output.push_str("
"),
- TagEnd::CodeBlock => output.push_str(""),
+ TagEnd::CodeBlock => output.push_str(""),
TagEnd::Emphasis => output.push_str(""),
TagEnd::Strong => output.push_str(""),
TagEnd::BlockQuote(_) => output.push_str(""),
@@ -164,16 +164,40 @@ fn render_end_tag(tag: TagEnd) -> String {
}
fn render_codeblock(block_kind: CodeBlockKind<'_>) -> String {
+ let header = String::from(
+ r#"
+
+
+
"#,
+ );
+
+ let mut output = String::new();
+
match block_kind {
- CodeBlockKind::Indented => "".to_string(),
+ CodeBlockKind::Indented => {
+ output.push_str(&header.replace("%CODE%", "code"));
+ output.push_str("");
+ }
+
CodeBlockKind::Fenced(CowStr::Borrowed("mermaid")) => {
- "".to_string()
+ output.push_str(&header.replace("%CODE%", "mermaid"));
+ output.push_str("");
}
+
CodeBlockKind::Fenced(CowStr::Borrowed("rawmermaid")) => {
- "".to_string()
+ output.push_str(&header.replace("%CODE%", "mermaid"));
+ output.push_str("");
}
- CodeBlockKind::Fenced(code_type) => format!("", code_type),
- }
+
+ CodeBlockKind::Fenced(code_type) => {
+ output.push_str(&header.replace("%CODE%", &code_type));
+ output.push_str(format!("", code_type).as_str());
+ }
+ };
+
+ output
}
fn render_blockquote(quote_kind: Option) -> String {
diff --git a/templates/base.html b/templates/base.html
index 159ad38..cead784 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -55,6 +55,7 @@
overflow: hidden;
background-color: #2b303b;
}
+
.code-header {
display: flex;
justify-content: space-between;