mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #4569 from piotrkwiecinski/uucore_help_section
uucore: fix help section doesn't render 3+ level headers
This commit is contained in:
commit
57541db124
1 changed files with 29 additions and 1 deletions
|
@ -170,11 +170,14 @@ fn parse_help_section(section: &str, content: &str) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefix includes space to allow processing of section with level 3-6 headers
|
||||||
|
let section_header_prefix = "## ";
|
||||||
|
|
||||||
content
|
content
|
||||||
.lines()
|
.lines()
|
||||||
.skip_while(|&l| !is_section_header(l, section))
|
.skip_while(|&l| !is_section_header(l, section))
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.take_while(|l| !l.starts_with("##"))
|
.take_while(|l| !l.starts_with(section_header_prefix))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
.trim()
|
.trim()
|
||||||
|
@ -252,6 +255,31 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn section_parsing_with_additional_headers() {
|
||||||
|
let input = "\
|
||||||
|
# ls\n\
|
||||||
|
## after section\n\
|
||||||
|
This is some section\n\
|
||||||
|
\n\
|
||||||
|
### level 3 header\n\
|
||||||
|
\n\
|
||||||
|
Additional text under the section.\n\
|
||||||
|
\n\
|
||||||
|
#### level 4 header\n\
|
||||||
|
\n\
|
||||||
|
Yet another paragraph\n";
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
parse_help_section("after section", input),
|
||||||
|
"This is some section\n\n\
|
||||||
|
### level 3 header\n\n\
|
||||||
|
Additional text under the section.\n\n\
|
||||||
|
#### level 4 header\n\n\
|
||||||
|
Yet another paragraph"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn section_parsing_panic() {
|
fn section_parsing_panic() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue