Update option anchors to include group name (#4711)

This commit is contained in:
Julian LaNeve 2023-05-29 17:26:10 -04:00 committed by GitHub
parent 68db74b3c5
commit 6425fe8c12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -104,7 +104,7 @@ fn process_documentation(documentation: &str, out: &mut String) {
"unknown option {option}"
);
let anchor = option.rsplit('.').next().unwrap();
let anchor = option.replace('.', "-");
out.push_str(&format!("- [`{option}`][{option}]\n"));
after.push_str(&format!("[{option}]: ../../settings#{anchor}"));
@ -152,7 +152,7 @@ Something [`else`][other].
[other]: http://example.com.
[mccabe.max-complexity]: ../../settings#max-complexity\n"
[mccabe.max-complexity]: ../../settings#mccabe-max-complexity\n"
);
}
}

View file

@ -5,7 +5,18 @@ use ruff::settings::options::Options;
use ruff::settings::options_base::{OptionEntry, OptionField};
fn emit_field(output: &mut String, name: &str, field: &OptionField, group_name: Option<&str>) {
output.push_str(&format!("#### [`{name}`](#{name})\n"));
// if there's a group name, we need to add it to the anchor
if let Some(group_name) = group_name {
// the anchor used to just be the name, but now it's the group name
// for backwards compatibility, we need to keep the old anchor
output.push_str(&format!("<span id=\"{name}\"></span>\n"));
output.push_str(&format!(
"#### [`{name}`](#{group_name}-{name}) {{: #{group_name}-{name} }}\n"
));
} else {
output.push_str(&format!("#### [`{name}`](#{name})\n"));
}
output.push('\n');
output.push_str(field.doc);
output.push_str("\n\n");