Supply metadata.content_type for to html output (#14990)

# Description

Adds pipeline metadata to the `to html` command output (hardcoded to
`text/html; charset=utf-8`)

# User-Facing Changes

Pipeline metadata is now included with the `to html` command output.
This commit is contained in:
Bruce Weirdan 2025-02-03 13:32:57 +01:00 committed by GitHub
parent 8b431e3a2e
commit 4424481487
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 2 deletions

1
Cargo.lock generated
View File

@ -3542,6 +3542,7 @@ dependencies = [
"fancy-regex",
"heck",
"itertools 0.13.0",
"mime",
"nu-ansi-term",
"nu-cmd-base",
"nu-cmd-lang",

View File

@ -34,8 +34,9 @@ serde = { workspace = true }
serde_urlencoded = { workspace = true }
v_htmlescape = { workspace = true }
itertools = { workspace = true }
mime = { workspace = true }
[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.101.1" }
nu-command = { path = "../nu-command", version = "0.101.1" }
nu-test-support = { path = "../nu-test-support", version = "0.101.1" }
nu-test-support = { path = "../nu-test-support", version = "0.101.1" }

View File

@ -330,7 +330,12 @@ fn to_html(
output_string = run_regexes(&regex_hm, &output_string);
}
Ok(Value::string(output_string, head).into_pipeline_data())
let metadata = PipelineMetadata {
data_source: nu_protocol::DataSource::None,
content_type: Some(mime::TEXT_HTML_UTF_8.to_string()),
};
Ok(Value::string(output_string, head).into_pipeline_data_with_metadata(metadata))
}
fn theme_demo(span: Span) -> PipelineData {

View File

@ -14,6 +14,15 @@ fn out_html_simple() {
);
}
#[test]
fn out_html_metadata() {
let actual = nu!(r#"
echo 3 | to html | metadata | get content_type
"#);
assert_eq!(actual.out, r#"text/html; charset=utf-8"#);
}
#[test]
fn out_html_partial() {
let actual = nu!(r#"