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:
parent
2b5095ac91
commit
44aff7cd46
10 changed files with 34 additions and 24 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue