feat: 添加 HTML、XML 和多语言代码格式化功能
新增三个格式化工具(HTML/XML/代码),支持美化和压缩模式。 修复 XML 验证器无法正确解析带属性标签的问题。 修复代码中未使用变量的警告,优化 HTML script/style 标签处理逻辑。
This commit is contained in:
28
src-tauri/src/commands/code_format_commands.rs
Normal file
28
src-tauri/src/commands/code_format_commands.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
//! 代码格式化命令
|
||||
//!
|
||||
//! 定义代码格式化相关的 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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user