mirror of
https://github.com/denoland/deno.git
synced 2024-12-18 05:14:21 -05:00
fix(fmt): stable formatting of HTML files with JS (#27164)
Closes https://github.com/denoland/deno/issues/26407 Closes https://github.com/denoland/deno/issues/26763 Closes https://github.com/denoland/deno/issues/26560 Closes https://github.com/denoland/deno/issues/26744 Closes https://github.com/denoland/deno/issues/27030
This commit is contained in:
parent
76571fd5a5
commit
53936eda11
5 changed files with 30 additions and 8 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -4682,9 +4682,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "markup_fmt"
|
||||
version = "0.16.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f303c36143671ac6c54112eb5aa95649b169dae783fdb6ead2c0e88b408c425c"
|
||||
checksum = "fa7605bb4ad755a9ab5c96f2ce3bfd4eb8acd559b842c041fc8a5f84d63aed3a"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"css_dataset",
|
||||
|
|
|
@ -130,7 +130,7 @@ libz-sys.workspace = true
|
|||
log = { workspace = true, features = ["serde"] }
|
||||
lsp-types.workspace = true
|
||||
malva = "=0.11.0"
|
||||
markup_fmt = "=0.16.0"
|
||||
markup_fmt = "=0.18.0"
|
||||
memmem.workspace = true
|
||||
monch.workspace = true
|
||||
notify.workspace = true
|
||||
|
|
|
@ -440,8 +440,10 @@ pub fn format_html(
|
|||
)
|
||||
}
|
||||
_ => {
|
||||
let mut typescript_config =
|
||||
get_resolved_typescript_config(fmt_options);
|
||||
let mut typescript_config_builder =
|
||||
get_typescript_config_builder(fmt_options);
|
||||
typescript_config_builder.file_indent_level(hints.indent_level);
|
||||
let mut typescript_config = typescript_config_builder.build();
|
||||
typescript_config.line_width = hints.print_width as u32;
|
||||
dprint_plugin_typescript::format_text(
|
||||
&path,
|
||||
|
@ -919,9 +921,9 @@ fn files_str(len: usize) -> &'static str {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_resolved_typescript_config(
|
||||
fn get_typescript_config_builder(
|
||||
options: &FmtOptionsConfig,
|
||||
) -> dprint_plugin_typescript::configuration::Configuration {
|
||||
) -> dprint_plugin_typescript::configuration::ConfigurationBuilder {
|
||||
let mut builder =
|
||||
dprint_plugin_typescript::configuration::ConfigurationBuilder::new();
|
||||
builder.deno();
|
||||
|
@ -953,7 +955,13 @@ fn get_resolved_typescript_config(
|
|||
});
|
||||
}
|
||||
|
||||
builder.build()
|
||||
builder
|
||||
}
|
||||
|
||||
fn get_resolved_typescript_config(
|
||||
options: &FmtOptionsConfig,
|
||||
) -> dprint_plugin_typescript::configuration::Configuration {
|
||||
get_typescript_config_builder(options).build()
|
||||
}
|
||||
|
||||
fn get_resolved_markdown_config(
|
||||
|
@ -1075,6 +1083,7 @@ fn get_resolved_markup_fmt_config(
|
|||
};
|
||||
|
||||
let language_options = LanguageOptions {
|
||||
script_formatter: Some(markup_fmt::config::ScriptFormatter::Dprint),
|
||||
quotes: Quotes::Double,
|
||||
format_comments: false,
|
||||
script_indent: true,
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
"broken": {
|
||||
"args": "fmt broken.html",
|
||||
"output": "broken.out"
|
||||
},
|
||||
"with_js": {
|
||||
"args": "fmt --check with_js.html",
|
||||
"output": "Checked 1 file\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
9
tests/specs/fmt/html/with_js.html
Normal file
9
tests/specs/fmt/html/with_js.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<body>
|
||||
<script>
|
||||
/* some multi-line comment
|
||||
with function below it */
|
||||
someFunc();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue