Files
tauri-shadcn-vite-project/src-tauri/src/commands/code_format_commands.rs
shenjianZ bf5d056811 feat: 添加 HTML、XML 和多语言代码格式化功能
新增三个格式化工具(HTML/XML/代码),支持美化和压缩模式。
  修复 XML 验证器无法正确解析带属性标签的问题。
  修复代码中未使用变量的警告,优化 HTML script/style 标签处理逻辑。
2026-02-10 20:24:21 +08:00

29 lines
926 B
Rust

//! 代码格式化命令
//!
//! 定义代码格式化相关的 Tauri 命令
use crate::models::code_format::{CodeFormatConfig, CodeFormatResult, CodeValidateResult, CodeLanguage};
use crate::services::code_format_service::CodeFormatService;
/// 格式化代码命令
#[tauri::command]
pub fn format_code(input: String, config: CodeFormatConfig) -> CodeFormatResult {
CodeFormatService::format(&input, &config)
.unwrap_or_else(|e| CodeFormatResult {
success: false,
result: String::new(),
error: Some(e.to_string()),
})
}
/// 验证代码命令
#[tauri::command]
pub fn validate_code(input: String, language: CodeLanguage) -> CodeValidateResult {
CodeFormatService::validate(&input, language)
.unwrap_or_else(|e| CodeValidateResult {
is_valid: false,
error_message: Some(e.to_string()),
error_line: None,
})
}