Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: Prevent fully defined links [name](link) from being reformatted #10442

Merged
merged 1 commit into from Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions crates/ruff_dev/src/generate_docs.rs
Expand Up @@ -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("## ") {
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down