Fix tools' ui_text to use inline code escaping (#27543)

Markdown escaping was added in #27502.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-03-26 15:49:51 -06:00 committed by GitHub
parent 2b5095ac91
commit 44aff7cd46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 34 additions and 24 deletions

View file

@ -11,7 +11,9 @@ impl Display for MarkdownString {
}
impl MarkdownString {
/// Escapes markdown special characters.
/// Escapes markdown special characters in markdown text blocks. Markdown code blocks follow
/// different rules and `MarkdownString::inline_code` or `MarkdownString::code_block` should be
/// used in that case.
///
/// Also escapes the following markdown extensions:
///
@ -134,6 +136,12 @@ impl MarkdownString {
Self(format!("{backticks}{space}{text}{space}{backticks}"))
}
}
/// Returns markdown for code blocks, wrapped in 3 or more backticks as needed.
pub fn code_block(tag: &str, text: &str) -> Self {
let backticks = "`".repeat(3.max(count_max_consecutive_chars(text, '`') + 1));
Self(format!("{backticks}{tag}\n{text}\n{backticks}\n"))
}
}
// Copied from `pulldown-cmark-to-cmark-20.0.0` with changed names.