From de0a6ec856b049ad137c88da10f095c1ef1fda37 Mon Sep 17 00:00:00 2001 From: augustelalande Date: Sun, 17 Mar 2024 19:34:06 -0400 Subject: [PATCH] prevent fully defineds links [...](...) from being reformatted --- crates/ruff_dev/src/generate_docs.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index 309a61a459fcb..2c3f24975a2a8 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -102,16 +102,15 @@ fn process_documentation(documentation: &str, out: &mut String, rule_name: &str) // 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( - documentation, - |caps: &Captures| { + let documentation = Regex::new(r"\[`([^`]*?)`]($|[^\[\(])") + .unwrap() + .replace_all(documentation, |caps: &Captures| { format!( "[`{option}`][{option}]{sep}", option = &caps[1], sep = &caps[2] ) - }, - ); + }); for line in documentation.split_inclusive('\n') { if line.starts_with("## ") { @@ -159,7 +158,7 @@ mod tests { process_documentation( " See also [`lint.mccabe.max-complexity`] and [`lint.task-tags`]. -Something [`else`][other]. +Something [`else`][other]. Some [link](https://example.com). ## Options @@ -174,7 +173,7 @@ Something [`else`][other]. output, " See also [`lint.mccabe.max-complexity`][lint.mccabe.max-complexity] and [`lint.task-tags`][lint.task-tags]. -Something [`else`][other]. +Something [`else`][other]. Some [link](https://example.com). ## Options