From 5855d9bcb0b07f49f049c38ba3ea346006085b40 Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 26 Mar 2024 17:23:59 +0100 Subject: [PATCH] fix(macros/config/file_tree/markdown): Change format to align with mdfmt To ensure, that `mdfmt` does not reformat our `expected.md` files. --- .../file_tree/markdown_representation.rs | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/macros/config/file_tree/markdown_representation.rs b/src/macros/config/file_tree/markdown_representation.rs index aaa4fe4..916aba6 100644 --- a/src/macros/config/file_tree/markdown_representation.rs +++ b/src/macros/config/file_tree/markdown_representation.rs @@ -51,28 +51,47 @@ impl Display for Language { impl Display for GeneratedFile { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("File path: `{}`\n", self.path.display()))?; + f.write_fmt(format_args!("File path: `{}`\n\n", self.path.display()))?; f.write_fmt(format_args!("```{}\n", self.language))?; f.write_fmt(format_args!("{}", &self.value))?; - f.write_str("```\n\n") + f.write_str("```") } } impl Display for FileTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut first = true; if !self.host_files.is_empty() { - f.write_str("# Host files\n")?; + f.write_str("# Host files\n\n")?; self.host_files .iter() - .map(|file| -> std::fmt::Result { f.write_str(&file.to_string()) }) + .map(|file| -> std::fmt::Result { + if !first { + f.write_str("\n\n")?; + } else { + first = false; + } + f.write_str(&file.to_string()) + }) .collect::()?; } + first = true; if !self.auxiliary_files.is_empty() { - f.write_str("# Auxiliary files\n")?; + if !self.host_files.is_empty() { + f.write_str("\n\n")?; + } + f.write_str("# Auxiliary files\n\n")?; self.auxiliary_files .iter() - .map(|file| -> std::fmt::Result { f.write_str(&file.to_string()) }) + .map(|file| -> std::fmt::Result { + if !first { + f.write_str("\n\n")?; + } else { + first = false; + } + f.write_str(&file.to_string()) + }) .collect::()?; } Ok(())