From 06a04c10e2bed94a3427e58d07324c4e5d0ca6d5 Mon Sep 17 00:00:00 2001 From: eggplants Date: Fri, 14 Jul 2023 02:25:54 +0900 Subject: [PATCH] Fix `Options` section of rule docs (#5741) ## Summary Fix: #5740 A trailing line-break are needed for the anchor. ## Test Plan http://127.0.0.1:8000/docs/rules/line-too-long/#options |before|after| |--|--| |![image](https://github.com/astral-sh/ruff/assets/42153744/8cb9dcce-aeda-4255-b21e-ab11817ba9e1)|![image](https://github.com/astral-sh/ruff/assets/42153744/b68d4fd7-da5a-4494-bb95-f7792f1a42db)| --- crates/ruff_dev/src/generate_docs.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index 864b030ad4..93caebddcd 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -81,7 +81,7 @@ fn process_documentation(documentation: &str, out: &mut String) { // a non-CommonMark-compliant Markdown parser, which doesn't support code // tags in link definitions // (see https://github.com/Python-Markdown/markdown/issues/280). - let documentation = Regex::new(r"\[`(.*?)`\]($|[^\[])").unwrap().replace_all( + let documentation = Regex::new(r"\[`(.*?)`]($|[^\[])").unwrap().replace_all( documentation, |caps: &Captures| { format!( @@ -106,7 +106,7 @@ fn process_documentation(documentation: &str, out: &mut String) { let anchor = option.replace('.', "-"); out.push_str(&format!("- [`{option}`][{option}]\n")); - after.push_str(&format!("[{option}]: ../../settings#{anchor}")); + after.push_str(&format!("[{option}]: ../../settings#{anchor}\n")); continue; } @@ -115,10 +115,10 @@ fn process_documentation(documentation: &str, out: &mut String) { out.push_str(line); } if !after.is_empty() { - out.push_str("\n\n"); + out.push('\n'); + out.push('\n'); out.push_str(&after); } - out.push('\n'); } #[cfg(test)] @@ -130,11 +130,12 @@ mod tests { let mut output = String::new(); process_documentation( " -See also [`mccabe.max-complexity`]. +See also [`mccabe.max-complexity`] and [`task-tags`]. Something [`else`][other]. ## Options +- `task-tags` - `mccabe.max-complexity` [other]: http://example.com.", @@ -143,16 +144,19 @@ Something [`else`][other]. assert_eq!( output, " -See also [`mccabe.max-complexity`][mccabe.max-complexity]. +See also [`mccabe.max-complexity`][mccabe.max-complexity] and [`task-tags`][task-tags]. Something [`else`][other]. ## Options +- [`task-tags`][task-tags] - [`mccabe.max-complexity`][mccabe.max-complexity] [other]: http://example.com. -[mccabe.max-complexity]: ../../settings#mccabe-max-complexity\n" +[task-tags]: ../../settings#task-tags +[mccabe.max-complexity]: ../../settings#mccabe-max-complexity +" ); } }