From 2f0ba7787299b474bb5c15aeb5ccdc0a31257970 Mon Sep 17 00:00:00 2001 From: Piotr Kwiecinski Date: Tue, 21 Mar 2023 19:09:12 +0100 Subject: [PATCH 1/3] uucore: fix help section doesn't render 3+ level headers --- src/uucore_procs/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index c1ef8bc75..0d8df7d9f 100644 --- a/src/uucore_procs/src/lib.rs +++ b/src/uucore_procs/src/lib.rs @@ -174,7 +174,7 @@ fn parse_help_section(section: &str, content: &str) -> String { .lines() .skip_while(|&l| !is_section_header(l, section)) .skip(1) - .take_while(|l| !l.starts_with("##")) + .take_while(|l| !l.starts_with("## ")) .collect::>() .join("\n") .trim() From 3b54421e9c86d0d492ce8b532ade3a38d6260ae2 Mon Sep 17 00:00:00 2001 From: Piotr Kwiecinski Date: Tue, 21 Mar 2023 20:42:45 +0100 Subject: [PATCH 2/3] uucore: add comment to parse_help_section --- src/uucore_procs/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index 0d8df7d9f..73054f9c4 100644 --- a/src/uucore_procs/src/lib.rs +++ b/src/uucore_procs/src/lib.rs @@ -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 .lines() .skip_while(|&l| !is_section_header(l, section)) .skip(1) - .take_while(|l| !l.starts_with("## ")) + .take_while(|l| !l.starts_with(section_header_prefix)) .collect::>() .join("\n") .trim() From 154370a0c62dac4848957b1d2345a8a3878c87e2 Mon Sep 17 00:00:00 2001 From: Piotr Kwiecinski Date: Wed, 22 Mar 2023 16:57:41 +0100 Subject: [PATCH 3/3] uucore: parse_help_section test section with multiple header --- src/uucore_procs/src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index 73054f9c4..ab2458ceb 100644 --- a/src/uucore_procs/src/lib.rs +++ b/src/uucore_procs/src/lib.rs @@ -255,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] #[should_panic] fn section_parsing_panic() {