Skip to content

Commit 730b0a6

Browse files
authored
style(uudoc): update header formatting for options and examples (#10004)
Adjust the formatting of the options and examples sections in the uudoc output to use Markdown headers: - Change `<h2>Options</h2>` to `## Options` - Change `Examples` to `## Examples` - Add regression test to prevent reverting to HTML headers
1 parent 49466a3 commit 730b0a6

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/bin/uudoc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ impl MDWriter<'_, '_> {
465465
/// # Errors
466466
/// Returns an error if the writer fails.
467467
fn options(&mut self) -> io::Result<()> {
468-
writeln!(self.w, "<h2>Options</h2>")?;
468+
writeln!(self.w)?;
469+
writeln!(self.w, "## Options")?;
470+
writeln!(self.w)?;
469471
write!(self.w, "<dl>")?;
470472
for arg in self.command.get_arguments() {
471473
write!(self.w, "<dt>")?;
@@ -576,7 +578,7 @@ fn format_examples(content: String, output_markdown: bool) -> Result<String, std
576578
use std::fmt::Write;
577579
let mut s = String::new();
578580
writeln!(s)?;
579-
writeln!(s, "Examples")?;
581+
writeln!(s, "## Examples")?;
580582
writeln!(s)?;
581583
for line in content.lines().skip_while(|l| !l.starts_with('-')) {
582584
if let Some(l) = line.strip_prefix("- ") {

tests/uudoc/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,39 @@ fn test_manpage_base64() {
132132
assert!(output_str.contains("base64 alphabet"));
133133
assert!(!output_str.to_ascii_lowercase().contains("base32"));
134134
}
135+
136+
// Test to ensure markdown headers are correctly formatted in generated markdown files
137+
// Prevents regression of https://github.com/uutils/coreutils/issues/10003
138+
#[test]
139+
fn test_markdown_header_format() {
140+
use std::fs;
141+
142+
// Read a sample markdown file from the documentation
143+
// This assumes the docs have been generated (they should be in the repo)
144+
let docs_path = "docs/src/utils/cat.md";
145+
146+
if fs::metadata(docs_path).is_ok() {
147+
let content =
148+
fs::read_to_string(docs_path).expect("Failed to read generated markdown file");
149+
150+
// Verify Options header is in markdown format (## Options)
151+
assert!(
152+
content.contains("## Options"),
153+
"Generated markdown should contain '## Options' header"
154+
);
155+
156+
// Verify no HTML h2 tags for Options (old format)
157+
assert!(
158+
!content.contains("<h2>Options</h2>"),
159+
"Generated markdown should not contain '<h2>Options</h2>' (use markdown format instead)"
160+
);
161+
162+
// Also verify Examples if it exists
163+
if content.contains("## Examples") {
164+
assert!(
165+
content.contains("## Examples"),
166+
"Generated markdown should contain '## Examples' header in markdown format"
167+
);
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)