fix: enclose fallback docs in code block (#828)

This commit is contained in:
Myriad-Dreamin 2024-11-15 20:59:26 +08:00 committed by GitHub
parent 52a8d0e678
commit 5ce0a8feba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 7 deletions

View file

@ -162,7 +162,20 @@ impl<'a> DocsChecker<'a> {
Ok(c) => Ok(c),
Err(e) => {
let e = e.replace("`", "\\`");
let fallback_docs = eco_format!("```\nfailed to parse docs: {e}\n```\n\n{docs}");
let max_consecutive_backticks = docs
.chars()
.fold((0, 0), |(max, count), c| {
if c == '`' {
(max.max(count + 1), count + 1)
} else {
(max, 0)
}
})
.0;
let backticks = "`".repeat((max_consecutive_backticks + 1).max(3));
let fallback_docs = eco_format!(
"```\nfailed to parse docs: {e}\n```\n\n{backticks}typ\n{docs}\n{backticks}\n"
);
Err(DocString {
docs: Some(fallback_docs),
var_bounds: HashMap::new(),