Skip to content

Commit fd259c9

Browse files
committed
Allow subsections
1 parent 25287ac commit fd259c9

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

‎src/tools/target-docs/src/parse.rs‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,21 @@ fn parse_file(full_path: PathBuf, file_name: &str, content: &str) -> Result<Pars
100100
if line.starts_with("```") {
101101
in_codeblock ^= true; // toggle
102102
push_line(&mut sections, line)?;
103-
} else if line.starts_with('#') {
104-
if in_codeblock {
105-
push_line(&mut sections, line)?;
106-
} else if let Some(header) = line.strip_prefix("## ") {
107-
if crate::SECTIONS.iter().any(|s| s.name == header) {
108-
sections.push((header.to_owned(), String::new()));
109-
} else {
110-
bail!(
111-
"on line {number}, `{header}` is not an allowed section name, must be one of {}",
112-
fmt::from_fn(|f| f
113-
.debug_list()
114-
.entries(super::SECTIONS.iter().map(|s| s.name))
115-
.finish())
116-
);
117-
}
103+
} else if in_codeblock {
104+
push_line(&mut sections, line)?;
105+
} else if line.starts_with("# ") {
106+
bail!("on line {number}, first-level headings are not allowed: `{line}`");
107+
} else if let Some(header) = line.strip_prefix("## ") {
108+
if crate::SECTIONS.iter().any(|s| s.name == header) {
109+
sections.push((header.to_owned(), String::new()));
118110
} else {
119-
bail!("on line {number}, the only allowed headings are `## `: `{line}`");
111+
bail!(
112+
"on line {number}, `{header}` is not an allowed section name, must be one of {}",
113+
fmt::from_fn(|f| f
114+
.debug_list()
115+
.entries(super::SECTIONS.iter().map(|s| s.name))
116+
.finish())
117+
);
120118
}
121119
} else {
122120
push_line(&mut sections, line)?;

‎src/tools/target-docs/src/parse/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pattern: \"x86_64-known-linux-gnu\"
4646
";
4747

4848
assert_is_err_contains(
49-
"the only allowed headings are `## `",
49+
"first-level headings are not allowed",
5050
super::parse_file(PathBuf::from(name), name, content),
5151
);
5252
}

0 commit comments

Comments
 (0)