Skip to content

Commit

Permalink
generate-copyright: Update HTML format
Browse files Browse the repository at this point in the history
The h3 containing the <a> tag didn't work, format wise. Also tried to harmonise the out-of-tree metadata formatting with the in-tree metadata formatting.
  • Loading branch information
jonathanpallant committed Jul 15, 2024
1 parent cf04752 commit 1cb8150
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/tools/generate-copyright/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,38 @@ fn render_deps<'a, 'b>(
license_set: &mut BTreeSet<String>,
) -> Result<(), Error> {
for dep in deps {
let authors_list = dep.authors.join(", ");
let authors_list = if dep.authors.is_empty() {
"None Specified".to_owned()
} else {
dep.authors.join(", ")
};
let url = format!("https://crates.io/crates/{}/{}", dep.name, dep.version);
writeln!(buffer)?;
writeln!(
buffer,
r#"<h3><a href="{url}">{name} {version}</a></h3>"#,
r#"<h3>📦 {name}-{version}</h3>"#,
name = dep.name,
version = dep.version,
url = url,
)?;
writeln!(buffer, "<h4>Authors</h4><p>{}</p>", escape_html(&authors_list))?;
writeln!(buffer, "<h4>License</h4><p>{}</p>", escape_html(&dep.license))?;
writeln!(buffer, r#"<p><b>URL:</b> <a href="{url}">{url}</a></p>"#,)?;
writeln!(buffer, "<p><b>Authors:</b> {}</p>", escape_html(&authors_list))?;
writeln!(buffer, "<p><b>License:</b> {}</p>", escape_html(&dep.license))?;
license_set.insert(dep.license.clone());
for (name, contents) in &dep.notices {
writeln!(buffer)?;
writeln!(buffer, "<h4>{}</h3>", name.to_string_lossy())?;
writeln!(buffer)?;
writeln!(buffer, "<details><summary>Click to expand</summary>")?;
writeln!(buffer, "<pre>\n{}\n</pre>", contents)?;
writeln!(buffer, "</details>")?;
writeln!(buffer, "<p><b>Notices:</b> ")?;
if dep.notices.is_empty() {
writeln!(buffer, "None")?;
} else {
for (name, contents) in &dep.notices {
writeln!(
buffer,
"<details><summary><code>{}</code></summary>",
name.to_string_lossy()
)?;
writeln!(buffer, "<pre>\n{}\n</pre>", contents)?;
writeln!(buffer, "</details>")?;
}
}
writeln!(buffer, "</p>")?;
}
Ok(())
}
Expand Down

0 comments on commit 1cb8150

Please sign in to comment.