新增三个格式化工具(HTML/XML/代码),支持美化和压缩模式。 修复 XML 验证器无法正确解析带属性标签的问题。 修复代码中未使用变量的警告,优化 HTML script/style 标签处理逻辑。
29 lines
926 B
Rust
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,
|
|
})
|
|
}
|