feat: coloration syntaxique via CSS classes (themeable)
Remplace les styles inline syntect par des classes CSS. Le CSS est généré côté Rust (base16-ocean.dark) et injecté au démarrage via get_syntax_highlight_css. Les thèmes peuvent surcharger .syntax-highlighting et les classes de tokens. Supprime le lien CDN highlight.js inutilisé. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
use crate::application::{file_service, render_service};
|
||||
use crate::infrastructure::comrak_renderer::{ComrakPreviewRenderer, ComrakRenderer};
|
||||
use crate::infrastructure::comrak_renderer::{
|
||||
syntax_css_for_theme, ComrakPreviewRenderer, ComrakRenderer,
|
||||
};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn render_markdown(content: String) -> String {
|
||||
let renderer = ComrakPreviewRenderer {
|
||||
theme: "base16-ocean.dark".to_string(),
|
||||
};
|
||||
let renderer = ComrakPreviewRenderer;
|
||||
render_service::render_string(&renderer, &content)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn convert_file(path: String) -> Result<String, String> {
|
||||
let renderer = ComrakRenderer {
|
||||
theme: "InspiredGitHub".to_string(),
|
||||
};
|
||||
let renderer = ComrakRenderer;
|
||||
render_service::render_file(&renderer, &path)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_syntax_highlight_css() -> String {
|
||||
syntax_css_for_theme("base16-ocean.dark")
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn list_md_files(dir: String) -> Result<Vec<String>, String> {
|
||||
file_service::list_markdown_files(&dir)
|
||||
@@ -41,7 +44,7 @@ mod tests {
|
||||
#[test]
|
||||
fn render_markdown_code_block() {
|
||||
let html = render_markdown("```rust\nfn main() {}\n```\n".to_string());
|
||||
assert!(html.contains("<code") || html.contains("<pre>"));
|
||||
assert!(html.contains("syntax-highlighting"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -80,6 +83,18 @@ mod tests {
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_syntax_highlight_css_returns_non_empty() {
|
||||
let css = get_syntax_highlight_css();
|
||||
assert!(!css.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_syntax_highlight_css_contains_wrapper_class() {
|
||||
let css = get_syntax_highlight_css();
|
||||
assert!(css.contains(".syntax-highlighting {"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_md_files_sorted() {
|
||||
let dir = tmpdir("pena_list_sorted");
|
||||
|
||||
Reference in New Issue
Block a user