(feat) copy code content

Signed-off-by: Gato <cedric@goutailler-olivier.fr>
This commit is contained in:
2026-06-22 21:33:38 +02:00
parent 2d9a1e64f9
commit 8b0f128313
7 changed files with 3511 additions and 6 deletions
+1 -1
View File
@@ -17,5 +17,5 @@ tauri-plugin-dialog = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
comrak = { version = "0.28", features = ["syntect"] }
syntect = "5"
syntect = { version = "5", features = ["yaml-load"] }
notify = "7"
File diff suppressed because it is too large Load Diff
-2
View File
@@ -102,13 +102,11 @@ body {
.content pre:not(.syntax-highlighting) {
background: #0f172a;
border: 1px solid #1e293b;
border-radius: 10px;
}
/* Bloc de code avec coloration syntaxique */
.content .syntax-highlighting {
border: 1px solid #1e293b;
border-radius: 10px;
}
/* Texte dans un bloc sans coloration */
@@ -2,15 +2,30 @@ use comrak::plugins::syntect::SyntectAdapterBuilder;
use comrak::{markdown_to_html_with_plugins, Options, Plugins};
use syntect::highlighting::ThemeSet;
use syntect::html::{css_for_theme_with_class_style, ClassStyle};
use syntect::parsing::SyntaxDefinition;
use crate::domain::MarkdownRenderer;
const TYPESCRIPT_SYNTAX: &str =
include_str!("../../resources/syntaxes/TypeScript.sublime-syntax");
fn build_syntax_set() -> syntect::parsing::SyntaxSet {
let mut builder = syntect::parsing::SyntaxSet::load_defaults_nonewlines().into_builder();
if let Ok(def) = SyntaxDefinition::load_from_str(TYPESCRIPT_SYNTAX, true, None) {
builder.add(def);
}
builder.build()
}
pub struct ComrakRenderer;
pub struct ComrakPreviewRenderer;
impl MarkdownRenderer for ComrakRenderer {
fn render(&self, content: &str) -> String {
let adapter = SyntectAdapterBuilder::new().css().build();
let adapter = SyntectAdapterBuilder::new()
.syntax_set(build_syntax_set())
.css()
.build();
let mut options = Options::default();
options.extension.table = true;
options.extension.strikethrough = true;
@@ -24,7 +39,10 @@ impl MarkdownRenderer for ComrakRenderer {
impl MarkdownRenderer for ComrakPreviewRenderer {
fn render(&self, content: &str) -> String {
let adapter = SyntectAdapterBuilder::new().css().build();
let adapter = SyntectAdapterBuilder::new()
.syntax_set(build_syntax_set())
.css()
.build();
let options = Options::default();
let mut plugins = Plugins::default();
plugins.render.codefence_syntax_highlighter = Some(&adapter);
@@ -62,6 +80,13 @@ mod tests {
assert!(html.contains("<span class="));
}
#[test]
fn typescript_syntax_is_highlighted() {
let r = ComrakRenderer;
let html = r.render("```typescript\ninterface Foo { id: string; }\n```\n");
assert!(html.contains("<span class="), "TypeScript should produce highlighted spans");
}
#[test]
fn syntax_css_known_theme_contains_wrapper() {
let css = syntax_css_for_theme("base16-ocean.dark");
@@ -80,5 +105,4 @@ mod tests {
let css = syntax_css_for_theme("nonexistent-theme-xyz");
assert!(css.is_empty());
}
}