feat: 新增 CSS 和 Rust 专业代码格式化器
集成 lightningcss 和 syn 库,为代码格式化工具添加 CSS 和 Rust 语言的专业格式化能力。同时重构 XML 格式化器,使用 roxmltree 和 quick-xml 替代纯函数实现,提升解析准确性和性能。
This commit is contained in:
@@ -62,6 +62,24 @@ fn prettify_code(input: &str, config: &CodeFormatConfig) -> Result<String, Strin
|
||||
};
|
||||
html_formatter::format_html(input, &html_config)
|
||||
}
|
||||
CodeLanguage::Css => {
|
||||
// CSS 使用专业格式化器
|
||||
use crate::utils::css_formatter;
|
||||
let css_config = crate::models::css_format::CssFormatConfig {
|
||||
indent: config.indent,
|
||||
mode: crate::models::code_format::FormatMode::Pretty,
|
||||
};
|
||||
css_formatter::format_css(input, &css_config)
|
||||
}
|
||||
CodeLanguage::Rust => {
|
||||
// Rust 使用专业格式化器
|
||||
use crate::utils::rust_formatter;
|
||||
let rust_config = crate::models::rust_format::RustFormatConfig {
|
||||
indent: config.indent,
|
||||
mode: crate::models::code_format::FormatMode::Pretty,
|
||||
};
|
||||
rust_formatter::format_rust(input, &rust_config)
|
||||
}
|
||||
_ => {
|
||||
// 其他语言使用通用格式化
|
||||
generic_prettify(input, config)
|
||||
@@ -97,6 +115,24 @@ fn compact_code(input: &str, config: &CodeFormatConfig) -> Result<String, String
|
||||
};
|
||||
html_formatter::format_html(input, &html_config)
|
||||
}
|
||||
CodeLanguage::Css => {
|
||||
// CSS 使用专业格式化器
|
||||
use crate::utils::css_formatter;
|
||||
let css_config = crate::models::css_format::CssFormatConfig {
|
||||
indent: 2,
|
||||
mode: crate::models::code_format::FormatMode::Compact,
|
||||
};
|
||||
css_formatter::format_css(input, &css_config)
|
||||
}
|
||||
CodeLanguage::Rust => {
|
||||
// Rust 使用专业格式化器
|
||||
use crate::utils::rust_formatter;
|
||||
let rust_config = crate::models::rust_format::RustFormatConfig {
|
||||
indent: 2,
|
||||
mode: crate::models::code_format::FormatMode::Compact,
|
||||
};
|
||||
rust_formatter::format_rust(input, &rust_config)
|
||||
}
|
||||
_ => {
|
||||
// 其他语言使用通用压缩
|
||||
generic_compact(input)
|
||||
|
||||
Reference in New Issue
Block a user